diff --git a/packages/doenetml-worker/src/test/tagSpecific/evaluate.test.ts b/packages/doenetml-worker/src/test/tagSpecific/evaluate.test.ts index b4da5cfc9..66b033413 100644 --- a/packages/doenetml-worker/src/test/tagSpecific/evaluate.test.ts +++ b/packages/doenetml-worker/src/test/tagSpecific/evaluate.test.ts @@ -3703,7 +3703,7 @@ describe("Evaluate tag tests", async () => { expect(stateVariables["/pha"].stateValues.text).eq("5"); }); - it.only("evaluate functions based on interpolated function", async () => { + it("evaluate functions based on interpolated function", async () => { let core = await createTestCore({ doenetML: `
f:
+
+ $sample1{name="noresample1"} + $sample2{name="noresample2"} + $noresample1{name="noreresample1"} + $noresample2{name="noreresample2"} +
+ + + + + + `, + }); + + let stateVariables = await returnAllStateVariables(core); + let num1 = stateVariables["/n1"].stateValues.value; + let num2 = stateVariables["/n2"].stateValues.value; + expect(Number.isInteger(num1) && num1 >= 1 && num1 <= 100).eq(true); + expect(Number.isInteger(num2) && num2 >= 1 && num2 <= 100).eq(true); + expect( + stateVariables[ + stateVariables["/noresample1"].replacements![0].componentName + ].stateValues.value, + ).eq(num1); + expect( + stateVariables[ + stateVariables["/noresample2"].replacements![0].componentName + ].stateValues.value, + ).eq(num2); + expect( + stateVariables[ + stateVariables["/noreresample1"].replacements![0].componentName + ].stateValues.value, + ).eq(num1); + expect( + stateVariables[ + stateVariables["/noreresample2"].replacements![0].componentName + ].stateValues.value, + ).eq(num2); + + expect( + stateVariables[ + stateVariables["/noresamplep"].activeChildren[1].componentName + ].stateValues.value, + ).eq(num1); + expect( + stateVariables[ + stateVariables["/noresamplep"].activeChildren[3].componentName + ].stateValues.value, + ).eq(num2); + expect( + stateVariables[ + stateVariables["/noreresamplep"].activeChildren[1].componentName + ].stateValues.value, + ).eq(num1); + expect( + stateVariables[ + stateVariables["/noreresamplep"].activeChildren[3].componentName + ].stateValues.value, + ).eq(num2); + }); + + it("select doesn't change dynamically", async () => { + let core = await createTestCore({ + doenetML: ` +
+
+
$maxNum2.value{assignNames="maxNum2a"}
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let sample1replacements = stateVariables["/sample1"].replacements!; + let sample2replacements = stateVariables["/sample2"].replacements!; + expect(sample1replacements.length).eq(5); + expect(sample2replacements.length).eq(2); + let sample1numbers = sample1replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let sample2numbers = sample2replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + + for (let num of sample1numbers) { + expect([1, 2, 3].includes(num)).eq(true); + } + for (let num of sample2numbers) { + expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].includes(num)).eq(true); + } + + // Nothing changes when change mathInputs + await updateMathInputValue({ + latex: "7", + componentName: "/numToSelect", + core, + }); + await updateMathInputValue({ + latex: "11", + componentName: "/maxNum", + core, + }); + await updateMathInputValue({ + latex: "16", + componentName: "/numToSelect2", + core, + }); + await updateMathInputValue({ + latex: "18", + componentName: "/maxNum2", + core, + }); + + stateVariables = await returnAllStateVariables(core); + sample1replacements = stateVariables["/sample1"].replacements!; + sample2replacements = stateVariables["/sample2"].replacements!; + + expect( + sample1replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ), + ).eqls(sample1numbers); + expect( + sample2replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ), + ).eqls(sample2numbers); + }); + + it("select doesn't resample in dynamic map", async () => { + let core = await createTestCore({ + doenetML: ` + How many numbers do you want?$map1
+ + $p1{name="p3"} + $p2{name="p4"} + + $p3{name="p5"} + $p4{name="p6"} + `, + }); + + async function check_sampled_numbers(sampledNumbers: number[]) { + let num = sampledNumbers.length; + const stateVariables = await returnAllStateVariables(core); + + expect( + stateVariables["/p1"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p2"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p3"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p4"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p5"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p6"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + } + + let sampledNumbers: number[] = []; + + // initially nothing + await check_sampled_numbers([]); + + // sample one variable + await updateMathInputValue({ latex: "1", componentName: "/mi1", core }); + + let stateVariables = await returnAllStateVariables(core); + sampledNumbers.push(stateVariables["/a/n"].stateValues.value); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get same number back + await updateMathInputValue({ latex: "1", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers); + + // get two more samples + await updateMathInputValue({ latex: "3", componentName: "/mi1", core }); + + stateVariables = await returnAllStateVariables(core); + let n1 = stateVariables["/a/n"].stateValues.value; + let n2 = stateVariables["/b/n"].stateValues.value; + let n3 = stateVariables["/c/n"].stateValues.value; + expect(n1).eq(sampledNumbers[0]); + sampledNumbers.push(n2); + sampledNumbers.push(n3); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get first two numbers back + await updateMathInputValue({ latex: "2", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers.slice(0, 2)); + + // get six total samples + await updateMathInputValue({ latex: "6", componentName: "/mi1", core }); + + stateVariables = await returnAllStateVariables(core); + n1 = stateVariables["/a/n"].stateValues.value; + n2 = stateVariables["/b/n"].stateValues.value; + n3 = stateVariables["/c/n"].stateValues.value; + let n4 = stateVariables["/d/n"].stateValues.value; + let n5 = stateVariables["/e/n"].stateValues.value; + let n6 = stateVariables["/f/n"].stateValues.value; + expect(n1).eq(sampledNumbers[0]); + expect(n2).eq(sampledNumbers[1]); + expect(n3).eq(sampledNumbers[2]); + sampledNumbers.push(n4); + sampledNumbers.push(n5); + sampledNumbers.push(n6); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get all six back + await updateMathInputValue({ latex: "6", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers); + }); + + it("select single math", async () => { + const doenetML = `$c, $d{hide="false"}
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let c = await stateVariables["/c"].stateValues.value; + let d = await stateVariables["/d"].stateValues.value; + expect(["a", "b", "c", "d", "e"].includes(c)).eq(true); + expect(["a", "b", "c", "d", "e"].includes(d)).eq(true); + + expect(stateVariables["/p1"].stateValues.text).eq(`${c}, `); + expect(stateVariables["/p2"].stateValues.text).eq(`${c}, ${d}`); + }); + + it("select multiple numbers with excludeCombinations, handles round-off error", async () => { + // Third number selected will be 0.1*3, which isn't exactly 0.3 due to round off error. + // Even so, excluding 0.3 works successfully. + const doenetML = `$c, $d
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let c = await stateVariables["/c"].stateValues.value; + let d = await stateVariables["/d"].stateValues.value; + expect(["a", "b", "c", "d", "e"].includes(c)).eq(true); + expect(["a", "b", "c", "d", "e"].includes(d)).eq(true); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/p1"].stateValues.text).eq(`${c}, `); + expect(stateVariables["/p2"].stateValues.text).eq(`${c}, ${d}`); + + await updateBooleanInputValue({ + boolean: true, + componentName: "/h1", + core, + }); + await updateBooleanInputValue({ + boolean: false, + componentName: "/h2", + core, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/p1"].stateValues.text).eq(`, ${d}`); + expect(stateVariables["/p2"].stateValues.text).eq(`${c}, ${d}`); + + await updateBooleanInputValue({ + boolean: false, + componentName: "/h1", + core, + }); + await updateBooleanInputValue({ + boolean: true, + componentName: "/h2", + core, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/p1"].stateValues.text).eq(`${c}, `); + expect(stateVariables["/p2"].stateValues.text).eq(`${c}, ${d}`); + }); + + it("selectFromSequence defaults to fixed", async () => { + let core = await createTestCore({ + doenetML: ` +
+
+ $a{name="a2"} + $b{name="b2"} + $c{name="c2"} +
+
+
+
+ $a.fixed{assignNames="af"} + $b.fixed{assignNames="bf"} + $c.fixed{assignNames="cf"} +
++ $a2.fixed{assignNames="a2f"} + $b2.fixed{assignNames="b2f"} + $c2.fixed{assignNames="c2f"} +
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let a = stateVariables["/a"].stateValues.value; + let b = stateVariables["/b"].stateValues.value; + let c = stateVariables["/c"].stateValues.value; + expect(["a", "b", "c", "d", "e"].includes(a)).eq(true); + expect(["a", "b", "c", "d", "e"].includes(b)).eq(true); + expect(["a", "b", "c", "d", "e"].includes(c)).eq(true); + + expect(stateVariables["/a2"].stateValues.value).eq(a); + expect(stateVariables["/b2"].stateValues.value).eq(b); + expect(stateVariables["/c2"].stateValues.value).eq(c); + + expect(stateVariables["/af"].stateValues.value).eq(true); + expect(stateVariables["/bf"].stateValues.value).eq(false); + expect(stateVariables["/cf"].stateValues.value).eq(true); + expect(stateVariables["/a2f"].stateValues.value).eq(true); + expect(stateVariables["/b2f"].stateValues.value).eq(false); + expect(stateVariables["/c2f"].stateValues.value).eq(true); + + await updateTextInputValue({ text: "f", componentName: "/a3", core }); + await updateTextInputValue({ text: "g", componentName: "/b3", core }); + await updateTextInputValue({ text: "h", componentName: "/c3", core }); + stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/a"].stateValues.value).eq(a); + expect(stateVariables["/b"].stateValues.value).eq("g"); + expect(stateVariables["/c"].stateValues.value).eq(c); + expect(stateVariables["/a2"].stateValues.value).eq(a); + expect(stateVariables["/b2"].stateValues.value).eq("g"); + expect(stateVariables["/c2"].stateValues.value).eq(c); + + await updateTextInputValue({ text: "i", componentName: "/a4", core }); + await updateTextInputValue({ text: "j", componentName: "/b4", core }); + await updateTextInputValue({ text: "k", componentName: "/c4", core }); + stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/a"].stateValues.value).eq(a); + expect(stateVariables["/b"].stateValues.value).eq("j"); + expect(stateVariables["/c"].stateValues.value).eq(c); + expect(stateVariables["/a2"].stateValues.value).eq(a); + expect(stateVariables["/b2"].stateValues.value).eq("j"); + expect(stateVariables["/c2"].stateValues.value).eq(c); + + await updateBooleanInputValue({ + boolean: true, + componentName: "/f1", + core, + }); + await updateBooleanInputValue({ + boolean: false, + componentName: "/f2", + core, + }); + stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/af"].stateValues.value).eq(true); + expect(stateVariables["/bf"].stateValues.value).eq(true); + expect(stateVariables["/cf"].stateValues.value).eq(false); + expect(stateVariables["/a2f"].stateValues.value).eq(true); + expect(stateVariables["/b2f"].stateValues.value).eq(true); + expect(stateVariables["/c2f"].stateValues.value).eq(false); + + await updateTextInputValue({ text: "l", componentName: "/a3", core }); + await updateTextInputValue({ text: "m", componentName: "/b3", core }); + await updateTextInputValue({ text: "n", componentName: "/c3", core }); + stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/a"].stateValues.value).eq(a); + expect(stateVariables["/b"].stateValues.value).eq("j"); + expect(stateVariables["/c"].stateValues.value).eq("n"); + expect(stateVariables["/a2"].stateValues.value).eq(a); + expect(stateVariables["/b2"].stateValues.value).eq("j"); + expect(stateVariables["/c2"].stateValues.value).eq("n"); + + await updateTextInputValue({ text: "o", componentName: "/a4", core }); + await updateTextInputValue({ text: "p", componentName: "/b4", core }); + await updateTextInputValue({ text: "q", componentName: "/c4", core }); + stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/a"].stateValues.value).eq(a); + expect(stateVariables["/b"].stateValues.value).eq("j"); + expect(stateVariables["/c"].stateValues.value).eq("q"); + expect(stateVariables["/a2"].stateValues.value).eq(a); + expect(stateVariables["/b2"].stateValues.value).eq("j"); + expect(stateVariables["/c2"].stateValues.value).eq("q"); + }); + + it("numToSelect from selectFromSequence", async () => { + let core = await createTestCore({ + doenetML: ` +n1 =
nums =
a1=$a1, b1=$b1, c1=$c1, d1=$d1, e1=$e1
+ +n2 =
nums =
a2=$a2, b2=$b2, c2=$c2, d2=$d2, e2=$e2
+ +n3 =
nums =
a3=$a3, b3=$b3, c3=$c3, d3=$d3, e3=$e3
+ +n4 =
nums =
a4=$a4, b4=$b4, c4=$c4, d4=$d4, e4=$e4
+ +n5 =
nums =
a5=$a5, b5=$b5, c5=$c5, d5=$d5, e5=$e5
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let n1 = stateVariables["/n1"].stateValues.value; + let n2 = stateVariables["/n2"].stateValues.value; + let n3 = stateVariables["/n3"].stateValues.value; + let n4 = stateVariables["/n4"].stateValues.value; + let n5 = stateVariables["/n5"].stateValues.value; + + let nums1 = stateVariables["/nums1"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums2 = stateVariables["/nums2"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums3 = stateVariables["/nums3"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums4 = stateVariables["/nums4"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums5 = stateVariables["/nums5"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + + expect(nums1.length).eq(n1); + expect(nums2.length).eq(n2); + expect(nums3.length).eq(n3); + expect(nums4.length).eq(n4); + expect(nums5.length).eq(n5); + + nums1.length = 5; + nums2.length = 5; + nums3.length = 5; + nums4.length = 5; + nums5.length = 5; + + nums1.fill("", n1); + nums2.fill("", n2); + nums3.fill("", n3); + nums4.fill("", n4); + nums5.fill("", n5); + + let l = ["a", "b", "c", "d", "e"]; + + expect(stateVariables["/p1"].stateValues.text).eq( + nums1.map((v, i) => `${l[i]}1=${v}`).join(", "), + ); + expect(stateVariables["/p2"].stateValues.text).eq( + nums2.map((v, i) => `${l[i]}2=${v}`).join(", "), + ); + expect(stateVariables["/p3"].stateValues.text).eq( + nums3.map((v, i) => `${l[i]}3=${v}`).join(", "), + ); + expect(stateVariables["/p4"].stateValues.text).eq( + nums4.map((v, i) => `${l[i]}4=${v}`).join(", "), + ); + expect(stateVariables["/p5"].stateValues.text).eq( + nums5.map((v, i) => `${l[i]}5=${v}`).join(", "), + ); + }); + + it("rounding", async () => { + let core = await createTestCore({ + doenetML: ` +Number to exclude:
Number to exclude:
$_aslist1{name="noresamplelist"}
- -$noresamplelist{name="noreresamplelist"}
- - $_p1{name="noresamplep"} - $noresamplep{name="noreresamplep"} - `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_math1") + " .mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("1"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let num1 = - stateVariables[ - stateVariables["/sample1"].replacements[0].componentName - ].stateValues.value; - let num2 = - stateVariables[ - stateVariables["/sample2"].replacements[0].componentName - ].stateValues.value; - expect(Number.isInteger(num1) && num1 >= 1 && num1 <= 100).eq(true); - expect(Number.isInteger(num2) && num2 >= 1 && num2 <= 100).eq(true); - expect( - stateVariables[ - stateVariables["/noresample1"].replacements[0].componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables["/noresample2"].replacements[0].componentName - ].stateValues.value, - ).eq(num2); - expect( - stateVariables[ - stateVariables["/noreresample1"].replacements[0] - .componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables["/noreresample2"].replacements[0] - .componentName - ].stateValues.value, - ).eq(num2); - - expect( - stateVariables[ - stateVariables["/noresamplelist"].activeChildren[0] - .componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables["/noresamplelist"].activeChildren[1] - .componentName - ].stateValues.value, - ).eq(num2); - expect( - stateVariables[ - stateVariables["/noreresamplelist"].activeChildren[0] - .componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables["/noreresamplelist"].activeChildren[1] - .componentName - ].stateValues.value, - ).eq(num2); - - expect( - stateVariables[ - stateVariables[ - stateVariables["/noresamplep"].activeChildren[0] - .componentName - ].activeChildren[0].componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables[ - stateVariables["/noresamplep"].activeChildren[0] - .componentName - ].activeChildren[1].componentName - ].stateValues.value, - ).eq(num2); - expect( - stateVariables[ - stateVariables[ - stateVariables["/noreresamplep"].activeChildren[0] - .componentName - ].activeChildren[0].componentName - ].stateValues.value, - ).eq(num1); - expect( - stateVariables[ - stateVariables[ - stateVariables["/noreresamplep"].activeChildren[0] - .componentName - ].activeChildren[1].componentName - ].stateValues.value, - ).eq(num2); - }); - }); - - it("select doesn't change dynamically", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - -$maxnum2.value{assignNames="maxnum2a"}
- `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_math1") + " .mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("1"); - }); - - let sample1numbers, sample2numbers; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let sample1replacements = stateVariables["/sample1"].replacements; - let sample2replacements = stateVariables["/sample2"].replacements; - expect(sample1replacements.length).eq(5); - expect(sample2replacements.length).eq(2); - sample1numbers = sample1replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - sample2numbers = sample2replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - - for (let num of sample1numbers) { - expect([1, 2, 3].includes(num)).eq(true); - } - for (let num of sample2numbers) { - expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].includes(num)).eq(true); - } - }); - - cy.log("Nothing changes when change mathinputs"); - cy.get(cesc("#\\/numToSelect") + " textarea").type( - `{end}{backspace}7{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum") + " textarea").type( - `{end}{backspace}11{enter}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/numToSelect2") + " textarea").type( - `{end}{backspace}15{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum2") + " textarea").type( - `{end}{backspace}{backspace}18{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum2a")).should("contain.text", "18"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let sample1replacements = stateVariables["/sample1"].replacements; - let sample2replacements = stateVariables["/sample2"].replacements; - - expect( - sample1replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ), - ).eqls(sample1numbers); - expect( - sample2replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ), - ).eqls(sample2numbers); - }); - }); - - it("select doesn't resample in dynamic map", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$_aslist1
- - $p1{name="p4"} - $p2{name="p5"} - $p3{name="p6"} - - $p4{name="p7"} - $p5{name="p8"} - $p6{name="p9"} -$_mathinput1.value{assignNames="m1"}
- `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", "a"); - - let samplednumbers = []; - - cy.log("initially nothing"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("sample one variable"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}1{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - samplednumbers.push(n1); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - for (let ind = 0; ind < 1; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get same number back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}1{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - - for (let ind = 0; ind < 1; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("get two more samples"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}3{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "3"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - samplednumbers.push(n2); - samplednumbers.push(n3); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - for (let ind = 0; ind < 3; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get first two numbers back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}2{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "2"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - - for (let ind = 0; ind < 2; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("get six total samples"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}6{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "6"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - let n4 = stateVariables["/d/n"].stateValues.value; - let n5 = stateVariables["/e/n"].stateValues.value; - let n6 = stateVariables["/f/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect(n3).eq(samplednumbers[2]); - samplednumbers.push(n4); - samplednumbers.push(n5); - samplednumbers.push(n6); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - for (let ind = 0; ind < 6; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get all six back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}6{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "6"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - let n4 = stateVariables["/d/n"].stateValues.value; - let n5 = stateVariables["/e/n"].stateValues.value; - let n6 = stateVariables["/f/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect(n3).eq(samplednumbers[2]); - expect(n4).eq(samplednumbers[3]); - expect(n5).eq(samplednumbers[4]); - expect(n6).eq(samplednumbers[5]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - for (let ind = 0; ind < 6; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - }); - - it("select single math, assign name", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$u{name="u2"}
-$v{name="v2"}
-$w{name="w2"}
- `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", "a"); - - let options = [ - me.fromText("x"), - me.fromText("x+y"), - me.fromText("x+2y"), - ]; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/u"]; - let u2 = stateVariables["/u2"]; - let comparisons = options.map((el) => - el.equals(me.fromAst(u.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(u.stateValues.value).eqls(u2.stateValues.value); - - let v = stateVariables["/v"]; - let v2 = stateVariables["/v2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(v.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(v.stateValues.value).eqls(v2.stateValues.value); - - let w = stateVariables["/w"]; - let w2 = stateVariables["/w2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(w.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(w.stateValues.value).eqls(w2.stateValues.value); - }); - }); - - it("select multiple maths, assign names", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - -$u{name="u2"}
-$v{name="v2"}
-$w{name="w2"}
- `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_math1") + " .mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("1"); - }); - - let options = [ - me.fromText("x"), - me.fromText("x+y"), - me.fromText("x+2y"), - ]; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/u"]; - let u2 = stateVariables["/u2"]; - let comparisons = options.map((el) => - el.equals(me.fromAst(u.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(u.stateValues.value).eqls(u2.stateValues.value); - - let v = stateVariables["/v"]; - let v2 = stateVariables["/v2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(v.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(v.stateValues.value).eqls(v2.stateValues.value); - - let w = stateVariables["/w"]; - let w2 = stateVariables["/w2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(w.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(w.stateValues.value).eqls(w2.stateValues.value); - - let s = stateVariables["/s"]; - for (let ind = 3; ind < 6; ind++) { - let r = stateVariables[s.replacements[ind].componentName]; - comparisons = options.map((el) => - el.equals(me.fromAst(r.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - } - }); - }); - - it("select multiple maths, assign names, new namespace", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - -$(s/u{name="u2"})
-$(s/v{name="v2"})
-$(s/w{name="w2"})
- `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_math1") + " .mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("1"); - }); - - let options = [ - me.fromText("x"), - me.fromText("x+y"), - me.fromText("x+2y"), - ]; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/s/u"]; - let u2 = stateVariables["/u2"]; - let comparisons = options.map((el) => - el.equals(me.fromAst(u.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(u.stateValues.value).eqls(u2.stateValues.value); - - let v = stateVariables["/s/v"]; - let v2 = stateVariables["/v2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(v.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(v.stateValues.value).eqls(v2.stateValues.value); - - let w = stateVariables["/s/w"]; - let w2 = stateVariables["/w2"]; - comparisons = options.map((el) => - el.equals(me.fromAst(w.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - expect(w.stateValues.value).eqls(w2.stateValues.value); - - let s = stateVariables["/s"]; - for (let ind = 3; ind < 6; ind++) { - let r = stateVariables[s.replacements[ind].componentName]; - comparisons = options.map((el) => - el.equals(me.fromAst(r.stateValues.value)), - ); - expect(comparisons.includes(true)).eq(true); - } - }); - }); - - it("selectfromsequence with hide will hide replacements", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -Selectfromsequences and hide
-$c,
$_aslist1{name="aslist2"}
- $_p1{name="p3"} - `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", "a"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let lastnumber = -20; - let originalnumbers = stateVariables[ - "/_selectfromsequence1" - ].replacements.map((x) => stateVariables[x.componentName]); - let secondnumbers = stateVariables["/aslist2"].activeChildren.map( - (x) => stateVariables[x.componentName], - ); - let thirdnumbers = stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.map((x) => stateVariables[x.componentName]); - for (let i = 0; i < 20; i++) { - let newnumber = originalnumbers[i].stateValues.value; - expect(newnumber).gte(lastnumber); - lastnumber = newnumber; - expect(secondnumbers[i].stateValues.value).eq(newnumber); - expect(thirdnumbers[i].stateValues.value).eq(newnumber); - } - }); - }); - - it("select letters and sort", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$_aslist1{name="aslist2"}
- $_p1{name="p3"} - `, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", "a"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let lastletter = "a"; - let originalletters = stateVariables[ - "/_selectfromsequence1" - ].replacements.map((x) => stateVariables[x.componentName]); - let secondletters = stateVariables["/aslist2"].activeChildren.map( - (x) => stateVariables[x.componentName], - ); - let thirdletters = stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.map((x) => stateVariables[x.componentName]); - for (let i = 0; i < 20; i++) { - let newletter = originalletters[i].stateValues.value; - expect(newletter.length).gte(lastletter.length); - expect( - newletter.length > lastletter.length || - newletter >= lastletter, - ).to.be.true; - lastletter = newletter; - expect(secondletters[i].stateValues.value).eq(newletter); - expect(thirdletters[i].stateValues.value).eq(newletter); - } - }); - }); - - it("selectfromsequence hides dynamically", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$c, $d
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let c = await stateVariables["/c"].stateValues.value; - let d = await stateVariables["/d"].stateValues.value; - expect(["a", "b", "c", "d", "e"].includes(c)).eq(true); - expect(["a", "b", "c", "d", "e"].includes(d)).eq(true); - - cy.get(cesc(`#\\/_p1`)).should("have.text", `${c}, `); - cy.get(cesc(`#\\/_p2`)).should("have.text", `${c}, ${d}`); - - cy.get(cesc("#\\/h1")).click(); - cy.get(cesc("#\\/h2")).click(); - - cy.get(cesc(`#\\/_p1`)).should("have.text", `, ${d}`); - cy.get(cesc(`#\\/_p2`)).should("have.text", `${c}, ${d}`); - - cy.get(cesc("#\\/h1")).click(); - cy.get(cesc("#\\/h2")).click(); - - cy.get(cesc(`#\\/_p1`)).should("have.text", `${c}, `); - cy.get(cesc(`#\\/_p2`)).should("have.text", `${c}, ${d}`); - }); - }); - - it("selectfromsequence defaults to fixed", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -
-
- $a{name="a2"} - $b{name="b2"} - $c{name="c2"} -
-
-
-
- $a.fixed{assignNames="af"} - $b.fixed{assignNames="bf"} - $c.fixed{assignNames="cf"} -
-- $a2.fixed{assignNames="a2f"} - $b2.fixed{assignNames="b2f"} - $c2.fixed{assignNames="c2f"} -
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let a = stateVariables["/a"].stateValues.value; - let b = stateVariables["/b"].stateValues.value; - let c = stateVariables["/c"].stateValues.value; - expect(["a", "b", "c", "d", "e"].includes(a)).eq(true); - expect(["a", "b", "c", "d", "e"].includes(b)).eq(true); - expect(["a", "b", "c", "d", "e"].includes(c)).eq(true); - - cy.get(cesc("#\\/a")).should("have.text", a); - cy.get(cesc("#\\/b")).should("have.text", b); - cy.get(cesc("#\\/c")).should("have.text", c); - cy.get(cesc("#\\/a2")).should("have.text", a); - cy.get(cesc("#\\/b2")).should("have.text", b); - cy.get(cesc("#\\/c2")).should("have.text", c); - - cy.get(cesc("#\\/af")).should("have.text", "true"); - cy.get(cesc("#\\/bf")).should("have.text", "false"); - cy.get(cesc("#\\/cf")).should("have.text", "true"); - cy.get(cesc("#\\/a2f")).should("have.text", "true"); - cy.get(cesc("#\\/b2f")).should("have.text", "false"); - cy.get(cesc("#\\/c2f")).should("have.text", "true"); - - cy.get(cesc("#\\/a3_input")).clear().type("f{enter}"); - cy.get(cesc("#\\/b3_input")).clear().type("g{enter}"); - cy.get(cesc("#\\/c3_input")).clear().type("h{enter}"); - - cy.get(cesc("#\\/a")).should("have.text", a); - cy.get(cesc("#\\/b")).should("have.text", "g"); - cy.get(cesc("#\\/c")).should("have.text", c); - cy.get(cesc("#\\/a2")).should("have.text", a); - cy.get(cesc("#\\/b2")).should("have.text", "g"); - cy.get(cesc("#\\/c2")).should("have.text", c); - - cy.get(cesc("#\\/a4_input")).clear().type("i{enter}"); - cy.get(cesc("#\\/b4_input")).clear().type("j{enter}"); - cy.get(cesc("#\\/c4_input")).clear().type("k{enter}"); - - cy.get(cesc("#\\/a")).should("have.text", a); - cy.get(cesc("#\\/b")).should("have.text", "j"); - cy.get(cesc("#\\/c")).should("have.text", c); - cy.get(cesc("#\\/a2")).should("have.text", a); - cy.get(cesc("#\\/b2")).should("have.text", "j"); - cy.get(cesc("#\\/c2")).should("have.text", c); - - cy.get(cesc("#\\/f1")).click(); - cy.get(cesc("#\\/f2")).click(); - - cy.get(cesc("#\\/af")).should("have.text", "true"); - cy.get(cesc("#\\/bf")).should("have.text", "true"); - cy.get(cesc("#\\/cf")).should("have.text", "false"); - cy.get(cesc("#\\/a2f")).should("have.text", "true"); - cy.get(cesc("#\\/b2f")).should("have.text", "true"); - cy.get(cesc("#\\/c2f")).should("have.text", "false"); - - cy.get(cesc("#\\/a3_input")).clear().type("l{enter}"); - cy.get(cesc("#\\/b3_input")).clear().type("m{enter}"); - cy.get(cesc("#\\/c3_input")).clear().type("n{enter}"); - - cy.get(cesc("#\\/a")).should("have.text", a); - cy.get(cesc("#\\/b")).should("have.text", "j"); - cy.get(cesc("#\\/c")).should("have.text", "n"); - cy.get(cesc("#\\/a2")).should("have.text", a); - cy.get(cesc("#\\/b2")).should("have.text", "j"); - cy.get(cesc("#\\/c2")).should("have.text", "n"); - - cy.get(cesc("#\\/a4_input")).clear().type("o{enter}"); - cy.get(cesc("#\\/b4_input")).clear().type("p{enter}"); - cy.get(cesc("#\\/c4_input")).clear().type("q{enter}"); - - cy.get(cesc("#\\/a")).should("have.text", a); - cy.get(cesc("#\\/b")).should("have.text", "j"); - cy.get(cesc("#\\/c")).should("have.text", "q"); - cy.get(cesc("#\\/a2")).should("have.text", a); - cy.get(cesc("#\\/b2")).should("have.text", "j"); - cy.get(cesc("#\\/c2")).should("have.text", "q"); - }); - }); - - it("numToSelect from selectfromsequence", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -n1 =
nums =
a1=$a1, b1=$b1, c1=$c1, d1=$d1, e1=$e1
- -n2 =
nums =
a2=$a2, b2=$b2, c2=$c2, d2=$d2, e2=$e2
- -n3 =
nums =
a3=$a3, b3=$b3, c3=$c3, d3=$d3, e3=$e3
- -n4 =
nums =
a4=$a4, b4=$b4, c4=$c4, d4=$d4, e4=$e4
- -n5 =
nums =
a5=$a5, b5=$b5, c5=$c5, d5=$d5, e5=$e5
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/n1"].stateValues.value; - let n2 = stateVariables["/n2"].stateValues.value; - let n3 = stateVariables["/n3"].stateValues.value; - let n4 = stateVariables["/n4"].stateValues.value; - let n5 = stateVariables["/n5"].stateValues.value; - - let nums1 = stateVariables["/nums1"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums2 = stateVariables["/nums2"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums3 = stateVariables["/nums3"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums4 = stateVariables["/nums4"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums5 = stateVariables["/nums5"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - - expect(nums1.length).eq(n1); - expect(nums2.length).eq(n2); - expect(nums3.length).eq(n3); - expect(nums4.length).eq(n4); - expect(nums5.length).eq(n5); - - nums1.length = 5; - nums2.length = 5; - nums3.length = 5; - nums4.length = 5; - nums5.length = 5; - - nums1.fill("", n1); - nums2.fill("", n2); - nums3.fill("", n3); - nums4.fill("", n4); - nums5.fill("", n5); - - let l = ["a", "b", "c", "d", "e"]; - - cy.get(cesc("#\\/p1")).should( - "have.text", - nums1.map((v, i) => `${l[i]}1=${v}`).join(", "), - ); - cy.get(cesc("#\\/p2")).should( - "have.text", - nums2.map((v, i) => `${l[i]}2=${v}`).join(", "), - ); - cy.get(cesc("#\\/p3")).should( - "have.text", - nums3.map((v, i) => `${l[i]}3=${v}`).join(", "), - ); - cy.get(cesc("#\\/p4")).should( - "have.text", - nums4.map((v, i) => `${l[i]}4=${v}`).join(", "), - ); - cy.get(cesc("#\\/p5")).should( - "have.text", - nums5.map((v, i) => `${l[i]}5=${v}`).join(", "), - ); - }); - }); - - it("rounding", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -Number to exclude:
Number to exclude: