class WidgetGiveSlots extends R.TestView.WidgetGiveSlots { constructor() { super() this.childWidget = new R.TestView.WidgetWithSlots() } } export function run() { let wgs: WidgetGiveSlots let wis: R.TestView.WidgetWithSlots describe("Widget slot test", () => { it("Create widget", () => { wgs = new WidgetGiveSlots() console.log(wgs.node) }) it("Can refer to data-id given to child widget", () => { let text = wgs.UI.header.textContent.toString().trim() if (text !== "HEADER") { throw new Error("Failed to reference") } }) it("Should beable to merge child classes", () => { wgs.VM.parentClass = "parent-class" wgs.childWidget.VM.childClass = "child-class" let classes = ["parent-set-widget", "child-set-widget", "parent-class", "child-class"] console.log(wgs.childWidget.node.className) for (let className of classes) { if (!wgs.childWidget.node.classList.contains(className)) { throw new Error("Fail to merge child widget:" + className) } } }) it("Child can refer to gived child widget by data-id", () => { let same = wgs.childWidget.UI.header === wgs.UI.header if (!same) { throw new Error("Failed to match header") } same = wgs.childWidget.UI.body === wgs.UI.body if (!same) { throw new Error("Failed to match body") } }) it("Class should merge correctly", () => { wgs.VM.parentSlotClass = "parent-set" wgs.childWidget.VM.childSlotClass = "slot-set" let classes = ["parent-set", "slot-set", "slot-header", "parent-header"] for (let name of classes) { if (!wgs.childWidget.UI.header.classList.contains(name)) { throw new Error("Fail to merge class:" + name) } } }) }) describe("Common widget test", () => { let tum: R.TestView.TestUseModal let tm: R.TestView.TestModal it("Widget include common widget", () => { Leaf.Widget.namespace.clear() Leaf.Widget.namespace.include(R.TestView.TestModal) }) it("Widget use common widget", () => { tum = new R.TestView.TestUseModal() let succeed = tum.node.widget instanceof R.TestView.TestModal if (!succeed) { throw new Error("Fail to create namespace") } tm = tum.node.widget as any }) it("Common widget should have dynamics properties attached", () => { tum.VM.parentHeaderSet = true tum.VM.useModalSet = true tm.VM.slotHeaderSet = true tm.VM.modalSet = true let classes: string[] classes = ["modal", "use-modal", "use-modal-set", "modal", "modal-set"] for (let name of classes) { if (!tum.node.classList.contains(name)) { console.error(tum.node.classList) throw new Error("Fail to transfer class:" + name) } } classes = ["parent-header", "parent-header-set", "slot-header", "slot-header-set"] for (let name of classes) { if (!tum.UI.header.classList.contains(name)) { console.error(tum.UI.header.classList) throw new Error("Fail to transfer slot class:" + name) } } }) }) describe("Test recursive widget list class", () => { class MasterList extends R.List.MasterList { theList = new TheList() constructor() { super() } } class TheList extends R.List.MasterList.TheList { constructor() { super() this.children.push(new Item()) } } class Item extends R.List.MasterList.TheList.Item { constructor() { super() this.VM.second = "V1" setTimeout(() => { this.VM.second = "V2" }, 200) } } it("Test widget reattach", (done) => { let master = new MasterList() setTimeout(() => { if (master.theList.children[0].node.classList.contains("V1")) { done(new Error("Can't overwrite!")) return } done() }, 400) }) }) describe("VM test", () => { it("Basic vm", () => { let view = new R.VmTest view.VM.header = "header-class" console.log(view.node.className) if (!view.node.classList.contains("header-class")) { throw new Error("Basic set class") } view.VM.header = true if (!view.node.classList.contains("header")) { throw new Error("Set class using true") } view.VM.header = false if (view.node.classList.contains("header")) { throw new Error("Set class using false") } }) it("Nested VM test", () => { let view = new R.VmTest view.VM.order = { address: { street: "STREET" } } //view.VM.order.address.street = "STREET" if ("STREET" !== view.UI.street.textContent.trim()) { throw new Error("Can't group set new object") } }) it("Can set VM using number 0", () => { let view = new R.VmTest view.VM.order = { address: { street: 0 } } console.error(view.node) if ("0" !== view.UI.street.textContent.trim()) { throw new Error("Can't set VM using number 0") } }) }) }