added navigation and a lot of unit tests

This commit is contained in:
metacryst
2024-03-18 09:38:07 +01:00
parent 802a39f502
commit b1d2370c0b
6 changed files with 340 additions and 180 deletions

8
Test/Pages/home.js Normal file
View File

@@ -0,0 +1,8 @@
class Home extends Page {
results = window.test
render = () => {
}
}
export default Home

View File

@@ -12,15 +12,109 @@ window.testSuites.push( class testShadow {
window.register(File, "file-el")
let form = {data: "asdf"}
const el = window.File(form)
console.log(el, el.$form, el._form)
if(!(el.form === form)) {
return `State field does not match object passed in!`
}
}
testRegisterThrowsIfNoConstructorParams() {
testMultiParams() {
class File2 extends Shadow {
$form
$tag
constructor(...params) {
super(...params)
}
}
window.register(File2, "file2-el")
let form = {data: "asdf"}
const el = window.File2(form, "tag")
if(!(el.form === form)) {
return `Form field does not match object passed in!`
}
if(!(el.tag === "tag")) {
return `Tag field does not match object passed in!`
}
}
onlyGetFieldsNotUsing$() {
class File5 extends Shadow {
$form
$tag
constructor(...params) {
super(...params)
}
}
window.register(File5, "file5-el")
let form = {data: "asdf"}
const el = window.File5(form, "tag")
if(el.$tag !== undefined) {
return "Got field the wrong way!"
}
}
testChangeAttrChangesField() {
class File3 extends Shadow {
$form
$tag
constructor(...params) {
super(...params)
}
}
window.register(File3, "file3-el")
let form = {data: "asdf"}
const el = window.File3(form, "tag")
el.setAttribute("tag", "asdf")
if(el.tag !== "asdf") {
return "Field did not change!"
}
}
testChangeFieldChangesAttr() {
class File4 extends Shadow {
$form
$tag
constructor(...params) {
super(...params)
}
}
window.register(File4, "file4-el")
let form = {data: "asdf"}
const el = window.File4(form, "tag")
el.tag = "asdf"
if(el.getAttribute("tag") !== "asdf") {
return "Attribute did not change!"
}
}
testDefaultStateFieldWorks() {
class File6 extends Shadow {
$form = {data: "asdf"}
constructor(...params) {
super(...params)
console.log(this.form)
}
}
window.register(File6, "file6-el")
const el = window.File6()
console.log(el, el.$form, el._form)
if(el.form === undefined) {
return `Default value did not work`
}
}
testRegisterThrowsIfNoConstructorParams() {
class File3 extends Shadow {
$form
constructor() {
super()
@@ -28,7 +122,7 @@ window.testSuites.push( class testShadow {
}
try {
window.register(File2, "file2-el")
window.register(File3, "file3-el")
} catch(e) {}
return "Error not thrown!"

View File

@@ -4,9 +4,15 @@
<title>Quill</title>
<link rel="icon" href="">
<link rel="stylesheet" href="">
<script src=""></script>
<script src="../index.js"></script>
<script src="test.js"></script>
<script type="module">
import Home from "./Pages/home.js";
window.routes = {
"/Test": Home
}
</script>
</head>
<body>

View File

@@ -15,7 +15,7 @@ window.test = async function() {
var start = new Date();
for(let j=0; j<window.testSuites.length; j++) {
let testSuite = window.testSuites[j];
console.log(`%c ➽ ${j+1} ${testSuite.name.replace("test", "")}`, 'color: #ffffff; font-size: 17px; padding-left: -20px; padding-top: 10px; padding-bottom: 10px; text-align: right;')
console.log(`%c ➽ ${j+1} ${testSuite.name.replace("test", "")}`, 'color: #e9c9a0; border: 3px solid #e9c9a0; border-radius: 10px; font-size: 17px; padding-left: -20px; margin-top: 20px; margin-bottom: 20px; padding-top: 10px; padding-bottom: 10px; padding-right: 10px; text-align: right;')
let suite = new testSuite();
let testNum = 0;
let suiteContents = Object.getOwnPropertyNames(testSuite.prototype)
@@ -23,13 +23,21 @@ window.test = async function() {
let test = suiteContents[i];
if(typeof suite[test] === 'function' && test !== "constructor") {
testNum++;
console.log(`%c${testNum}. ${test}`, "margin-top: 10px; border-top: 2px solid #e9c9a0; color: #e9c9a0; border-radius: 10px; padding: 10px;");
let fail = await suite[test]();
if(fail) {
failed++;
console.log(`%c ${testNum}. ${test}: ${fail}`, 'background: #222; color: rgb(254, 62, 43)');
let spaceNum = test.length - fail.length
let spaces = ""
if(spaceNum > 0) {
for(let i=0; i < spaceNum; i++) {
spaces += " "
}
}
console.log(`%c ${fail}${spaces}`, 'border-bottom: 2px solid #e9c9a0; color: rgb(254, 62, 43); border-radius: 10px; padding: 10px');
} else {
success++;
console.log(`%c ${testNum}. ${test}`, 'background: #222; color: #00FF00');
console.log(`%c${testNum}. ${test}`, 'border-bottom: 2px solid #e9c9a0; background: #628c60; color: transparent; border-radius: 10px; padding: 0px 10px 0px 10px');
}
}
// Need to flush ws buffer since saving is disabled, and that is what usually does the flushing