2020-02-10 16:51:09 +01:00
|
|
|
import { load, makePage, makeScreen } from "./testAppDef"
|
2020-01-24 14:18:31 +01:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
describe("initialiseApp (binding)", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
it("should populate root element prop from store value", async () => {
|
2020-02-10 16:51:09 +01:00
|
|
|
const { dom } = await load(
|
|
|
|
makePage({
|
|
|
|
_component: "testlib/div",
|
|
|
|
className: {
|
|
|
|
"##bbstate": "divClassName",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "default",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
const rootDiv = dom.window.document.body.children[0]
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(rootDiv.className.includes("default")).toBe(true)
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should update root element from store", async () => {
|
2020-02-10 16:51:09 +01:00
|
|
|
const { dom, app } = await load(
|
|
|
|
makePage({
|
|
|
|
_component: "testlib/div",
|
|
|
|
className: {
|
|
|
|
"##bbstate": "divClassName",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "default",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2020-02-03 10:24:25 +01:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
app.pageStore().update(s => {
|
2020-02-03 10:24:25 +01:00
|
|
|
s.divClassName = "newvalue"
|
|
|
|
return s
|
|
|
|
})
|
|
|
|
|
|
|
|
const rootDiv = dom.window.document.body.children[0]
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(rootDiv.className.includes("newvalue")).toBe(true)
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should populate child component with store value", async () => {
|
2020-02-10 16:51:09 +01:00
|
|
|
const { dom } = await load(
|
|
|
|
makePage({
|
|
|
|
_component: "testlib/div",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerOneText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header one",
|
|
|
|
},
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
2020-02-10 16:51:09 +01:00
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerTwoText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header two",
|
|
|
|
},
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
2020-02-10 16:51:09 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
const rootDiv = dom.window.document.body.children[0]
|
|
|
|
|
|
|
|
expect(rootDiv.children.length).toBe(2)
|
|
|
|
expect(rootDiv.children[0].tagName).toBe("H1")
|
|
|
|
expect(rootDiv.children[0].innerText).toBe("header one")
|
|
|
|
expect(rootDiv.children[1].tagName).toBe("H1")
|
|
|
|
expect(rootDiv.children[1].innerText).toBe("header two")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should populate child component with store value", async () => {
|
2020-02-10 16:51:09 +01:00
|
|
|
const { dom, app } = await load(
|
|
|
|
makePage({
|
|
|
|
_component: "testlib/div",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerOneText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header one",
|
|
|
|
},
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
2020-02-10 16:51:09 +01:00
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerTwoText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header two",
|
|
|
|
},
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
2020-02-10 16:51:09 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
2020-02-03 10:24:25 +01:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
app.pageStore().update(s => {
|
2020-02-03 10:24:25 +01:00
|
|
|
s.headerOneText = "header 1 - new val"
|
|
|
|
s.headerTwoText = "header 2 - new val"
|
|
|
|
return s
|
|
|
|
})
|
|
|
|
|
|
|
|
const rootDiv = dom.window.document.body.children[0]
|
|
|
|
|
|
|
|
expect(rootDiv.children.length).toBe(2)
|
|
|
|
expect(rootDiv.children[0].tagName).toBe("H1")
|
|
|
|
expect(rootDiv.children[0].innerText).toBe("header 1 - new val")
|
|
|
|
expect(rootDiv.children[1].tagName).toBe("H1")
|
|
|
|
expect(rootDiv.children[1].innerText).toBe("header 2 - new val")
|
|
|
|
})
|
2020-02-10 16:51:09 +01:00
|
|
|
|
|
|
|
it("should populate screen child with store value", async () => {
|
|
|
|
const { dom, app } = await load(
|
|
|
|
makePage({
|
|
|
|
_component: "testlib/div",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "##builtin/screenslot",
|
|
|
|
text: "header one",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
[
|
|
|
|
makeScreen("/", {
|
|
|
|
_component: "testlib/div",
|
|
|
|
className: "screen-class",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerOneText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header one",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_component: "testlib/h1",
|
|
|
|
text: {
|
|
|
|
"##bbstate": "headerTwoText",
|
|
|
|
"##bbsource": "store",
|
|
|
|
"##bbstatefallback": "header two",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
app.screenStore().update(s => {
|
|
|
|
s.headerOneText = "header 1 - new val"
|
|
|
|
s.headerTwoText = "header 2 - new val"
|
|
|
|
return s
|
|
|
|
})
|
|
|
|
|
|
|
|
const rootDiv = dom.window.document.body.children[0]
|
|
|
|
expect(rootDiv.children.length).toBe(1)
|
|
|
|
|
|
|
|
const screenRoot = rootDiv.children[0]
|
|
|
|
|
|
|
|
expect(screenRoot.children.length).toBe(1)
|
|
|
|
expect(screenRoot.children[0].children.length).toBe(2)
|
|
|
|
expect(screenRoot.children[0].children[0].innerText).toBe(
|
|
|
|
"header 1 - new val"
|
|
|
|
)
|
|
|
|
expect(screenRoot.children[0].children[1].innerText).toBe(
|
|
|
|
"header 2 - new val"
|
|
|
|
)
|
|
|
|
})
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|