diff --git a/packages/doenetml-worker/src/Core.js b/packages/doenetml-worker/src/Core.js index 50ffcbb41..6e447020c 100644 --- a/packages/doenetml-worker/src/Core.js +++ b/packages/doenetml-worker/src/Core.js @@ -400,7 +400,7 @@ export default class Core { this.updateInfo.componentsToUpdateRenderers.clear(); - // evalute itemCreditAchieved so that will be fresh + // evaluate itemCreditAchieved so that will be fresh // and can detect changes when it is marked stale await this.document.stateValues.itemCreditAchieved; diff --git a/packages/doenetml-worker/src/components/SamplePrimeNumbers.js b/packages/doenetml-worker/src/components/SamplePrimeNumbers.js index c5cf1d8eb..c66a9958b 100644 --- a/packages/doenetml-worker/src/components/SamplePrimeNumbers.js +++ b/packages/doenetml-worker/src/components/SamplePrimeNumbers.js @@ -59,9 +59,9 @@ export default class SamplePrimeNumbers extends CompositeComponent { }; attributes.variantDeterminesSeed = { - createComponentOfType: "boolean", + createPrimitiveOfType: "boolean", createStateVariable: "variantDeterminesSeed", - defaultValue: false, + defaultPrimitiveValue: false, public: true, }; @@ -358,8 +358,21 @@ export default class SamplePrimeNumbers extends CompositeComponent { ); } - static determineNumberOfUniqueVariants() { - return { success: false }; + static determineNumberOfUniqueVariants({ + serializedComponent, + componentInfoObjects, + }) { + let variantDeterminesSeed = + serializedComponent.attributes.variantDeterminesSeed.primitive; + + if (variantDeterminesSeed) { + return { success: false }; + } else { + return super.determineNumberOfUniqueVariants({ + serializedComponent, + componentInfoObjects, + }); + } } async resample({ diff --git a/packages/doenetml-worker/src/components/SampleRandomNumbers.js b/packages/doenetml-worker/src/components/SampleRandomNumbers.js index 0e87f49e6..7474aa05d 100644 --- a/packages/doenetml-worker/src/components/SampleRandomNumbers.js +++ b/packages/doenetml-worker/src/components/SampleRandomNumbers.js @@ -102,9 +102,9 @@ export default class SampleRandomNumbers extends CompositeComponent { } attributes.variantDeterminesSeed = { - createComponentOfType: "boolean", + createPrimitiveOfType: "boolean", createStateVariable: "variantDeterminesSeed", - defaultValue: false, + defaultPrimitiveValue: false, public: true, }; @@ -776,7 +776,17 @@ export default class SampleRandomNumbers extends CompositeComponent { serializedComponent, componentInfoObjects, }) { - return { success: false }; + let variantDeterminesSeed = + serializedComponent.attributes.variantDeterminesSeed.primitive; + + if (variantDeterminesSeed) { + return { success: false }; + } else { + return super.determineNumberOfUniqueVariants({ + serializedComponent, + componentInfoObjects, + }); + } } async resample({ diff --git a/packages/doenetml-worker/src/components/SelectRandomNumbers.js b/packages/doenetml-worker/src/components/SelectRandomNumbers.js index 25af1b7d3..dc94d3888 100644 --- a/packages/doenetml-worker/src/components/SelectRandomNumbers.js +++ b/packages/doenetml-worker/src/components/SelectRandomNumbers.js @@ -238,6 +238,10 @@ export default class SelectRandomNumbers extends SampleRandomNumbers { warnings, }; } + + static determineNumberOfUniqueVariants() { + return { success: false }; + } } delete SelectRandomNumbers.stateVariableToEvaluateAfterReplacements; diff --git a/packages/doenetml-worker/src/test/assignNames/basicCopy.test.ts b/packages/doenetml-worker/src/test/assignNames/basicCopy.test.ts index 7d576271a..b7b47dd51 100644 --- a/packages/doenetml-worker/src/test/assignNames/basicCopy.test.ts +++ b/packages/doenetml-worker/src/test/assignNames/basicCopy.test.ts @@ -1,13 +1,6 @@ import { describe, expect, it, vi } from "vitest"; import { createTestCore, returnAllStateVariables } from "../utils/test-core"; -import { - movePoint, - updateBooleanInputValue, - updateMathInputValue, - updateTextInputValue, - updateValue, -} from "../utils/actions"; -import Core from "../../Core"; +import { movePoint, updateMathInputValue } from "../utils/actions"; const Mock = vi.fn(); vi.stubGlobal("postMessage", Mock); diff --git a/packages/doenetml-worker/src/test/variants/specifySingleVariant.test.ts b/packages/doenetml-worker/src/test/variants/specifySingleVariant.test.ts new file mode 100644 index 000000000..dcd13c6e0 --- /dev/null +++ b/packages/doenetml-worker/src/test/variants/specifySingleVariant.test.ts @@ -0,0 +1,1591 @@ +import { describe, expect, it, vi } from "vitest"; +import { createTestCore, returnAllStateVariables } from "../utils/test-core"; +import { + submitAnswer, + updateMathInputValue, + updateTextInputValue, +} from "../utils/actions"; +import { numberToLetters } from "@doenet/utils"; +import me from "math-expressions"; + +const Mock = vi.fn(); +vi.stubGlobal("postMessage", Mock); +vi.mock("hyperformula"); + +describe("Specifying single variant tests", async () => { + async function run_select_from_sequence_test({ + specifiedNumVariants, + specifiedSeeds, + specifiedVariantNames, + }: { + specifiedNumVariants?: number; + specifiedSeeds?: string[]; + specifiedVariantNames?: string[]; + }) { + function createDoenetML({ + numVariants, + seeds, + variantNames, + extra = "", + }: { + numVariants?: number; + seeds?: string[]; + variantNames?: string[]; + extra?: string; + }) { + let variantControl = ""; + if ( + numVariants !== undefined || + seeds !== undefined || + variantNames !== undefined + ) { + variantControl = " + Selected number: + +

+ `; + } + + async function check_variant( + variantIndex: number, + n: number, + seeds: string[], + variantNames: string[], + ) { + let variantName = variantNames[variantIndex - 1]; + let variantSeed = seeds[variantIndex - 1]; + + const stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(n); + expect( + stateVariables["/_document1"].stateValues.generatedVariantInfo, + ).eqls({ + index: variantIndex, + name: variantName, + meta: { + createdBy: "/_document1", + }, + subvariants: [ + { + indices: [n], + meta: { createdBy: "/s1" }, + }, + ], + }); + expect( + stateVariables["/_document1"].sharedParameters.variantSeed, + ).eq(variantSeed); + expect( + stateVariables["/_document1"].sharedParameters.variantIndex, + ).eq(variantIndex); + expect( + stateVariables["/_document1"].sharedParameters.variantName, + ).eq(variantName); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(variantNames); + } + + let numVariants = 100; + if (specifiedNumVariants !== undefined) { + numVariants = Math.round( + Math.max(1, Math.min(1000, specifiedNumVariants)), + ); + } + + let seeds = [...Array(numVariants).keys()].map((i) => `${i + 1}`); + if (specifiedSeeds !== undefined) { + seeds = specifiedSeeds; + } + + let variantNames = [...Array(numVariants).keys()].map((i) => + numberToLetters(i + 1, true), + ); + if (specifiedVariantNames !== undefined) { + variantNames = specifiedVariantNames; + } + + let nBySeed: Record = {}; + + // specify first variant + let doenetML = createDoenetML({ + numVariants: specifiedNumVariants, + seeds: specifiedSeeds, + variantNames: specifiedVariantNames, + extra: "hi", + }); + let core = await createTestCore({ doenetML, requestedVariantIndex: 1 }); + let stateVariables = await returnAllStateVariables(core); + nBySeed[seeds[0]] = stateVariables["/n"].stateValues.value; + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + // Number doesn't change with update + // even if change non-variant content at beginning + doenetML = createDoenetML({ + numVariants: specifiedNumVariants, + seeds: specifiedSeeds, + variantNames: specifiedVariantNames, + extra: "bye!", + }); + core = await createTestCore({ doenetML, requestedVariantIndex: 1 }); + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + if (numVariants === 1) { + // specifying any other variant gives first + core = await createTestCore({ doenetML, requestedVariantIndex: 2 }); + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + core = await createTestCore({ + doenetML, + requestedVariantIndex: 128, + }); + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + core = await createTestCore({ + doenetML, + requestedVariantIndex: -52, + }); + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + return; + } + + // Number does change for index 2 + core = await createTestCore({ doenetML, requestedVariantIndex: 2 }); + stateVariables = await returnAllStateVariables(core); + nBySeed[seeds[1]] = stateVariables["/n"].stateValues.value; + expect(nBySeed[seeds[1]]).not.eq(nBySeed[seeds[0]]); + await check_variant(2, nBySeed[seeds[1]], seeds, variantNames); + + // Number doesn't change with update + // even if change non-variant content at beginning + doenetML = createDoenetML({ + numVariants: specifiedNumVariants, + seeds: specifiedSeeds, + variantNames: specifiedVariantNames, + extra: ` + + + $mi+$ans`, + }); + core = await createTestCore({ doenetML, requestedVariantIndex: 2 }); + await check_variant(2, nBySeed[seeds[1]], seeds, variantNames); + + // Indices equal mod numVariants don't change result + doenetML = createDoenetML({ + numVariants: specifiedNumVariants, + seeds: specifiedSeeds, + variantNames: specifiedVariantNames, + }); + core = await createTestCore({ + doenetML, + requestedVariantIndex: 2 + 124 * numVariants, + }); + await check_variant(2, nBySeed[seeds[1]], seeds, variantNames); + + core = await createTestCore({ + doenetML, + requestedVariantIndex: 2 - 21 * numVariants, + }); + await check_variant(2, nBySeed[seeds[1]], seeds, variantNames); + + if (numVariants >= 4) { + // specify third variant + core = await createTestCore({ + doenetML, + requestedVariantIndex: 3 + 77 * numVariants, + }); + stateVariables = await returnAllStateVariables(core); + nBySeed[seeds[2]] = stateVariables["/n"].stateValues.value; + expect(nBySeed[seeds[2]]).not.eq(nBySeed[seeds[0]]); + expect(nBySeed[seeds[2]]).not.eq(nBySeed[seeds[1]]); + await check_variant(3, nBySeed[seeds[2]], seeds, variantNames); + + // specify fourth variant + core = await createTestCore({ + doenetML, + requestedVariantIndex: 4 + -3261 * numVariants, + }); + stateVariables = await returnAllStateVariables(core); + nBySeed[seeds[3]] = stateVariables["/n"].stateValues.value; + expect(nBySeed[seeds[3]]).not.eq(nBySeed[seeds[0]]); + expect(nBySeed[seeds[3]]).not.eq(nBySeed[seeds[1]]); + expect(nBySeed[seeds[3]]).not.eq(nBySeed[seeds[2]]); + await check_variant(4, nBySeed[seeds[3]], seeds, variantNames); + } + + // invalid index gives variant 1 + core = await createTestCore({ doenetML, requestedVariantIndex: NaN }); + await check_variant(1, nBySeed[seeds[0]], seeds, variantNames); + + // round variant index to nearest integer + core = await createTestCore({ + doenetML, + requestedVariantIndex: 2.48 + 521 * numVariants, + }); + await check_variant(2, nBySeed[seeds[1]], seeds, variantNames); + + if (specifiedSeeds) { + // randomly shuffle the specified seeds into a new order + let newSpecifiedSeeds = [...specifiedSeeds]; + for (let i = newSpecifiedSeeds.length - 1; i > 0; i--) { + const rand = Math.random(); + const j = Math.floor(rand * (i + 1)); + [newSpecifiedSeeds[i], newSpecifiedSeeds[j]] = [ + newSpecifiedSeeds[j], + newSpecifiedSeeds[i], + ]; + } + + // for all the seeds that we've tested so far, i.e., those in `nBySeed`, + // find the new variant index that is associated with that seed + // and test that the new variant index gives the same value of n + for (let seed in nBySeed) { + let variantIndex = newSpecifiedSeeds.indexOf(seed) + 1; + let doenetML = createDoenetML({ + numVariants, + seeds: newSpecifiedSeeds, + variantNames: specifiedVariantNames, + extra: `${Math.random()}`, + }); + core = await createTestCore({ + doenetML, + requestedVariantIndex: variantIndex, + }); + await check_variant( + variantIndex, + nBySeed[seed], + newSpecifiedSeeds, + variantNames, + ); + } + } + } + + it("document with no variant control", async () => { + await run_select_from_sequence_test({}); + }); + + it("document with variant control specifying seeds", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 5, + specifiedSeeds: ["50283", "25018", "52018", "2917392", "603962"], + }); + }); + + it("document with variant control specifying seeds and variant names", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 4, + specifiedSeeds: ["9026", "ab32", "0m3pf", "lm2hA"], + specifiedVariantNames: ["hi", "bye", "d", "1"], + }); + }); + + it("document with variant control specifying only number of variants", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 3, + }); + }); + + it("document with variant control specifying zero variants", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 0, + }); + }); + + it("document with variant control specifying fractional number of variants", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 3.5, + }); + }); + + it("document with variant control specifying negative fractional number of variants", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: -3.5, + }); + }); + + it("document with variant control specifying too many variants", async () => { + await run_select_from_sequence_test({ + specifiedNumVariants: 10000, + }); + }); + + it("document with variant control specifying variantNames", async () => { + async function check_variant(variantIndex: number) { + let variantNames = [ + "avocado", + "broccoli", + "carrot", + "dill", + "eggplant", + ]; + let variantName = variantNames[variantIndex - 1]; + let expectedX = variantName[0]; + + const stateVariables = await returnAllStateVariables(core); + + let x = stateVariables["/x"].stateValues.value.tree; + expect(x).eq(expectedX); + let xorig = + stateVariables[ + stateVariables[ + stateVariables["/s1"].replacements![0].componentName + ].replacements![0].componentName + ].stateValues.value.tree; + expect(xorig).eq(expectedX); + let x2 = stateVariables["/x2"].stateValues.value.tree; + expect(x2).eq(expectedX); + let x3 = + stateVariables[ + stateVariables[ + stateVariables["/x3"].replacements![0].componentName + ].replacements![0].componentName + ].stateValues.value.tree; + expect(x3).eq(expectedX); + + expect( + stateVariables["/_document1"].sharedParameters.variantSeed, + ).eq(variantIndex.toString()); + expect( + stateVariables["/_document1"].sharedParameters.variantIndex, + ).eq(variantIndex); + expect( + stateVariables["/_document1"].sharedParameters.variantName, + ).eq(variantName); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(variantNames); + } + + let createDoenetML = (extra: string) => ` + ${extra} + +

Selected variable: + +

+

Selected variable repeated: $x{name="x2"}

+

Selected variable repeated again: $s1{name="x3"}

+ `; + + // specify first variant index + let core = await createTestCore({ + doenetML: createDoenetML(`hi`), + requestedVariantIndex: 1, + }); + await check_variant(1); + + // specify third variant index + core = await createTestCore({ + doenetML: createDoenetML(`bye`), + requestedVariantIndex: 3, + }); + await check_variant(3); + + // specify large variant index + core = await createTestCore({ + doenetML: createDoenetML(`big`), + requestedVariantIndex: 20582310, + }); + await check_variant(5); + + // specify negative variant index + core = await createTestCore({ + doenetML: createDoenetML(``), + requestedVariantIndex: -20582308, + }); + await check_variant(2); + + // invalid variant index gives index 1 + core = await createTestCore({ + doenetML: createDoenetML(``), + requestedVariantIndex: -NaN, + }); + await check_variant(1); + + // round non-integer variant index + core = await createTestCore({ + doenetML: createDoenetML(``), + requestedVariantIndex: 4.5, + }); + await check_variant(5); + }); + + it("nested selects", async () => { + let doenetML = ` + + + + + + + + + +

+ + + + +

Enter item $item as text: $(p/item)

+ `; + + let firstStringsToInd = { + "Favorite color:": 0, + "Selected number:": 1, + "Chosen letter:": 2, + "Variable:": 3, + }; + + // Test a bunch of variants + for (let ind = 1; ind <= 5; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: Math.round(Math.random() * 1000), + }); + + let stateVariables = await returnAllStateVariables(core); + let p = stateVariables["/p"]; + + let variantInd = firstStringsToInd[p.activeChildren[0].trim()]; + expect(variantInd).not.eq(undefined); + + let secondValue = + stateVariables[p.activeChildren[1].componentName].stateValues + .value; + + if (variantInd === 0) { + let i = [ + "red", + "orange", + "green", + "white", + "chartreuse", + ].indexOf(secondValue); + expect(i).not.eq(-1); + } else if (variantInd === 1) { + let num = secondValue; + expect(Number.isInteger(num)).eq(true); + if (num > 0) { + expect(num).gte(1000); + expect(num).lte(2000); + } else { + expect(num).gte(-1000); + expect(num).lte(-900); + } + } else if (variantInd === 2) { + let i = ["a", "b", "c", "d", "e", "f", "g"].indexOf( + secondValue, + ); + expect(i).not.eq(-1); + } else { + let i = ["u", "v", "w", "x", "z", "y"].indexOf(secondValue); + expect(i).not.eq(-1); + } + + await updateTextInputValue({ + text: `${secondValue}`, + name: "/ti", + core, + }); + await submitAnswer({ name: "/ans", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + + await updateTextInputValue({ + text: `${secondValue}X`, + name: "/ti", + core, + }); + await submitAnswer({ name: "/ans", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(0); + + await updateTextInputValue({ + text: `${secondValue}`, + name: "/ti", + core, + }); + await submitAnswer({ name: "/ans", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + } + }); + + async function test_selected_problems( + doenetML: string, + ignoreSecondVariants = false, + ) { + let titlesToInd = { + "A word problem": 1, + "A number problem": 2, + }; + let variantOfProblemsFound: { 0: number[]; 1: number[] } = { + 0: [], + 1: [], + }; + + let originalVariantInds: number[] = []; + let originalSecondValues: (number | string)[] = []; + + // Test a bunch of variants + for (let ind = 1; ind <= 10; ind++) { + // show values don't change for same variant + for (let ind2 = 0; ind2 < 2; ind2++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let variantInds: number[] = []; + let secondValues: (number | string)[] = []; + + for (let i = 1; i <= 3; i++) { + let problem = stateVariables["/problem" + i]; + let variantInd = titlesToInd[problem.stateValues.title]; + + expect(variantInd).not.eq(undefined); + + variantInds.push(variantInd); + + let p = + stateVariables[problem.activeChildren[4].componentName]; + + if (variantInd === 1) { + expect(p.activeChildren[0].trim()).eq("Word:"); + let problemVariantInd = + [ + "angry", + "bad", + "churlish", + "drab", + "excoriated", + ].indexOf( + stateVariables[ + p.activeChildren[1].componentName + ].stateValues.value, + ) + 1; + expect(problemVariantInd).not.eq(0); + if ( + !variantOfProblemsFound[0].includes( + problemVariantInd, + ) + ) { + variantOfProblemsFound[0].push(problemVariantInd); + } + expect(problemVariantInd).eq( + problem.stateValues.generatedVariantInfo.index, + ); + } else { + expect(p.activeChildren[0].trim()).eq("Number:"); + let num = + stateVariables[p.activeChildren[1].componentName] + .stateValues.value; + expect(Number.isInteger(num)).eq(true); + expect(num >= 1 && num <= 10).eq(true); + + let problemVariantInd = + problem.stateValues.generatedVariantInfo.index; + if ( + !variantOfProblemsFound[1].includes( + problemVariantInd, + ) + ) { + variantOfProblemsFound[1].push(problemVariantInd); + } + } + + let secondValue = + stateVariables[p.activeChildren[1].componentName] + .stateValues.value; + secondValues.push(secondValue); + } + + if (ind2 === 0) { + originalVariantInds = variantInds; + originalSecondValues = secondValues; + } else { + expect(variantInds).eqls(originalVariantInds); + expect(secondValues).eqls(originalSecondValues); + } + } + } + + // make sure all problem variants were selected at least once + expect(variantOfProblemsFound[0].sort()).eqls([1, 2, 3]); + if (!ignoreSecondVariants) { + expect(variantOfProblemsFound[1].sort()).eqls([1, 2, 3, 4]); + } + } + + it("selected problems", async () => { + const doenetML = ` + + + + + + + +

+ + + + `; + + await test_selected_problems(doenetML); + }); + + it("selected problems, one outside select", async () => { + const doenetML = ` + + + A number problem + +

Number:

+
+ + + + + +

+ + + + `; + + await test_selected_problems(doenetML); + }); + + it("selected problems, one without variant control", async () => { + const doenetML = ` + + + + + + + +

+ + + + `; + + await test_selected_problems(doenetML, true); + }); + + it("select and sample random numbers", async () => { + const doenetML = ` + +

+

+

+

+ `; + + let originalNumbers: number[] = []; + + // Test a bunch of variants + for (let ind = 1; ind <= 10; ind++) { + // show values don't change for same variant + for (let ind2 = 0; ind2 < 2; ind2++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let valuesS1: number[] = + stateVariables["/s1"].stateValues.selectedValues; + let valuesS3: number[] = + stateVariables["/s3"].stateValues.selectedValues; + + let valuesS2: number[] = + stateVariables["/s2"].stateValues.sampledValues; + let valuesS4: number[] = + stateVariables["/s4"].stateValues.sampledValues; + + let allNumbers = [ + ...valuesS1, + ...valuesS2, + ...valuesS3, + ...valuesS4, + ]; + + if (ind2 === 0) { + expect(allNumbers).not.eqls(originalNumbers); + originalNumbers = allNumbers; + } else { + expect(allNumbers).eqls(originalNumbers); + } + } + } + }); + + it("choiceInputs", async () => { + let doenetML = ` + +

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

$c1.selectedValue{assignNames="c1v"}

+ `; + + // let generatedVariantInfo; + let originalChoiceOrders; + let originalChoiceTexts; + + // Test a bunch of variants + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let orderC1 = stateVariables["/c1"].stateValues.choiceOrder; + let orderC2 = stateVariables["/c2"].stateValues.choiceOrder; + + let orderC3 = stateVariables["/c3"].stateValues.choiceOrder; + let orderC4 = stateVariables["/c4"].stateValues.choiceOrder; + + let textC1 = stateVariables["/c1"].stateValues.choiceTexts; + let textC2 = stateVariables["/c2"].stateValues.choiceTexts; + + let textC3 = stateVariables["/c3"].stateValues.choiceTexts; + let textC4 = stateVariables["/c4"].stateValues.choiceTexts; + + let allOrders = [...orderC1, ...orderC2, ...orderC3, ...orderC4]; + let allTexts = [...textC1, ...textC2, ...textC3, ...textC4]; + expect(allOrders).not.eqls(originalChoiceOrders); + originalChoiceOrders = allOrders; + expect(allTexts).not.eqls(originalChoiceTexts); + originalChoiceTexts = allTexts; + } + }); + + it("excluded sequence items", async () => { + let doenetML = ` + + + +

Enter $m: $m

+

Enter $n: $n

+ + `; + + // Test a bunch of variants + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let m = stateVariables["/m"].stateValues.value; + let n = stateVariables["/n"].stateValues.value; + + await updateMathInputValue({ latex: `${m}`, name: "/mi1", core }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ latex: `${n}`, name: "/mi2", core }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + + await updateMathInputValue({ latex: `${m}X`, name: "/mi1", core }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ latex: `${n}X`, name: "/mi2", core }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(0); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(0); + + await updateMathInputValue({ latex: `${m}`, name: "/mi1", core }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ latex: `${n}`, name: "/mi2", core }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + } + }); + + it("excluded combinations of sequence items", async () => { + let doenetML = ` + + + + +

Enter $m: $m

+

Enter $x2: $x2

+

Enter $l1: $l1

+ `; + + // Test a bunch of variants + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let m = stateVariables["/m"].stateValues.value; + let n = stateVariables["/n"].stateValues.value; + + let x1 = stateVariables["/x1"].stateValues.value; + let x2 = stateVariables["/x2"].stateValues.value; + + let l1 = stateVariables["/l1"].stateValues.value; + let l2 = stateVariables["/l2"].stateValues.value; + + await updateMathInputValue({ latex: `${m}`, name: "/mi1", core }); + await updateMathInputValue({ + latex: `${me.fromAst(x2).toString()}`, + name: "/mi2", + core, + }); + await updateTextInputValue({ text: `${l1}`, name: "/ti3", core }); + await submitAnswer({ name: "/ans1", core }); + await submitAnswer({ name: "/ans2", core }); + await submitAnswer({ name: "/ans3", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans3"].stateValues.creditAchieved).eq(1); + + await updateMathInputValue({ latex: `${m}X`, name: "/mi1", core }); + await updateMathInputValue({ + latex: `${me.fromAst(x2).toString()}X`, + name: "/mi2", + core, + }); + await updateTextInputValue({ text: `${l1}X`, name: "/ti3", core }); + await submitAnswer({ name: "/ans1", core }); + await submitAnswer({ name: "/ans2", core }); + await submitAnswer({ name: "/ans3", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(0); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(0); + expect(stateVariables["/ans3"].stateValues.creditAchieved).eq(0); + + await updateMathInputValue({ latex: `${m}`, name: "/mi1", core }); + await updateMathInputValue({ + latex: `${me.fromAst(x2).toString()}`, + name: "/mi2", + core, + }); + await updateTextInputValue({ text: `${l1}`, name: "/ti3", core }); + await submitAnswer({ name: "/ans1", core }); + await submitAnswer({ name: "/ans2", core }); + await submitAnswer({ name: "/ans3", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans3"].stateValues.creditAchieved).eq(1); + } + }); + + it("document inherits variants from single problem", async () => { + let doenetML = ` + + + + + +

Enter $fruit: + $fruit +

+
+ `; + + // get both options and then they repeat + for (let ind = 1; ind <= 3; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let fruit = ["apple", "orange"][(ind - 1) % 2]; + + let stateVariables = await returnAllStateVariables(core); + + let textinputName = + stateVariables["/ans"].stateValues.inputChildren[0] + .componentName; + + expect(stateVariables["/fruit"].stateValues.value).eq(fruit); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["apple", "orange"]); + expect( + stateVariables["/_document1"].sharedParameters.variantName, + ).eq(fruit); + + await updateTextInputValue({ + text: fruit, + name: textinputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans"].stateValues.submittedResponses).eqls([ + fruit, + ]); + + await updateTextInputValue({ + text: `${fruit}s`, + name: textinputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(0); + expect(stateVariables["/ans"].stateValues.submittedResponses).eqls([ + fruit + "s", + ]); + + await updateTextInputValue({ + text: fruit, + name: textinputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans"].stateValues.submittedResponses).eqls([ + fruit, + ]); + } + }); + + it("adding non-random component does not change what is selected in a variant", async () => { + // random piece 1 has more than 100 options so doesn't attempt to use non-random unique variants + let randomPiece1 = ` + + `; + + let randomPiece2 = ` + + `; + + let randomPiece3 = ` + + `; + + let randomPiece4 = ` +
+ + + Random number + +
+ `; + + let nonRandom1 = ` + Hello + `; + + let nonRandom2 = ` + +

one

+

two

+
+ `; + + let nonRandom3 = ` + + + + + + + `; + + let nonRandom4 = ` +
+ New section +

content

+
+ `; + + let doenetML1 = randomPiece1 + randomPiece2; + + let core = await createTestCore({ + doenetML: doenetML1, + requestedVariantIndex: 1, + }); + + let stateVariables = await returnAllStateVariables(core); + let n = stateVariables["/n"].stateValues.value; + let a = stateVariables["/a"].stateValues.value.tree; + + let doenetML2 = + randomPiece1 + + nonRandom1 + + randomPiece2 + + nonRandom2 + + nonRandom3 + + nonRandom4; + + core = await createTestCore({ + doenetML: doenetML2, + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(n); + expect(stateVariables["/a"].stateValues.value.tree).eq(a); + + let doenetML3 = + randomPiece1 + randomPiece2 + randomPiece3 + randomPiece4; + + core = await createTestCore({ + doenetML: doenetML3, + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + let n2 = stateVariables["/n"].stateValues.value; + expect(n2).not.eq(n); + n = n2; + a = stateVariables["/a"].stateValues.value.tree; + let w1 = stateVariables["/w1"].stateValues.value; + let w2 = stateVariables["/w2"].stateValues.value; + let w3 = stateVariables["/w3"].stateValues.value; + let m = stateVariables["/m"].stateValues.value; + + let doenetML4 = + randomPiece1 + + nonRandom1 + + randomPiece2 + + nonRandom2 + + randomPiece3 + + nonRandom3 + + randomPiece4 + + nonRandom4; + + core = await createTestCore({ + doenetML: doenetML4, + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(n); + expect(stateVariables["/a"].stateValues.value.tree).eq(a); + expect(stateVariables["/w1"].stateValues.value).eq(w1); + expect(stateVariables["/w2"].stateValues.value).eq(w2); + expect(stateVariables["/w3"].stateValues.value).eq(w3); + expect(stateVariables["/m"].stateValues.value).eq(m); + }); + + async function test_variants_include_exclude({ + createDoenetML, + variantsFromProblem = false, + documentAndProblemVariantsDiffer = false, + }: { + createDoenetML: ({ + include, + exclude, + }?: { + include?: string[]; + exclude?: string[]; + }) => string; + variantsFromProblem?: boolean; + documentAndProblemVariantsDiffer?: boolean; + }) { + // get two variants with no include/exclude + let values: number[] = []; + + let core = await createTestCore({ + doenetML: createDoenetML(), + requestedVariantIndex: 2, + }); + + let stateVariables = await returnAllStateVariables(core); + values.push(stateVariables["/n"].stateValues.value); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + } + + core = await createTestCore({ + doenetML: createDoenetML(), + requestedVariantIndex: 5, + }); + + stateVariables = await returnAllStateVariables(core); + values.push(stateVariables["/n"].stateValues.value); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 5, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(5); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + } + + // get same variants when add variantsToInclude + + core = await createTestCore({ + doenetML: createDoenetML({ include: ["b", "e"] }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[0]); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(documentAndProblemVariantsDiffer ? ["a", "b"] : ["b", "e"]); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ include: ["b", "e"] }), + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[1]); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "2" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "b" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(documentAndProblemVariantsDiffer ? ["a", "b"] : ["b", "e"]); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e"]); + } + + // get same variants when add variantsToExclude + + core = await createTestCore({ + doenetML: createDoenetML({ exclude: ["a", "d", "h", "j"] }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[0]); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c", "d", "e", "f"] + : ["b", "c", "e", "f", "g", "i"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "c", "e", "f", "g", "i"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ exclude: ["a", "d", "h", "j"] }), + requestedVariantIndex: 3, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[1]); + + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "3" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 3, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "c" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c", "d", "e", "f"] + : ["b", "c", "e", "f", "g", "i"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(3); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "c", "e", "f", "g", "i"]); + } + + // get same variants when add variantsToInclude and variantsToExclude + + core = await createTestCore({ + doenetML: createDoenetML({ + include: ["a", "b", "d", "e", "g", "h"], + exclude: ["a", "c", "d", "h", "j"], + }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[0]); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c"] + : ["b", "e", "g"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e", "g"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ + include: ["a", "b", "d", "e", "g", "h"], + exclude: ["a", "c", "d", "h", "j"], + }), + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(values[1]); + + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "2" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "b" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c"] + : ["b", "e", "g"], + ); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e", "g"]); + } + } + + it("variantsToInclude and variantsToExclude", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + + Selected number: + + `; + } + + await test_variants_include_exclude({ createDoenetML }); + }); + + it("variantsToInclude and variantsToExclude in problem as only child", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + + Hello! + + Selected number: + + + `; + } + + await test_variants_include_exclude({ + createDoenetML, + variantsFromProblem: true, + documentAndProblemVariantsDiffer: false, + }); + }); + + it("variantsToInclude and variantsToExclude in problem, extra child", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + Hello! + + + Selected number: + + + `; + } + + await test_variants_include_exclude({ + createDoenetML, + variantsFromProblem: true, + documentAndProblemVariantsDiffer: true, + }); + }); +}); diff --git a/packages/doenetml-worker/src/test/variants/uniqueVariants.test.ts b/packages/doenetml-worker/src/test/variants/uniqueVariants.test.ts new file mode 100644 index 000000000..de136da39 --- /dev/null +++ b/packages/doenetml-worker/src/test/variants/uniqueVariants.test.ts @@ -0,0 +1,2683 @@ +import { describe, expect, it, vi } from "vitest"; +import { createTestCore, returnAllStateVariables } from "../utils/test-core"; +import { + submitAnswer, + updateMathInputValue, + updateSelectedIndices, + updateTextInputValue, +} from "../utils/actions"; +import { numberToLetters } from "@doenet/utils"; +import me from "math-expressions"; + +const Mock = vi.fn(); +vi.stubGlobal("postMessage", Mock); +vi.mock("hyperformula"); + +describe("Unique variant tests", async () => { + it("single select", async () => { + let values = ["u", "v", "w", "x", "y", "z"]; + let doenetML = ` + + + `; + + // get all values in order and they repeat in next variants + for (let ind = 1; ind <= 18; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value.tree).eq( + values[(ind - 1) % 6], + ); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f"]); + } + }); + + it("single selectFromSequence", async () => { + let doenetML = ` + + + `; + // get all values in order and they repeat in next variants + for (let ind = 1; ind <= 15; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value).eq( + ((ind - 1) % 5) + 1, + ); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e"]); + } + }); + + it("selectFromSequence with excludes", async () => { + let doenetML = ` + + + `; + // get all values in order and they repeat in next variants + for (let ind = 1; ind <= 12; ind++) { + let letters = ["c", "e", "i", "m"]; + + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value).eq( + letters[(ind - 1) % 4], + ); + } + }); + + it("select and selectFromSequence combination", async () => { + let valuesW = ["m", "n"]; + let valuesX = ["x", "y", "z"]; + let valuesY = [2, 3, 4]; + let valuesZ = [3, 7]; + + let values: string[] = []; + for (let w of valuesW) { + for (let x of valuesX) { + for (let y of valuesY) { + for (let z of valuesZ) { + values.push([w, x, y, z].join(",")); + } + } + } + } + let valuesFound: string[] = []; + + let numVariants = + valuesW.length * valuesX.length * valuesY.length * valuesZ.length; + + let wsFound: string[] = [], + xsFound: string[] = [], + ysFound: number[] = [], + zsFound: number[] = []; + + let doenetML = ` + + + + + + + + `; + + // get all values in variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newW = stateVariables["/w"].stateValues.value; + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newW, newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 3) { + wsFound.push(newW); + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(wsFound.slice(0, 2).sort()).eqls(valuesW); + expect(xsFound.sort()).eqls(valuesX); + expect(ysFound.sort()).eqls(valuesY); + expect(zsFound.slice(0, 2).sort()).eqls(valuesZ); + + // values begin to repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 15; ind += 3) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newW = stateVariables["/w"].stateValues.value; + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newW, newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("select multiple", async () => { + let valuesSingle = ["w", "x", "y", "z"]; + let valuesFound: string[] = []; + let values: string[] = []; + for (let x of valuesSingle) { + for (let y of valuesSingle) { + if (y == x) { + continue; + } + for (let z of valuesSingle) { + if (z === x || z === y) { + continue; + } + values.push([x, y, z].join(",")); + } + } + } + + let numVariants = values.length; + + let xsFound: string[] = [], + ysFound: string[] = [], + zsFound: string[] = []; + + let doenetML = ` + + + `; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 4) { + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(xsFound.sort()).eqls(valuesSingle); + expect(ysFound.sort()).eqls(valuesSingle); + expect(zsFound.sort()).eqls(valuesSingle); + + // values begin to repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("select multiple with replacement", async () => { + let valuesSingle = ["x", "y", "z"]; + let valuesFound: string[] = []; + let values: string[] = []; + for (let x of valuesSingle) { + for (let y of valuesSingle) { + for (let z of valuesSingle) { + values.push([x, y, z].join(",")); + } + } + } + + let numVariants = values.length; + let xsFound: string[] = [], + ysFound: string[] = [], + zsFound: string[] = []; + + let doenetML = ` + + + `; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 3) { + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(xsFound.sort()).eqls(valuesSingle); + expect(ysFound.sort()).eqls(valuesSingle); + expect(zsFound.sort()).eqls(valuesSingle); + + // values begin to repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newZ = stateVariables["/z"].stateValues.value.tree; + let newValue = [newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("select multiple from sequence", async () => { + let valuesSingle = ["w", "x", "y", "z"]; + let valuesFound: string[] = []; + let values: string[] = []; + for (let x of valuesSingle) { + for (let y of valuesSingle) { + if (y == x) { + continue; + } + for (let z of valuesSingle) { + if (z === x || z === y) { + continue; + } + values.push([x, y, z].join(",")); + } + } + } + + let numVariants = values.length; + let xsFound: string[] = [], + ysFound: string[] = [], + zsFound: string[] = []; + + let doenetML = ` + + + `; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 4) { + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(xsFound.sort()).eqls(valuesSingle); + expect(ysFound.sort()).eqls(valuesSingle); + expect(zsFound.sort()).eqls(valuesSingle); + + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("select multiple from sequence with replacement", async () => { + let valuesSingle = ["x", "y", "z"]; + let valuesFound: string[] = []; + let values: string[] = []; + for (let x of valuesSingle) { + for (let y of valuesSingle) { + for (let z of valuesSingle) { + values.push([x, y, z].join(",")); + } + } + } + + let numVariants = values.length; + let xsFound: string[] = [], + ysFound: string[] = [], + zsFound: string[] = []; + + let doenetML = ` + + + `; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 3) { + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(xsFound.sort()).eqls(valuesSingle); + expect(ysFound.sort()).eqls(valuesSingle); + expect(zsFound.sort()).eqls(valuesSingle); + + // values begin to repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("limit variants", async () => { + let valuesSingle = ["u", "v", "w", "x", "y", "z"]; + let valuesFound: string[] = []; + let values: string[] = []; + for (let w of valuesSingle) { + for (let x of valuesSingle) { + for (let y of valuesSingle) { + for (let z of valuesSingle) { + values.push([w, x, y, z].join(",")); + } + } + } + } + + let numVariants = 10; + let wsFound: string[] = [], + xsFound: string[] = [], + ysFound: string[] = [], + zsFound: string[] = []; + + let doenetML = ` + + + `; + + // get unique values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newW = stateVariables["/w"].stateValues.value; + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newW, newX, newY, newZ].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + + if (ind <= 6) { + wsFound.push(newW); + xsFound.push(newX); + ysFound.push(newY); + zsFound.push(newZ); + } + } + + // all individual options selected in first variants + expect(wsFound.sort()).eqls(valuesSingle); + expect(xsFound.sort()).eqls(valuesSingle); + expect(ysFound.sort()).eqls(valuesSingle); + expect(zsFound.sort()).eqls(valuesSingle); + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= 2 * numVariants + 3; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + // to wait for page to load + + let stateVariables = await returnAllStateVariables(core); + let newW = stateVariables["/w"].stateValues.value; + let newX = stateVariables["/x"].stateValues.value; + let newY = stateVariables["/y"].stateValues.value; + let newZ = stateVariables["/z"].stateValues.value; + let newValue = [newW, newX, newY, newZ].join(","); + + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("selects of selectFromSequence", async () => { + let valuesFound: number[] = []; + let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; + let numVariants = values.length; + + let doenetML = ` + + + `; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x"].stateValues.value; + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); + + if (ind === 3) { + // all individual groups selected in first variants + expect(valuesFound.some((x) => x <= 2)).eq(true); + expect(valuesFound.some((x) => x >= 101 && x <= 103)).eq(true); + expect(valuesFound.some((x) => x >= 201 && x <= 204)).eq(true); + } + + if (ind === 6) { + // all individual groups selected twice in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(2); + } + + if (ind === 8) { + // most individual groups selected three times in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(3); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(3); + } + } + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x"].stateValues.value; + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("selects of selects", async () => { + let valuesFound: number[] = []; + let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; + let numVariants = values.length; + + let doenetML = ` + + 1 2 + + + + + `; + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x"].stateValues.value.tree; + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); + + if (ind === 3) { + // all individual groups selected in first variants + expect(valuesFound.some((x) => x <= 2)).eq(true); + expect(valuesFound.some((x) => x >= 101 && x <= 103)).eq(true); + expect(valuesFound.some((x) => x >= 201 && x <= 204)).eq(true); + } + + if (ind === 6) { + // all individual groups selected twice in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(2); + } + + if (ind === 8) { + // most individual groups selected three times in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(3); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(3); + } + } + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x"].stateValues.value.tree; + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("selects of paragraphs of selects/selectFromSequence", async () => { + let valuesFound: number[] = []; + let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; + let numVariants = values.length; + + let doenetML = ` + + 1 2

+ + + + + `; + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x/n"].stateValues.value; + if (newValue.tree !== undefined) { + newValue = newValue.tree; + } + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); + + if (ind === 3) { + // all individual groups selected in first variants + expect(valuesFound.some((x) => x <= 2)).eq(true); + expect(valuesFound.some((x) => x >= 101 && x <= 103)).eq(true); + expect(valuesFound.some((x) => x >= 201 && x <= 204)).eq(true); + } + + if (ind === 6) { + // all individual groups selected twice in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(2); + } + + if (ind === 8) { + // most individual groups selected three times in first variants + expect( + valuesFound.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), + ).eq(2); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(3); + expect( + valuesFound.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(3); + } + } + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newValue = stateVariables["/x/n"].stateValues.value; + if (newValue.tree !== undefined) { + newValue = newValue.tree; + } + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("selects of selects, select multiple", async () => { + let valuesFound: string[] = []; + let valuesSingle = [1, 2, 101, 102, 103, 201, 202, 203, 204]; + let values: string[] = []; + for (let x of valuesSingle) { + for (let y of valuesSingle) { + if (Math.abs(y - x) > 5) { + values.push([x, y].join(",")); + } + } + } + let numVariants = values.length; + + let doenetML = ` + + + 1 2 + + + + + + `; + + // get unique values in first variants + for (let ind = 1; ind <= 20; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newValue = [newX, newY].join(","); + expect(values.includes(newValue)).eq(true); + expect(valuesFound.includes(newValue)).eq(false); + valuesFound.push(newValue); + } + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 20; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let newX = stateVariables["/x"].stateValues.value.tree; + let newY = stateVariables["/y"].stateValues.value.tree; + let newValue = [newX, newY].join(","); + expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); + } + + // selects all individual groups equally in first variants + let valuesFound1: number[] = []; + let valuesFound2: number[] = []; + for (let pass = 0; pass < 12; pass++) { + for (let ind = pass * 3 + 1; ind <= (pass + 1) * 3; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + valuesFound1.push(stateVariables["/x"].stateValues.value.tree); + valuesFound2.push(stateVariables["/y"].stateValues.value.tree); + } + expect(valuesFound1.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0)).eq( + pass + 1, + ); + expect( + valuesFound1.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(pass + 1); + expect( + valuesFound1.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(pass + 1); + expect(valuesFound2.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0)).eq( + pass + 1, + ); + expect( + valuesFound2.reduce( + (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), + 0, + ), + ).eq(pass + 1); + expect( + valuesFound2.reduce( + (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), + 0, + ), + ).eq(pass + 1); + } + }); + + it("deeper nesting of selects/selectFromSequence", async () => { + let doenetML = ` + + + + + + +

+ + + + + + `; + + let valuesFound: string[] = []; + + let colorsA = [ + "red", + "orange", + "yellow", + "magenta", + "maroon", + "fuchsia", + "scarlet", + ]; + let colorsB = ["green", "chartreuse", "turquoise"]; + let colorsC = ["white", "black"]; + let allColors = [...colorsA, ...colorsB, ...colorsC]; + + let letters = [...Array(26)].map((_, i) => + String.fromCharCode("a".charCodeAt(0) + i), + ); + + let variables = ["u", "v", "w", "x", "y", "z"]; + + let categories = [ + "Favorite color:", + "Selected number:", + "Chosen letter:", + "Variable:", + ]; + + let numVariants = 24; + + let colorsFound: string[] = []; + let numbersFound: number[] = []; + let lettersFound: string[] = []; + let variablesFound: string[] = []; + let categoriesFound: string[] = []; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let category = stateVariables["/p"].activeChildren[0].trim(); + expect(categories.includes(category)).eq(true); + + let component = + stateVariables[ + stateVariables["/p"].activeChildren.filter( + (x) => x.componentName, + )[0].componentName + ]; + let newValue = component.stateValues.value; + if (category === categories[0]) { + expect(allColors.includes(newValue)).eq(true); + colorsFound.push(newValue); + } else if (category === categories[1]) { + let validNum = + Number.isInteger(newValue) && + ((newValue >= 1000 && newValue <= 2000) || + (newValue >= -1000 && newValue <= -900)); + expect(validNum).eq(true); + numbersFound.push(newValue); + } else if (category === categories[2]) { + expect(letters.includes(newValue)).eq(true); + lettersFound.push(newValue); + } else { + newValue = newValue.tree; + expect(variables.includes(newValue)).eq(true); + variablesFound.push(newValue); + } + + let combinedValue = [category, newValue].join(","); + + expect(valuesFound.includes(combinedValue)).eq(false); + valuesFound.push(combinedValue); + + categoriesFound.push(category); + + if (ind === 4) { + // all individual groups selected in first variants + for (let ind = 0; ind < 4; ind++) { + expect(categoriesFound.includes(categories[ind])).eq(true); + } + } + + if (ind === 8) { + // all individual groups selected twice in first variants + for (let ind = 0; ind < 4; ind++) { + expect( + categoriesFound.slice(4, 8).includes(categories[ind]), + ).eq(true); + } + } + } + + // the 24 values are distributed 6 to each category and evenly distributed across subcategories + let colorsFoundSet = new Set(colorsFound); + expect(colorsFoundSet.size).eq(6); + expect( + colorsA.reduce((a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), 0), + ).eq(2); + expect( + colorsB.reduce((a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), 0), + ).eq(2); + expect( + colorsC.reduce((a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), 0), + ).eq(2); + + expect(numbersFound.reduce((a, c) => a + (c > 0 ? 1 : 0), 0)).eq(3); + expect(numbersFound.reduce((a, c) => a + (c < 0 ? 1 : 0), 0)).eq(3); + + expect(lettersFound.length).eq(6); + expect(variablesFound.length).eq(6); + + expect(variablesFound.sort()).eqls(variables); + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let category = stateVariables["/p"].activeChildren[0].trim(); + let component = + stateVariables[ + stateVariables["/p"].activeChildren.filter( + (x) => x.componentName, + )[0].componentName + ]; + let newValue = component.stateValues.value; + if (newValue.tree !== undefined) { + newValue = newValue.tree; + } + let combinedValue = [category, newValue].join(","); + expect(combinedValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("select problems of selects/selectFromSequence", async () => { + let doenetML = ` + + + + + +

Enter the color $(p/color): $(p/color)

+ + + + + +

Enter the word $(p/word): $(p/word)

+ + + + + `; + + let valuesFound: string[] = []; + + let colorsA = [ + "red", + "orange", + "yellow", + "magenta", + "maroon", + "fuchsia", + "scarlet", + ]; + let colorsB = ["green", "chartreuse", "turquoise"]; + let allColors = [...colorsA, ...colorsB]; + + let wordsA = ["run", "walk", "jump", "skip"]; + let wordsB = [ + "soft", + "scary", + "large", + "empty", + "residual", + "limitless", + ]; + let allWords = [...wordsA, ...wordsB]; + + let letters = [...Array(26)].map((_, i) => + String.fromCharCode("a".charCodeAt(0) + i), + ); + + let categories = ["Favorite color", "Selected word", "Chosen letter"]; + + let numVariants = 6; + + let categoriesFound: string[] = []; + let colorsFound: string[] = []; + let wordsFound: string[] = []; + let lettersFound: string[] = []; + + // get all values in first variants + for (let ind = 1; ind <= numVariants; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let textinputName = + stateVariables[`/problem/ans`].stateValues.inputChildren[0] + .componentName; + let category = stateVariables["/problem"].stateValues.title; + expect(categories.includes(category)).eq(true); + + let component = + stateVariables[ + stateVariables[ + stateVariables["/problem"].activeChildren.filter( + (x) => x.componentName, + )[1].componentName + ].activeChildren[1].componentName + ]; + let newValue = component.stateValues.value; + if (category === categories[0]) { + expect(allColors.includes(newValue)).eq(true); + colorsFound.push(newValue); + } else if (category === categories[1]) { + expect(allWords.includes(newValue)).eq(true); + wordsFound.push(newValue); + } else if (category === categories[2]) { + expect(letters.includes(newValue)).eq(true); + lettersFound.push(newValue); + } + + let combinedValue = [category, newValue].join(","); + + expect(valuesFound.includes(combinedValue)).eq(false); + valuesFound.push(combinedValue); + + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f"]); + + categoriesFound.push(category); + + if (ind === 3) { + // all individual groups selected in first variants + for (let ind = 0; ind < 3; ind++) { + expect(categoriesFound.includes(categories[ind])).eq(true); + } + } + + if (ind === 6) { + // all individual groups selected twice in first variants + for (let ind = 0; ind < 3; ind++) { + expect( + categoriesFound.slice(3).includes(categories[ind]), + ).eq(true); + } + } + + await updateTextInputValue({ + text: `${newValue}`, + name: textinputName, + core, + }); + await submitAnswer({ name: `/problem/ans`, core }); + stateVariables = await returnAllStateVariables(core); + expect( + stateVariables["/problem/ans"].stateValues.creditAchieved, + ).eq(1); + expect( + stateVariables["/problem/ans"].stateValues.submittedResponses, + ).eqls([newValue]); + expect(stateVariables[textinputName].stateValues.value).eq( + newValue, + ); + + await updateTextInputValue({ + text: `${newValue}X`, + name: textinputName, + core, + }); + await submitAnswer({ name: `/problem/ans`, core }); + + stateVariables = await returnAllStateVariables(core); + expect( + stateVariables["/problem/ans"].stateValues.creditAchieved, + ).eq(0); + expect( + stateVariables["/problem/ans"].stateValues.submittedResponses, + ).eqls([newValue + "X"]); + expect(stateVariables[textinputName].stateValues.value).eq( + newValue + "X", + ); + + await updateTextInputValue({ + text: `${newValue}`, + name: textinputName, + core, + }); + await submitAnswer({ name: `/problem/ans`, core }); + + stateVariables = await returnAllStateVariables(core); + expect( + stateVariables["/problem/ans"].stateValues.creditAchieved, + ).eq(1); + expect( + stateVariables["/problem/ans"].stateValues.submittedResponses, + ).eqls([newValue]); + expect(stateVariables[textinputName].stateValues.value).eq( + newValue, + ); + } + + let colorsFoundSet = new Set(colorsFound); + expect(colorsFoundSet.size).eq(2); + expect( + colorsA.reduce((a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), 0), + ).eq(1); + expect( + colorsB.reduce((a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), 0), + ).eq(1); + + let wordsFoundSet = new Set(wordsFound); + expect(wordsFoundSet.size).eq(2); + expect( + wordsA.reduce((a, c) => a + (wordsFoundSet.has(c) ? 1 : 0), 0), + ).eq(1); + expect( + wordsB.reduce((a, c) => a + (wordsFoundSet.has(c) ? 1 : 0), 0), + ).eq(1); + + // values repeat in next variants + for (let ind = numVariants + 1; ind <= numVariants + 6; ind += 2) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let category = stateVariables["/problem"].stateValues.title; + let component = + stateVariables[ + stateVariables[ + stateVariables["/problem"].activeChildren.filter( + (x) => x.componentName, + )[1].componentName + ].activeChildren[1].componentName + ]; + let newValue = component.stateValues.value; + let combinedValue = [category, newValue].join(","); + expect(combinedValue).eq(valuesFound[(ind - 1) % numVariants]); + } + }); + + it("can get unique with map without variants", async () => { + let doenetML = ` + + + + + + + + +

N:

+ `; + + // get all values in order and they repeat in next variants + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value).eq( + ((ind - 1) % 3) + 1, + ); + expect(stateVariables["/p1"].stateValues.text).eq("letter: a"); + expect(stateVariables["/p2"]).be.undefined; + + await updateMathInputValue({ latex: "3", name: "/n", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/p1"].stateValues.text).eq("letter: a"); + expect(stateVariables["/p2"].stateValues.text).eq("letter: b"); + expect(stateVariables["/p3"].stateValues.text).eq("letter: c"); + + expect(stateVariables["/x"].stateValues.value).eq( + ((ind - 1) % 3) + 1, + ); + expect( + stateVariables[ + stateVariables["/p1"].activeChildren[1].componentName + ].stateValues.value, + ).eq("a"); + expect( + stateVariables[ + stateVariables["/p2"].activeChildren[1].componentName + ].stateValues.value, + ).eq("b"); + expect( + stateVariables[ + stateVariables["/p3"].activeChildren[1].componentName + ].stateValues.value, + ).eq("c"); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c"]); + + await updateMathInputValue({ latex: "4", name: "/n", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/p1"].stateValues.text).eq("letter: a"); + expect(stateVariables["/p2"].stateValues.text).eq("letter: b"); + expect(stateVariables["/p3"].stateValues.text).eq("letter: c"); + expect(stateVariables["/p4"].stateValues.text).eq("letter: d"); + } + }); + + async function test_shuffled_choice_input( + doenetML: string, + insiderAnswer = false, + ) { + let ordersFound: string[] = []; + let choices = ["red", "blue", "green"]; + + // get all orders in first 6 variants + for (let ind = 1; ind <= 6; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + let stateVariables = await returnAllStateVariables(core); + + let ciName = "/ci"; + if (insiderAnswer) { + ciName = + stateVariables["/ans"].stateValues.inputChildren[0] + .componentName; + } + + let choiceOrder = stateVariables[ciName].stateValues.choiceOrder; + let selectedOrder = choiceOrder.join(","); + expect(ordersFound.includes(selectedOrder)).eq(false); + ordersFound.push(selectedOrder); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f"]); + + for (let i = 0; i < 3; i++) { + await updateSelectedIndices({ + name: ciName, + selectedIndices: [i + 1], + core, + }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables[ciName].stateValues.selectedValues).eqls([ + choices[choiceOrder[i] - 1], + ]); + } + + await updateSelectedIndices({ + name: ciName, + selectedIndices: [1], + core, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables[ciName].stateValues.selectedValues).eqls([ + choices[choiceOrder[0] - 1], + ]); + } + + // 7th variant repeats first order + let ind = 7; + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let ciName = "/ci"; + if (insiderAnswer) { + ciName = + stateVariables["/ans"].stateValues.inputChildren[0] + .componentName; + } + let choiceOrder = stateVariables[ciName].stateValues.choiceOrder; + let selectedOrder = choiceOrder.join(","); + expect(selectedOrder).eq(ordersFound[0]); + } + + it("single shuffled choiceInput", async () => { + let doenetML = ` + + + red + blue + green + + + `; + + await test_shuffled_choice_input(doenetML); + }); + + it("single shuffled choiceInput, choices copied in", async () => { + let doenetML = ` + + red + + blue + green + + + + + + + `; + + await test_shuffled_choice_input(doenetML); + }); + + it("single shuffled choiceInput sugared inside answer", async () => { + let doenetML = ` + + red + blue + green + + + `; + + await test_shuffled_choice_input(doenetML, true); + }); + + it("shuffled choiceInput with selectFromSequence in choices", async () => { + let doenetML = ` + + + + + + `; + + let selectionsFound: string[] = []; + + // get all options in first 8 variants + for (let ind = 1; ind <= 8; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; + let n = stateVariables["/n"].stateValues.value; + let l = stateVariables["/l"].stateValues.value; + let choices = [n.toString(), l]; + let selectedOption = [...choiceOrder, ...choices].join(","); + expect(selectionsFound.includes(selectedOption)).eq(false); + selectionsFound.push(selectedOption); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h"]); + + for (let i = 0; i < 2; i++) { + await updateSelectedIndices({ + name: "/ci", + selectedIndices: [i + 1], + core, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ci"].stateValues.selectedValues).eqls([ + choices[choiceOrder[i] - 1], + ]); + } + + await updateSelectedIndices({ + name: "/ci", + selectedIndices: [1], + core, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ci"].stateValues.selectedValues).eqls([ + choices[choiceOrder[0] - 1], + ]); + } + + let ind = 9; + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; + let n = stateVariables["/n"].stateValues.value; + let l = stateVariables["/l"].stateValues.value; + let choices = [n.toString(), l]; + let selectedOption = [...choiceOrder, ...choices].join(","); + expect(selectedOption).eq(selectionsFound[0]); + }); + + async function test_shuffle(doenetML: string) { + let ordersFound: string[] = []; + let colors = ["red", "blue", "green"]; + + // get all orders in first 6 variants + for (let ind = 1; ind <= 6; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let componentOrder = + stateVariables["/sh"].stateValues.componentOrder; + expect([...componentOrder].sort()).eqls([1, 2, 3]); + + let selectedOrder = componentOrder.join(","); + expect(ordersFound.includes(selectedOrder)).eq(false); + ordersFound.push(selectedOrder); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f"]); + + expect(stateVariables["/pList"].stateValues.text).eq( + componentOrder.map((x) => colors[x - 1]).join(", "), + ); + } + + // 7th variant repeats first order + let ind = 7; + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let componentOrder = stateVariables["/sh"].stateValues.componentOrder; + let selectedOrder = componentOrder.join(","); + expect(selectedOrder).eq(ordersFound[0]); + + expect(stateVariables["/pList"].stateValues.text).eq( + componentOrder.map((x) => colors[x - 1]).join(", "), + ); + } + + it("shuffle", async () => { + let doenetML = ` + +

+ red + blue + green +

+ + `; + + await test_shuffle(doenetML); + }); + + it("shuffle, copy in components", async () => { + let doenetML = ` + + red + + blue + green + +

+ + +

+ + `; + + await test_shuffle(doenetML); + }); + + async function test_document_problem_unique({ + doenetML, + mOptions = [], + nOptions = [], + }: { + doenetML: string; + mOptions?: number[]; + nOptions?: number[]; + }) { + // Note: mOptions must be length 2 if exists + // nOptions must be length 3 if exists + + // get all 6 options and then they repeat + for (let ind = 1; ind <= 8; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + + let mathInputName = + stateVariables["/ans1"].stateValues.inputChildren[0] + .componentName; + let mathInput2Name = + stateVariables["/ans2"].stateValues.inputChildren[0] + .componentName; + + let m = mOptions[(ind - 1) % 2]; + let n = nOptions[(ind - 1) % 3]; + if (m === undefined) { + m = stateVariables["/m"].stateValues.value; + mOptions.push(m); + } else { + expect(stateVariables["/m"].stateValues.value).eq(m); + } + if (n === undefined) { + n = stateVariables["/n"].stateValues.value; + nOptions.push(n); + } else { + expect(stateVariables["/n"].stateValues.value).eq(n); + } + + console.log({ m, n, mOptions, nOptions }); + + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f"]); + + await updateMathInputValue({ + latex: `${m}`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ + latex: `${n}`, + name: mathInput2Name, + core, + }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + expect( + stateVariables["/ans1"].stateValues.submittedResponses[0].tree, + ).eq(m); + expect( + stateVariables["/ans2"].stateValues.submittedResponses[0].tree, + ).eq(n); + + await updateMathInputValue({ + latex: `${m}1`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ + latex: `${n}1`, + name: mathInput2Name, + core, + }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(0); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(0); + + expect( + stateVariables["/ans1"].stateValues.submittedResponses[0].tree, + ).eq(m * 10 + 1); + expect( + stateVariables["/ans2"].stateValues.submittedResponses[0].tree, + ).eq(n * 10 + 1); + + await updateMathInputValue({ + latex: `${m}`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans1", core }); + await updateMathInputValue({ + latex: `${n}`, + name: mathInput2Name, + core, + }); + await submitAnswer({ name: "/ans2", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans1"].stateValues.creditAchieved).eq(1); + expect(stateVariables["/ans2"].stateValues.creditAchieved).eq(1); + expect( + stateVariables["/ans1"].stateValues.submittedResponses[0].tree, + ).eq(m); + expect( + stateVariables["/ans2"].stateValues.submittedResponses[0].tree, + ).eq(n); + } + } + + it("document and problems with unique variants", async () => { + let doenetML = ` + + + +

Enter : + $m +

+
+ + +

Enter : + $n +

+
+ `; + + await test_document_problem_unique({ + doenetML, + mOptions: [1, 2], + nOptions: [3, 4, 5], + }); + }); + + it("document and problems with unique variants, even without specifying in document", async () => { + let doenetML = ` + + +

Enter : + $m +

+
+ + +

Enter : + $n +

+
+ `; + + await test_document_problem_unique({ + doenetML, + mOptions: [1, 2], + nOptions: [3, 4, 5], + }); + }); + + it("document and problems with unique variants, even without specifying in document or problem", async () => { + let doenetML = ` + +

Enter : + $m +

+
+ +

Enter : + $n +

+
+ `; + + await test_document_problem_unique({ + doenetML, + mOptions: [1, 2], + nOptions: [3, 4, 5], + }); + }); + + it("document with unique variants, from problems without unique variants", async () => { + let doenetML = ` + + + +

Enter : + $m +

+
+ + +

Enter : + $n +

+
+ `; + + await test_document_problem_unique({ doenetML }); + }); + + it("document with unique variants, from problems without unique variants, even without specifying unique", async () => { + let doenetML = ` + + +

Enter : + $m +

+
+ + +

Enter : + $n +

+
+ `; + + await test_document_problem_unique({ doenetML }); + }); + + it("document inherits variants from single problem with unique variants", async () => { + let doenetML = ` + + +

Enter : + $m +

+
+ `; + + // get all 3 options and then they repeat + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let m = ((ind - 1) % 3) + 5; + + let stateVariables = await returnAllStateVariables(core); + + let mathInputName = + stateVariables["/ans"].stateValues.inputChildren[0] + .componentName; + + expect(stateVariables["/m"].stateValues.value).eq(m); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["five", "six", "seven"]); + expect( + stateVariables["/_document1"].sharedParameters.variantName, + ).eq(["five", "six", "seven"][(ind - 1) % 3]); + + await updateMathInputValue({ + latex: `${m}`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + expect( + stateVariables["/ans"].stateValues.submittedResponses[0].tree, + ).eq(m); + + await updateMathInputValue({ + latex: `${m}1`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(0); + expect( + stateVariables["/ans"].stateValues.submittedResponses[0].tree, + ).eq(m * 10 + 1); + + await updateMathInputValue({ + latex: `${m}`, + name: mathInputName, + core, + }); + await submitAnswer({ name: "/ans", core }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/ans"].stateValues.creditAchieved).eq(1); + expect( + stateVariables["/ans"].stateValues.submittedResponses[0].tree, + ).eq(m); + } + }); + + it("no variant control, 1 unique variant", async () => { + let core = await createTestCore({ doenetML: "hello" }); + + let stateVariables = await returnAllStateVariables(core); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a"]); + }); + + it("no variant control, single select", async () => { + let doenetML = ``; + let values = ["u", "v", "w"]; + + // get all values in order and they repeat in next variants + for (let ind = 1; ind <= 4; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value.tree).eq( + values[(ind - 1) % 3], + ); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c"]); + } + }); + + it("no variant control, select and selectFromSequence", async () => { + let doenetML = ` + + + `; + let values = ["u", "v", "w"]; + + // get first values in order + for (let ind = 1; ind <= 3; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/x"].stateValues.value.tree).eq( + values[ind - 1], + ); + expect(stateVariables["/n"].stateValues.value).eq(ind); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants.length, + ).eq(30); + } + }); + + it("no variant control, 100 is still unique variants", async () => { + let doenetML = ` + + `; + // get first values in order + for (let ind = 1; ind <= 5; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(ind); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants.length, + ).eq(100); + } + }); + + it("no variant control, 101 is not unique variants", async () => { + let doenetML = ` + + `; + let foundOneNotInOrder = false; + + // don't get first values in order + for (let ind = 1; ind <= 3; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + if (stateVariables["/n"].stateValues.value !== ind) { + foundOneNotInOrder = true; + } + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants.length, + ).eq(100); + } + + expect(foundOneNotInOrder).eq(true); + }); + + it("no variant control, problem with 3 selects", async () => { + // Catch bug in enumerateCombinations + // where was indirectly overwriting numVariantsByDescendant + + let doenetML = ` + + + + + + `; + + let values = [135, 246, 145, 236, 136, 245, 146, 235]; + + // get each value exactly one, in order corresponding to above list + let valuesFound: number[] = []; + for (let ind = 1; ind <= 8; ind++) { + let core = await createTestCore({ + doenetML, + requestedVariantIndex: ind, + }); + + let stateVariables = await returnAllStateVariables(core); + let a = stateVariables["/a"].stateValues.value; + let b = stateVariables["/b"].stateValues.value; + let c = stateVariables["/c"].stateValues.value; + + let val = a * 100 + b * 10 + c; + valuesFound.push(val); + expect( + stateVariables["/_document1"].sharedParameters + .allPossibleVariants.length, + ).eq(8); + } + + expect(valuesFound).eqls(values); + }); + + async function test_variants_include_exclude({ + createDoenetML, + variantsFromProblem = false, + documentAndProblemVariantsDiffer = false, + }: { + createDoenetML: ({ + include, + exclude, + }?: { + include?: string[]; + exclude?: string[]; + }) => string; + variantsFromProblem?: boolean; + documentAndProblemVariantsDiffer?: boolean; + }) { + // get two variants with no include/exclude + + let core = await createTestCore({ + doenetML: createDoenetML(), + requestedVariantIndex: 2, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(2); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + } + + core = await createTestCore({ + doenetML: createDoenetML(), + requestedVariantIndex: 5, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(5); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 5, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(5); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); + } + + // get same variants when add variantsToInclude + + core = await createTestCore({ + doenetML: createDoenetML({ include: ["b", "e"] }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(2); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(documentAndProblemVariantsDiffer ? ["a", "b"] : ["b", "e"]); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ include: ["b", "e"] }), + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(5); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "2" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "b" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(documentAndProblemVariantsDiffer ? ["a", "b"] : ["b", "e"]); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e"]); + } + + // get same variants when add variantsToExclude + + core = await createTestCore({ + doenetML: createDoenetML({ exclude: ["a", "d", "h", "j"] }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(2); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c", "d", "e", "f"] + : ["b", "c", "e", "f", "g", "i"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "c", "e", "f", "g", "i"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ exclude: ["a", "d", "h", "j"] }), + requestedVariantIndex: 3, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(5); + + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "3" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 3, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "c" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c", "d", "e", "f"] + : ["b", "c", "e", "f", "g", "i"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(3); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "c", "e", "f", "g", "i"]); + } + + // get same variants when add variantsToInclude and variantsToExclude + + core = await createTestCore({ + doenetML: createDoenetML({ + include: ["a", "b", "d", "e", "g", "h"], + exclude: ["a", "c", "d", "h", "j"], + }), + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(2); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "1" : "2", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "a" : "b", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c"] + : ["b", "e", "g"], + ); + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "2", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(1); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "b", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e", "g"]); + } + + core = await createTestCore({ + doenetML: createDoenetML({ + include: ["a", "b", "d", "e", "g", "h"], + exclude: ["a", "c", "d", "h", "j"], + }), + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(5); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + variantsFromProblem ? "2" : "5", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + documentAndProblemVariantsDiffer ? "b" : "e", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls( + documentAndProblemVariantsDiffer + ? ["a", "b", "c"] + : ["b", "e", "g"], + ); + + if (variantsFromProblem) { + expect(stateVariables["/problem1"].sharedParameters.variantSeed).eq( + "5", + ); + expect( + stateVariables["/problem1"].sharedParameters.variantIndex, + ).eq(2); + expect(stateVariables["/problem1"].sharedParameters.variantName).eq( + "e", + ); + expect( + stateVariables["/problem1"].sharedParameters + .allPossibleVariants, + ).eqls(["b", "e", "g"]); + } + } + + it("variantsToInclude and variantsToExclude", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + + Selected number: + + `; + } + + await test_variants_include_exclude({ createDoenetML }); + }); + + it("variantsToInclude and variantsToExclude in problem as only child", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + + Hello! + + Selected number: + + + `; + } + + await test_variants_include_exclude({ + createDoenetML, + variantsFromProblem: true, + documentAndProblemVariantsDiffer: false, + }); + }); + + it("variantsToInclude and variantsToExclude in problem, extra child", async () => { + function createDoenetML({ + include = [], + exclude = [], + }: { include?: string[]; exclude?: string[] } = {}) { + let attributes = ""; + if (include.length > 0) { + attributes += `variantsToInclude="${include.join(" ")}"`; + } + if (exclude.length > 0) { + attributes += `variantsToExclude="${exclude.join(" ")}"`; + } + + return ` + Hello! + + + Selected number: + + + `; + } + + await test_variants_include_exclude({ + createDoenetML, + variantsFromProblem: true, + documentAndProblemVariantsDiffer: true, + }); + }); + + it("unique variants determined by numVariants specified, even with variantsToInclude and variantsToExclude", async () => { + // unique variants when numVariants is 1000 + + let doenetMLa = ` + + Selected number: + + `; + + let core = await createTestCore({ + doenetML: doenetMLa, + requestedVariantIndex: 1, + }); + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(20); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "20", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "t", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["t", "cv"]); + + core = await createTestCore({ + doenetML: doenetMLa, + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).eq(100); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "100", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "cv", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["t", "cv"]); + + // non-unique variants when numVariants is 100 + + let doenetMLb = ` + + Selected number: + + `; + + core = await createTestCore({ + doenetML: doenetMLb, + requestedVariantIndex: 1, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).not.eq(20); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "20", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 1, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "t", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["t", "cv"]); + + core = await createTestCore({ + doenetML: doenetMLb, + requestedVariantIndex: 2, + }); + + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).not.eq(100); + expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq( + "100", + ); + expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq( + 2, + ); + expect(stateVariables["/_document1"].sharedParameters.variantName).eq( + "cv", + ); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["t", "cv"]); + }); + + it("unless variant determines seed, sample random/prime numbers does not add variants", async () => { + // no other variants so get 1 variant + let core = await createTestCore({ + doenetML: ` + + `, + }); + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).gte(1).lte(10); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants, + ).eqls(["a"]); + + // just get 10 variants from select + core = await createTestCore({ + doenetML: ` + + + `, + }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).gte(1).lte(10000); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants + .length, + ).eq(10); + + // when variant determines seed, get 100 different variants + core = await createTestCore({ + doenetML: ` + + `, + }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).gte(1).lte(10); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants + .length, + ).eq(100); + + core = await createTestCore({ + doenetML: ` + + `, + }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/n"].stateValues.value).gte(1).lte(10000); + expect( + stateVariables["/_document1"].sharedParameters.allPossibleVariants + .length, + ).eq(100); + }); +}); diff --git a/packages/test-cypress/cypress/e2e/variants/specifysinglevariant.cy.js b/packages/test-cypress/cypress/e2e/variants/specifysinglevariant.cy.js index 65ad706df..0ad69ebfe 100644 --- a/packages/test-cypress/cypress/e2e/variants/specifysinglevariant.cy.js +++ b/packages/test-cypress/cypress/e2e/variants/specifysinglevariant.cy.js @@ -1,5 +1,4 @@ -import me from "math-expressions"; -import { cesc, cesc2, numberToLetters } from "@doenet/utils"; +import { cesc, cesc2 } from "@doenet/utils"; describe("Specifying single variant document tests", function () { beforeEach(() => { @@ -7,5547 +6,46 @@ describe("Specifying single variant document tests", function () { cy.visit("/"); }); - it("document with no variant control", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- 1 - Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - let nWithIndex1; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithIndex1 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls([ - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "aa", - "ab", - "ac", - "ad", - "ae", - "af", - "ag", - "ah", - "ai", - "aj", - "ak", - "al", - "am", - "an", - "ao", - "ap", - "aq", - "ar", - "as", - "at", - "au", - "av", - "aw", - "ax", - "ay", - "az", - "ba", - "bb", - "bc", - "bd", - "be", - "bf", - "bg", - "bh", - "bi", - "bj", - "bk", - "bl", - "bm", - "bn", - "bo", - "bp", - "bq", - "br", - "bs", - "bt", - "bu", - "bv", - "bw", - "bx", - "by", - "bz", - "ca", - "cb", - "cc", - "cd", - "ce", - "cf", - "cg", - "ch", - "ci", - "cj", - "ck", - "cl", - "cm", - "cn", - "co", - "cp", - "cq", - "cr", - "cs", - "ct", - "cu", - "cv", - ]); - }); - - cy.log("Number doesn't change with multiple updates"); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- a - Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- b - Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `b`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- c - Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - let generatedVariantInfo; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - generatedVariantInfo = JSON.parse( - JSON.stringify( - stateVariables["/_document1"].stateValues - .generatedVariantInfo, - ), - ); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - // cy.log(`Number doesn't change when use generatedVariantInfo`) - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // d - // Selected number: - // - //

- // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `d`) - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex1); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'a', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex1], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('1'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(1); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('a'); - // }) - - cy.log("Number changes for index 2"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- e - Selected number: - -

- `, - requestedVariantIndex: 2, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `e`); - - let nWithIndex2; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithIndex2 = stateVariables["/n"].stateValues.value; - expect(nWithIndex2).not.eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- f - Selected number: - -

- `, - requestedVariantIndex: 2, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `f`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- g - Selected number: - -

- `, - requestedVariantIndex: 2, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `g`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.log("Index 102 same as index 2"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- g2 - Selected number: - -

- `, - requestedVariantIndex: 102, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `g2`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- h - Selected number: - -

- `, - requestedVariantIndex: 102, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `h`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.log("Index -298 same as index 2"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- i - Selected number: - -

- `, - requestedVariantIndex: -298, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `i`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.reload(); // occasionally reload so doesn't slow way down (presumably due to garbage collection) - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- j - Selected number: - -

- `, - requestedVariantIndex: -298, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `j`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.log("Index 83057201 same as index 1"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- k - Selected number: - -

- `, - requestedVariantIndex: 83057201, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `k`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- l - Selected number: - -

- `, - requestedVariantIndex: 83057201, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `l`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - // cy.log("Variant 'a' same as index 1"); - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // m - // Selected number: - // - //

- // `, - // requestedVariant: { name: 'a' }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `m`); - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex1); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'a', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex1], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('1'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(1); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('a'); - // }) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // n - // Selected number: - // - //

- // `, - // requestedVariant: { name: 'a' }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `n`); - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex1); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'a', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex1], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('1'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(1); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('a'); - // }) - - // cy.log("Variant 'b' same as index 2"); - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // o - // Selected number: - // - //

- // `, - // requestedVariant: { name: 'b' }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `o`); - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex2); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 2, - // name: 'b', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex2], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('2'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(2); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('b'); - // }) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // q - // Selected number: - // - //

- // `, - // requestedVariant: { name: 'b' }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `q`); - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex2); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 2, - // name: 'b', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex2], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('2'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(2); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('b'); - // }) - - cy.log("Index '301' same as index 1"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- r - Selected number: - -

- `, - requestedVariantIndex: "301", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `r`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.log("Variant 'cQ' and index '95' are the same"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- s - Selected number: - -

- `, - requestedVariantIndex: "95", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `s`); - - let nWithIndex95; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithIndex95 = stateVariables["/n"].stateValues.value; - expect(nWithIndex95).not.eq(nWithIndex1); - expect(nWithIndex95).not.eq(nWithIndex2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 95, - name: "cq", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex95], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("95"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(95); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("cq"); - }); - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // t - // Selected number: - // - //

- // `, - // requestedVariant: { name: 'cQ' }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `t`); - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex95); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 95, - // name: 'cq', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex95], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('95'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(95); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('cq'); - // }) - - cy.reload(); // occasionally reload so doesn't slow way down (presumably due to garbage collection) - - cy.log(`invalid index gives variant 1`); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- u - Selected number: - -

- `, - requestedVariantIndex: "bad", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `u`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - // cy.log(`invalid name gives variant 1`) - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - //

- // v - // Selected number: - // - //

- // `, - // requestedVariant: { name: "bad" }, - // }, "*"); - // }); - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `v`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithIndex1); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'a', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [nWithIndex1], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('1'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(1); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('a'); - // }) - - cy.log(`round variant index to nearest integer`); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -

- w - Selected number: - -

- `, - requestedVariantIndex: 95.48, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `w`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithIndex95); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 95, - name: "cq", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithIndex95], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("95"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(95); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("cq"); - }); - }); - - it("document with variant control specifying variantNames", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 1 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - cy.window().then(async (win) => { - let expectedx = "a"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'avocado', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [4], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("avocado"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["avocado", "broccoli", "carrot", "dill", "eggplant"]); - }); - - cy.log("specify third variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 2 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: 3, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `2`); - - cy.window().then(async (win) => { - let expectedx = "c"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 3, - // name: 'carrot', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [2], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("carrot"); - }); - - // cy.log("specify variant bRoccoli") - // let generatedVariantInfo; - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // 3 - // - //

Selected variable: - // - //

- //

Selected variable repeated:

- //

Selected variable repeated again:

- // `, - // requestedVariant: { name: 'bRoccoli' }, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `3`) - - // cy.window().then(async (win) => { - // let expectedx = 'b'; - - // let stateVariables = await win.returnAllStateVariables1(); - // let x = stateVariables['/x'].stateValues.value; - // expect(x).eq(expectedx); - // let xorig = stateVariables[stateVariables[stateVariables['/_select1'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(xorig).eq(expectedx); - // let x2 = stateVariables[stateVariables['/x2'].replacements[0].componentName].stateValues.value; - // expect(x2).eq(expectedx); - // let x3 = stateVariables[stateVariables[stateVariables['/x3'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 2, - // name: 'broccoli', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [5], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - // generatedVariantInfo = JSON.parse(JSON.stringify(stateVariables["/_document1"].stateValues.generatedVariantInfo)) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('2'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(2); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('broccoli'); - // }) - - // cy.log("same result with previous generatedVariantInfo") - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // 3a - // - //

Selected variable: - // - //

- //

Selected variable repeated:

- //

Selected variable repeated again:

- // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `3a`) - - // cy.window().then(async (win) => { - // let expectedx = 'b'; - - // let stateVariables = await win.returnAllStateVariables1(); - // let x = stateVariables['/x'].stateValues.value; - // expect(x).eq(expectedx); - // let xorig = stateVariables[stateVariables[stateVariables['/_select1'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(xorig).eq(expectedx); - // let x2 = stateVariables[stateVariables['/x2'].replacements[0].componentName].stateValues.value; - // expect(x2).eq(expectedx); - // let x3 = stateVariables[stateVariables[stateVariables['/x3'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 2, - // name: 'broccoli', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [5], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('2'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(2); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('broccoli'); - // }) - - // cy.log("specify variant dill") - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // 4 - // - //

Selected variable: - // - //

- //

Selected variable repeated:

- //

Selected variable repeated again:

- // `, - // requestedVariant: { name: 'dill' }, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `4`) - - // cy.window().then(async (win) => { - // let expectedx = 'd'; - - // let stateVariables = await win.returnAllStateVariables1(); - // let x = stateVariables['/x'].stateValues.value; - // expect(x).eq(expectedx); - // let xorig = stateVariables[stateVariables[stateVariables['/_select1'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(xorig).eq(expectedx); - // let x2 = stateVariables[stateVariables['/x2'].replacements[0].componentName].stateValues.value; - // expect(x2).eq(expectedx); - // let x3 = stateVariables[stateVariables[stateVariables['/x3'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 4, - // name: 'dill', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [1], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('4'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(4); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('dill'); - // }) - - cy.log("specify large variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 5 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: 20582310, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `5`); - - cy.window().then(async (win) => { - let expectedx = "e"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 5, - // name: 'eggplant', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [3], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("eggplant"); - }); - - cy.log("specify negative variant index as string"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 6 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: "-20582308", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `6`); - - cy.window().then(async (win) => { - let expectedx = "b"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 2, - // name: 'broccoli', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [5], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("broccoli"); - }); - - cy.log("invalid variant index gives index 1"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 7 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: "wrong", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `7`); - - cy.window().then(async (win) => { - let expectedx = "a"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'avocado', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [4], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("avocado"); - }); - - // cy.log("invalid variant name gives index 0") - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // 8 - // - //

Selected variable: - // - //

- //

Selected variable repeated:

- //

Selected variable repeated again:

- // `, - // requestedVariant: { name: 'rotten' }, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `8`) - - // cy.window().then(async (win) => { - // let expectedx = 'a'; - - // let stateVariables = await win.returnAllStateVariables1(); - // let x = stateVariables['/x'].stateValues.value; - // expect(x).eq(expectedx); - // let xorig = stateVariables[stateVariables[stateVariables['/_select1'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(xorig).eq(expectedx); - // let x2 = stateVariables[stateVariables['/x2'].replacements[0].componentName].stateValues.value; - // expect(x2).eq(expectedx); - // let x3 = stateVariables[stateVariables[stateVariables['/x3'].replacements[0].componentName].replacements[0].componentName].stateValues.value; - // expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 1, - // name: 'avocado', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [4], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('1'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(1); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('avocado'); - // }) - - cy.log("round non-integer variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 9 - -

Selected variable: - -

-

Selected variable repeated: $x{name="x2"}

-

Selected variable repeated again: $_select1{name="x3"}

- `, - requestedVariantIndex: 4.5, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `9`); - - cy.window().then(async (win) => { - let expectedx = "e"; - - let stateVariables = await win.returnAllStateVariables1(); - let x = stateVariables["/x"].stateValues.value; - expect(x).eq(expectedx); - let xorig = - stateVariables[ - stateVariables[ - stateVariables["/_select1"].replacements[0] - .componentName - ].replacements[0].componentName - ].stateValues.value; - expect(xorig).eq(expectedx); - let x2 = stateVariables["/x2"].stateValues.value; - expect(x2).eq(expectedx); - let x3 = - stateVariables[ - stateVariables[ - stateVariables["/x3"].replacements[0].componentName - ].replacements[0].componentName - ].stateValues.value; - expect(x3).eq(expectedx); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 5, - // name: 'eggplant', - // meta: { - // createdBy: "/_document1" - // }, - // subvariants: [{ - // indices: [3], - // subvariants: [], - // meta: { createdBy: "/_select1" } - // }] - // }) - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("eggplant"); - }); - }); - - it("document with variant control specifying seeds, two different orders", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed50283; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed50283 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed50283], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("50283"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - b - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `b`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed50283); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed50283], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("50283"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.log("specify second variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - c - -

- Selected number: - -

- `, - requestedVariantIndex: 124082, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - let nWithSeed25018; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed25018 = stateVariables["/n"].stateValues.value; - expect(nWithSeed25018).not.eq(nWithSeed50283); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed25018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("25018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - d - -

- Selected number: - -

- `, - requestedVariantIndex: 124082, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `d`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed25018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed25018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("25018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.log("specify third variant"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - e - -

- Selected number: - -

- `, - requestedVariantIndex: "3", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `e`); - - let nWithSeed52018; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed52018 = stateVariables["/n"].stateValues.value; - expect(nWithSeed52018).not.eq(nWithSeed50283); - expect(nWithSeed52018).not.eq(nWithSeed25018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 3, - name: "c", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed52018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("52018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - }); - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // f - // - //

- // Selected number: - // - //

- // `, - // requestedVariant: { name: 'c' }, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `f`) - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithSeed52018); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 3, - // name: 'c', - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [nWithSeed52018], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('52018'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(3); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('c'); - // }) - - cy.log("specify fourth variant as string"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - g - -

- Selected number: - -

- `, - requestedVariantIndex: "820572309", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `g`); - - let nWithSeed2917392; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed2917392 = stateVariables["/n"].stateValues.value; - expect(nWithSeed2917392).not.eq(nWithSeed50283); - expect(nWithSeed2917392).not.eq(nWithSeed25018); - expect(nWithSeed2917392).not.eq(nWithSeed52018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 4, - name: "d", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed2917392], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2917392"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(4); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("d"); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - h - -

- Selected number: - -

- `, - requestedVariantIndex: "820572309", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `h`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed2917392); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 4, - name: "d", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed2917392], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2917392"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(4); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("d"); - }); - - cy.log("specify fifth variant as negative"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - i - -

- Selected number: - -

- `, - requestedVariantIndex: "-820572305", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `i`); - - let nWithSeed603962; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed603962 = stateVariables["/n"].stateValues.value; - expect(nWithSeed603962).not.eq(nWithSeed50283); - expect(nWithSeed603962).not.eq(nWithSeed25018); - expect(nWithSeed603962).not.eq(nWithSeed52018); - expect(nWithSeed603962).not.eq(nWithSeed2917392); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 5, - name: "e", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed603962], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("603962"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - }); - - let generatedVariantInfo; - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - j - -

- Selected number: - -

1 - `, - requestedVariantIndex: "-820572305", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `j`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed603962); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 5, - name: "e", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed603962], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - generatedVariantInfo = JSON.parse( - JSON.stringify( - stateVariables["/_document1"].stateValues - .generatedVariantInfo, - ), - ); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("603962"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - }); - - // cy.log('same results with previous generatedVariantInfo') - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // ja - // - //

- // Selected number: - // - //

1 - // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `ja`) - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithSeed603962); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 5, - // name: 'e', - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [nWithSeed603962], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('603962'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(5); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('e'); - // }) - - cy.log("reorder seeds"); - cy.log("specify first variant index"); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - k - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `k`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed2917392); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed2917392], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2917392"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.reload(); // occasionally reload so doesn't slow way down (presumably due to garbage collection) - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - l - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `l`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed2917392); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed2917392], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2917392"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - - cy.log("specify second variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - m - -

- Selected number: - -

- `, - requestedVariantIndex: 124082, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `m`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed52018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed52018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("52018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - // cy.log("specify third variant by name") - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // n - // - //

- // Selected number: - // - //

- // `, - // requestedVariant: { name: 'c' }, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `n`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - // expect(stateVariables['/n'].stateValues.value).eq(nWithSeed603962); - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls({ - // index: 3, - // name: 'c', - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [nWithSeed603962], - // meta: { createdBy: "/_selectfromsequence1" } - // }] - // }) - // expect(stateVariables["/_document1"].sharedParameters.variantSeed).eq('603962'); - // expect(stateVariables["/_document1"].sharedParameters.variantIndex).eq(3); - // expect(stateVariables["/_document1"].sharedParameters.variantName).eq('c'); - // }) - - cy.log("specify fourth variant as string"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - o - -

- Selected number: - -

- `, - requestedVariantIndex: "820572309", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `o`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed50283); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 4, - name: "d", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed50283], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("50283"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(4); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("d"); - }); - - cy.log("specify fifth variant as negative"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - p - -

- Selected number: - -

- `, - requestedVariantIndex: "-820572305", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `p`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed25018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 5, - name: "e", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed25018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("25018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - }); - }); - - it("document with variant control partially specifying seeds and variantNames", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed50283; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed50283 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "d", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed50283], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("50283"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("d"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["d", "h", "c", "e"]); - }); - - cy.log("specify second variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - c - -

- Selected number: - -

- `, - requestedVariantIndex: 124082, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - let nWithSeed25018; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed25018 = stateVariables["/n"].stateValues.value; - expect(nWithSeed25018).not.eq(nWithSeed50283); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "h", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed25018], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("25018"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("h"); - }); - - cy.log("specify third variant"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - e - -

- Selected number: - -

- `, - requestedVariantIndex: "3", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `e`); - - let nWithSeed3; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed3 = stateVariables["/n"].stateValues.value; - expect(nWithSeed3).not.eq(nWithSeed50283); - expect(nWithSeed3).not.eq(nWithSeed25018); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 3, - name: "c", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed3], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - }); - - cy.log("specify fourth variant as string"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - g - -

- Selected number: - -

- `, - requestedVariantIndex: "820572308", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `g`); - - let nWithSeed4; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed4 = stateVariables["/n"].stateValues.value; - expect(nWithSeed4).not.eq(nWithSeed50283); - expect(nWithSeed4).not.eq(nWithSeed25018); - expect(nWithSeed4).not.eq(nWithSeed3); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 4, - name: "e", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed4], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("4"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(4); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - }); - }); - - it("document with variant control specifying only number of variants", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed1; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed1 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - }); - - cy.log("specify second variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - c - -

- Selected number: - -

- `, - requestedVariantIndex: 5, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - let nWithSeed2; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed2 = stateVariables["/n"].stateValues.value; - expect(nWithSeed2).not.eq(nWithSeed1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 2, - name: "b", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed2], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - }); - - cy.log("specify third variant"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - e - -

- Selected number: - -

- `, - requestedVariantIndex: "3", - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `e`); - - let nWithSeed3; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed3 = stateVariables["/n"].stateValues.value; - expect(nWithSeed3).not.eq(nWithSeed1); - expect(nWithSeed3).not.eq(nWithSeed2); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 3, - name: "c", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed3], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - }); - }); - - it("document with variant control specifying zero variants", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 1, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed1; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed1 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a"]); - }); - - cy.log("specify second variant index gives first"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - c - -

- Selected number: - -

- `, - requestedVariantIndex: 2, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - }); - - it("document with variant control specifying fractional number of variants", () => { - cy.log("specify third variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 7, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed3; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed3 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 3, - name: "c", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed3], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d"]); - }); - }); - - it("document with variant control specifying negative fractional number of variants", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 19, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed1; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed1 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a"]); - }); - - cy.log("specify second variant index gives first"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - c - -

- Selected number: - -

- `, - requestedVariantIndex: 5, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `c`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(nWithSeed1); - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - }); - }); - - it("document with variant control specifying too many variants", () => { - cy.log("specify first variant index"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - -

- Selected number: - -

- `, - requestedVariantIndex: 1001, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - let nWithSeed1; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - nWithSeed1 = stateVariables["/n"].stateValues.value; - expect( - stateVariables["/_document1"].stateValues.generatedVariantInfo, - ).eqls({ - index: 1, - name: "a", - meta: { - createdBy: "/_document1", - }, - subvariants: [ - { - indices: [nWithSeed1], - meta: { createdBy: "/_selectfromsequence1" }, - }, - ], - }); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants.length, - ).eq(1000); - }); - }); - - it("nested selects", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - - - - - - - -

- - - - -

Enter item $item as text: $(p/item)

- `; - - let firstStringsToInd = { - "Favorite color:": 0, - "Selected number:": 1, - "Chosen letter:": 2, - "Variable:": 3, - }; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 5; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let p = stateVariables["/p"]; - - let variantInd = firstStringsToInd[p.activeChildren[0].trim()]; - expect(variantInd).not.eq(undefined); - - let secondValue = - stateVariables[p.activeChildren[1].componentName] - .stateValues.value; - - if (variantInd === 0) { - let i = [ - "red", - "orange", - "green", - "white", - "chartreuse", - ].indexOf(secondValue); - expect(i).not.eq(-1); - } else if (variantInd === 1) { - let num = secondValue; - expect(Number.isInteger(num)).eq(true); - if (num > 0) { - expect(num).gte(1000); - expect(num).lte(2000); - } else { - expect(num).gte(-1000); - expect(num).lte(-900); - } - } else if (variantInd === 2) { - let i = ["a", "b", "c", "d", "e", "f", "g"].indexOf( - secondValue, - ); - expect(i).not.eq(-1); - } else { - let i = ["u", "v", "w", "x", "z", "y"].indexOf(secondValue); - expect(i).not.eq(-1); - } - - cy.get(cesc("#\\/_textinput1_input")).type( - `${secondValue}{enter}`, - ); - cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - - cy.wait(2000); // wait for 2 second debounce - cy.reload(); - - // don't need to give requested variant here, - // as will load variant from IndexedDB given the attempt number - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/_textinput1"]; - }), - ); - - cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let p = stateVariables["/p"]; - - let variantInd2 = - firstStringsToInd[p.activeChildren[0].trim()]; - expect(variantInd2).eq(variantInd); - - let secondValue2 = - stateVariables[p.activeChildren[1].componentName] - .stateValues.value; - expect(secondValue2).eq(secondValue); - - cy.get(cesc("#\\/_textinput1_input")).type(`{end}X`); - cy.get(cesc("#\\/_textinput1_submit")).click(); - cy.get(cesc("#\\/_textinput1_incorrect")).should( - "be.visible", - ); - cy.get(cesc("#\\/_textinput1_input")).type( - `{end}{backspace}`, - ); - cy.get(cesc("#\\/_textinput1_submit")).click(); - cy.get(cesc("#\\/_textinput1_correct")).should( - "be.visible", - ); - }); - }); - } - }); - - it("selected problems", () => { - let titlesToInd = { - "A word problem": 1, - "A number problem": 2, - }; - - let variantOfProblemsFound = { - 0: [], - 1: [], - }; - - let originalVariantInds; - let originalSecondValues; - - // let generatedVariantInfo; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 10; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 2 === 0) { - cy.reload(); - } - - // show values don't change for same variant - for (let ind2 = 0; ind2 < 2; ind2++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - ${ind2} - - - - - - - - - -

- - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.get(cesc("#\\/_text2")).should("have.text", `${ind2}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: ind, - // name: numberToLetters(ind, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - let variantInds = []; - let secondValues = []; - - for (let i = 1; i <= 3; i++) { - let problem = stateVariables["/problem" + i]; - let variantInd = titlesToInd[problem.stateValues.title]; - - expect(variantInd).not.eq(undefined); - - variantInds.push(variantInd); - // generatedVariantInfo.subvariants[0].indices.push(variantInd); - - let p = - stateVariables[ - problem.activeChildren[4].componentName - ]; - - if (variantInd === 1) { - expect(p.activeChildren[0].trim()).eq("Word:"); - let problemVariantInd = - [ - "angry", - "bad", - "churlish", - "drab", - "excoriated", - ].indexOf( - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value, - ) + 1; - expect(problemVariantInd).not.eq(0); - if ( - !variantOfProblemsFound[0].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[0].push( - problemVariantInd, - ); - } - expect(problemVariantInd).eq( - problem.stateValues.generatedVariantInfo.index, - ); - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - // }) - } else { - expect(p.activeChildren[0].trim()).eq("Number:"); - let num = - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value; - expect(Number.isInteger(num)).eq(true); - expect(num >= 1 && num <= 10).eq(true); - - let problemVariantInd = - problem.stateValues.generatedVariantInfo.index; - if ( - !variantOfProblemsFound[1].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[1].push( - problemVariantInd, - ); - } - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // }) - } - - let secondValue = - stateVariables[p.activeChildren[1].componentName] - .stateValues.value; - if (secondValue === undefined) { - secondValue = - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value; - } - secondValues.push(secondValue); - } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // generatedVariantInfo.subvariants[0].subvariants - // ); - - if (ind2 === 0) { - originalVariantInds = variantInds; - originalSecondValues = secondValues; - } else { - expect(variantInds).eqls(originalVariantInds); - expect(secondValues).eqls(originalSecondValues); - } - }); - } - } - - // cy.log(`repeat last with previous generatedVariantInfo`) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // repeat - // - - // - // - // - // - // - // - // - //

- // - // - // - // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `repeat`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: 10, - // name: numberToLetters(10, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - // let variantInds = []; - // let secondValues = []; - - // for (let i = 1; i <= 3; i++) { - // let problem = stateVariables['/problem' + i]; - // let variantInd = titlesToInd[problem.stateValues.title]; - - // expect(variantInd).not.eq(undefined); - - // variantInds.push(variantInd); - // generatedVariantInfo.subvariants[0].indices.push(variantInd); - - // let p = problem.activeChildren[4]; - - // if (variantInd === 1) { - // expect(p.activeChildren[0].trim()).eq("Word:") - // let problemVariantInd = ["angry", "bad", "churlish", "drab", "excoriated"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - // expect(problemVariantInd).not.eq(0) - // if (!variantOfProblemsFound[0].includes(problemVariantInd)) { - // variantOfProblemsFound[0].push(problemVariantInd); - // } - // expect(problemVariantInd).eq(problem.stateValues.generatedVariantInfo.index) - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - // }) - // } else { - // expect(p.activeChildren[0].trim()).eq("Number:"); - // let num = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // expect(Number.isInteger(num)).eq(true); - // expect(num >= 1 && num <= 10).eq(true); - - // let problemVariantInd = problem.stateValues.generatedVariantInfo.index - // if (!variantOfProblemsFound[1].includes(problemVariantInd)) { - // variantOfProblemsFound[1].push(problemVariantInd); - // } - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // }) - // } - - // let secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // if (secondValue === undefined) { - // secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // } - // secondValues.push(secondValue); - // } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // generatedVariantInfo.subvariants[0].subvariants - // ); - - // expect(variantInds).eqls(originalVariantInds); - // expect(secondValues).eqls(originalSecondValues); - - // }) - - cy.log( - "make sure all problem variants were selected at least once", - ).then(() => { - expect(variantOfProblemsFound[0].sort()).eqls([1, 2, 3, 4, 5]); - expect(variantOfProblemsFound[1].sort()).eqls([1, 2, 3, 4]); - }); - }); - - it("selected problems, one outside select", () => { - let titlesToInd = { - "A word problem": 1, - "A number problem": 2, - }; - - let variantOfProblemsFound = { - 0: [], - 1: [], - }; - - let originalVariantInds; - let originalSecondValues; - - // let generatedVariantInfo; - // let itemVariantInfo; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 10; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 5 === 0) { - cy.reload(); - } - - // show values don't change for same variant - for (let ind2 = 0; ind2 < 2; ind2++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - ${ind2} - - - A number problem - -

Number:

-
- - - - - -

- - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.get(cesc("#\\/_text2")).should("have.text", `${ind2}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: ind, - // name: numberToLetters(ind, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [undefined, { - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - // itemVariantInfo = []; - - let variantInds = []; - let secondValues = []; - - for (let i = 1; i <= 3; i++) { - let problem = stateVariables["/problem" + i]; - let variantInd = titlesToInd[problem.stateValues.title]; - - expect(variantInd).not.eq(undefined); - - variantInds.push(variantInd); - // if (i !== 1) { - // generatedVariantInfo.subvariants[1].indices.push(variantInd); - // } - let p = - stateVariables[ - problem.activeChildren[4].componentName - ]; - - if (variantInd === 1) { - expect(p.activeChildren[0].trim()).eq("Word:"); - let problemVariantInd = - ["angry", "bad", "churlish"].indexOf( - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value, - ) + 1; - expect(problemVariantInd).not.eq(0); - if ( - !variantOfProblemsFound[0].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[0].push( - problemVariantInd, - ); - } - expect(problemVariantInd).eq( - problem.stateValues.generatedVariantInfo.index, - ); - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // let problemVariantInfo = { - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - - // } - - // itemVariantInfo.push(problemVariantInfo); - // generatedVariantInfo.subvariants[1].subvariants.push( - // problemVariantInfo - // ); - } else { - expect(p.activeChildren[0].trim()).eq("Number:"); - let num = - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value; - expect(Number.isInteger(num)).eq(true); - expect(num >= 1 && num <= 10).eq(true); - - let problemVariantInd = - problem.stateValues.generatedVariantInfo.index; - if ( - !variantOfProblemsFound[1].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[1].push( - problemVariantInd, - ); - } - // let problemVariantInfo = { - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // } - // itemVariantInfo.push(problemVariantInfo); - // if (i === 1) { - // generatedVariantInfo.subvariants[0] = problemVariantInfo - // } else { - // generatedVariantInfo.subvariants[1].subvariants.push( - // problemVariantInfo - // ); - // } - } - - let secondValue = - stateVariables[p.activeChildren[1].componentName] - .stateValues.value; - secondValues.push(secondValue); - } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // itemVariantInfo - // ); - - if (ind2 === 0) { - originalVariantInds = variantInds; - originalSecondValues = secondValues; - } else { - expect(variantInds).eqls(originalVariantInds); - expect(secondValues).eqls(originalSecondValues); - } - }); - } - } - - // cy.log(`repeat last with previous generatedVariantInfo`) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // repeat - // - - // A number problem - // - //

Number:

- //
- // - // - // - // - // - // - // - //

- // - // - // - // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `repeat`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: 10, - // name: numberToLetters(10, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [undefined, { - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - // itemVariantInfo = []; - - // let variantInds = []; - // let secondValues = []; - - // for (let i = 1; i <= 3; i++) { - // let problem = stateVariables['/problem' + i]; - // let variantInd = titlesToInd[problem.stateValues.title]; - - // expect(variantInd).not.eq(undefined); - - // variantInds.push(variantInd); - // if (i !== 1) { - // generatedVariantInfo.subvariants[1].indices.push(variantInd); - // } - // let p = problem.activeChildren[4]; - - // if (variantInd === 1) { - // expect(p.activeChildren[0].trim()).eq("Word:") - // let problemVariantInd = ["angry", "bad", "churlish", "drab", "excoriated"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - // expect(problemVariantInd).not.eq(0) - // if (!variantOfProblemsFound[0].includes(problemVariantInd)) { - // variantOfProblemsFound[0].push(problemVariantInd); - // } - // expect(problemVariantInd).eq(problem.stateValues.generatedVariantInfo.index) - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // let problemVariantInfo = { - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - - // } - - // itemVariantInfo.push(problemVariantInfo); - // generatedVariantInfo.subvariants[1].subvariants.push( - // problemVariantInfo - // ); - // } else { - // expect(p.activeChildren[0].trim()).eq("Number:"); - // let num = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // expect(Number.isInteger(num)).eq(true); - // expect(num >= 1 && num <= 10).eq(true); - - // let problemVariantInd = problem.stateValues.generatedVariantInfo.index - // if (!variantOfProblemsFound[1].includes(problemVariantInd)) { - // variantOfProblemsFound[1].push(problemVariantInd); - // } - // let problemVariantInfo = { - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // } - // itemVariantInfo.push(problemVariantInfo); - // if (i === 1) { - // generatedVariantInfo.subvariants[0] = problemVariantInfo - // } else { - // generatedVariantInfo.subvariants[1].subvariants.push( - // problemVariantInfo - // ); - // } - // } - - // let secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // if (secondValue === undefined) { - // secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // } - // secondValues.push(secondValue); - // } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // itemVariantInfo - // ); - - // expect(variantInds).eqls(originalVariantInds); - // expect(secondValues).eqls(originalSecondValues); - - // }) - - cy.log( - "make sure all problem variants were selected at least once", - ).then(() => { - expect(variantOfProblemsFound[0].sort()).eqls([1, 2, 3]); - expect(variantOfProblemsFound[1].sort()).eqls([1, 2, 3, 4]); - }); - }); - - it("selected problems, one without variant control", () => { - let titlesToInd = { - "A word problem": 1, - "A number problem": 2, - }; - - let variantOfProblemsFound = { - 0: [], - 1: [], - }; - - let originalVariantInds; - let originalSecondValues; - - // let generatedVariantInfo; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 10; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 5 === 0) { - cy.reload(); - } - - // show values don't change for same variant - for (let ind2 = 0; ind2 < 2; ind2++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - ${ind2} - - - - - - - - - -

- - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.get(cesc("#\\/_text2")).should("have.text", `${ind2}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: ind, - // name: numberToLetters(ind, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - let variantInds = []; - let secondValues = []; - - for (let i = 1; i <= 3; i++) { - let problem = stateVariables["/problem" + i]; - let variantInd = titlesToInd[problem.stateValues.title]; - - expect(variantInd).not.eq(undefined); - - variantInds.push(variantInd); - // generatedVariantInfo.subvariants[0].indices.push(variantInd); - - let p = - stateVariables[ - problem.activeChildren[4].componentName - ]; - - if (variantInd === 1) { - expect(p.activeChildren[0].trim()).eq("Word:"); - let problemVariantInd = - [ - "angry", - "bad", - "churlish", - "drab", - "excoriated", - ].indexOf( - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value, - ) + 1; - expect(problemVariantInd).not.eq(0); - if ( - !variantOfProblemsFound[0].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[0].push( - problemVariantInd, - ); - } - expect(problemVariantInd).eq( - problem.stateValues.generatedVariantInfo.index, - ); - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - // }) - } else { - expect(p.activeChildren[0].trim()).eq("Number:"); - let num = - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value; - expect(Number.isInteger(num)).eq(true); - expect(num >= 1 && num <= 10).eq(true); - - let problemVariantInd = - problem.stateValues.generatedVariantInfo.index; - if ( - !variantOfProblemsFound[1].includes( - problemVariantInd, - ) - ) { - variantOfProblemsFound[1].push( - problemVariantInd, - ); - } - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // }) - } - - let secondValue = - stateVariables[p.activeChildren[1].componentName] - .stateValues.value; - if (secondValue === undefined) { - secondValue = - stateVariables[ - p.activeChildren[1].componentName - ].stateValues.value; - } - secondValues.push(secondValue); - } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // generatedVariantInfo.subvariants[0].subvariants - // ); - - if (ind2 === 0) { - originalVariantInds = variantInds; - originalSecondValues = secondValues; - } else { - expect(variantInds).eqls(originalVariantInds); - expect(secondValues).eqls(originalSecondValues); - } - }); - } - } - - // cy.log(`repeat last with previous generatedVariantInfo`) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // repeat - // - - // - // - // - // - // - // - // - //

- // - // - // - // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `repeat`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - - // generatedVariantInfo = { - // index: 10, - // name: numberToLetters(10, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // indices: [], - // meta: { createdBy: "/_select1" }, - // subvariants: [] - // }] - // } - - // let variantInds = []; - // let secondValues = []; - - // for (let i = 1; i <= 3; i++) { - // let problem = stateVariables['/problem' + i]; - // let variantInd = titlesToInd[problem.stateValues.title]; - - // expect(variantInd).not.eq(undefined); - - // variantInds.push(variantInd); - // generatedVariantInfo.subvariants[0].indices.push(variantInd); - - // let p = problem.activeChildren[4]; - - // if (variantInd === 1) { - // expect(p.activeChildren[0].trim()).eq("Word:") - // let problemVariantInd = ["angry", "bad", "churlish", "drab", "excoriated"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - // expect(problemVariantInd).not.eq(0) - // if (!variantOfProblemsFound[0].includes(problemVariantInd)) { - // variantOfProblemsFound[0].push(problemVariantInd); - // } - // expect(problemVariantInd).eq(problem.stateValues.generatedVariantInfo.index) - - // let selectVariantInd = ["bad", "angry", "drab", "excoriated", "churlish"].indexOf(stateVariables[p.activeChildren[1].componentName].stateValues.value) + 1; - - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [selectVariantInd], - // meta: { - // createdBy: `/problem${i}/_select1`, - // }, - // subvariants: [] - // }] - // }) - // } else { - // expect(p.activeChildren[0].trim()).eq("Number:"); - // let num = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // expect(Number.isInteger(num)).eq(true); - // expect(num >= 1 && num <= 10).eq(true); - - // let problemVariantInd = problem.stateValues.generatedVariantInfo.index - // if (!variantOfProblemsFound[1].includes(problemVariantInd)) { - // variantOfProblemsFound[1].push(problemVariantInd); - // } - // generatedVariantInfo.subvariants[0].subvariants.push({ - // index: problemVariantInd, - // name: numberToLetters(problemVariantInd, true), - // meta: { - // createdBy: `/problem${i}`, - // }, - // subvariants: [{ - // indices: [num], - // meta: { - // createdBy: `/problem${i}/_selectfromsequence1`, - // }, - // }] - // }) - // } - - // let secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // if (secondValue === undefined) { - // secondValue = stateVariables[p.activeChildren[1].componentName].stateValues.value; - // } - // secondValues.push(secondValue); - // } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - // expect(stateVariables["/_document1"].stateValues.itemVariantInfo).eqls( - // generatedVariantInfo.subvariants[0].subvariants - // ); - - // expect(variantInds).eqls(originalVariantInds); - // expect(secondValues).eqls(originalSecondValues); - - // }) - - cy.log( - "make sure all problem variants were selected at least once", - ).then(() => { - expect(variantOfProblemsFound[0].sort()).eqls([1, 2, 3, 4, 5]); - // not for second problem since have 100 possible variants by default - // expect(variantOfProblemsFound[1].sort()).eqls([1, 2, 3, 4, 5, 6]); - }); - }); - - it("select and sample random numbers", () => { - // let generatedVariantInfo; - let originalNumbers; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 10; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 5 === 0) { - cy.reload(); - } - - // show values don't change for same variant - for (let ind2 = 0; ind2 < 2; ind2++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - ${ind2} - -

-

-

-

- `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.get(cesc("#\\/_text2")).should("have.text", `${ind2}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let valuesS1 = - stateVariables["/s1"].stateValues.selectedValues; - let valuesS3 = - stateVariables["/s3"].stateValues.selectedValues; - - let valuesS2 = - stateVariables["/s2"].stateValues.sampledValues; - let valuesS4 = - stateVariables["/s4"].stateValues.sampledValues; - - // generatedVariantInfo = { - // index: ind, - // name: numberToLetters(ind, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // values: [...valuesS1], - // meta: { createdBy: "/s1" } - // }, { - // values: [...valuesS3], - // meta: { createdBy: "/s3" } - // }] - // } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - - let allNumbers = [ - ...valuesS1, - ...valuesS2, - ...valuesS3, - ...valuesS4, - ]; - - if (ind2 === 0) { - expect(allNumbers).not.eqls(originalNumbers); - originalNumbers = allNumbers; - } else { - expect(allNumbers).eqls(originalNumbers); - } - }); - } - } - - // cy.log(`repeat last one with previous generatedVariantInfo`) - - // cy.window().then(async (win) => { - // win.postMessage({ - // doenetML: ` - // repeat - // - //

- //

- //

- //

- // `, - // requestedVariant: generatedVariantInfo, - // }, "*"); - // }) - // // to wait for page to load - // cy.get(cesc('#\\/_text1')).should('have.text', `repeat`) - - // cy.window().then(async (win) => { - // let stateVariables = await win.returnAllStateVariables1(); - - // let valuesS1 = stateVariables["/s1"].stateValues.selectedValues; - // let valuesS3 = stateVariables["/s3"].stateValues.selectedValues; - - // let valuesS2 = stateVariables["/s2"].stateValues.sampledValues; - // let valuesS4 = stateVariables["/s4"].stateValues.sampledValues; - - // generatedVariantInfo = { - // index: 10, - // name: numberToLetters(10, true), - // meta: { - // createdBy: "/_document1", - // }, - // subvariants: [{ - // values: [...valuesS1], - // meta: { createdBy: "/s1" } - // }, { - // values: [...valuesS3], - // meta: { createdBy: "/s3" } - // }] - // } - - // expect(stateVariables["/_document1"].stateValues.generatedVariantInfo).eqls( - // generatedVariantInfo - // ) - - // let allNumbers = [...valuesS1, ...valuesS2, ...valuesS3, ...valuesS4] - - // expect(allNumbers).eqls(originalNumbers); - - // }) - }); - - it("choiceinputs", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - -

- - - - - -

-

- - - - - -

-

- - - - - -

-

- - - - - -

-

$c1.selectedValue{assignNames="c1v"}

- `; - - // let generatedVariantInfo; - let originalChoiceOrders; - let originalChoiceTexts; - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 4; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let orderC1 = stateVariables["/c1"].stateValues.choiceOrder; - let orderC2 = stateVariables["/c2"].stateValues.choiceOrder; - - let orderC3 = stateVariables["/c3"].stateValues.choiceOrder; - let orderC4 = stateVariables["/c4"].stateValues.choiceOrder; - - let textC1 = stateVariables["/c1"].stateValues.choiceTexts; - let textC2 = stateVariables["/c2"].stateValues.choiceTexts; - - let textC3 = stateVariables["/c3"].stateValues.choiceTexts; - let textC4 = stateVariables["/c4"].stateValues.choiceTexts; - - let allOrders = [ - ...orderC1, - ...orderC2, - ...orderC3, - ...orderC4, - ]; - let allTexts = [...textC1, ...textC2, ...textC3, ...textC4]; - expect(allOrders).not.eqls(originalChoiceOrders); - originalChoiceOrders = allOrders; - expect(allTexts).not.eqls(originalChoiceTexts); - originalChoiceTexts = allTexts; - - // click a choice input so that data is saved to IndexedDB - cy.get(cesc2(`#/c1_choice1_input`)).click(); - cy.get(cesc2(`#/c1v`)).should("have.text", textC1[0]); - cy.get(cesc2(`#/c1_choice1_input`)).should("be.checked"); - - cy.wait(2000); // wait for 2 second debounce - cy.reload(); - - // don't need to give requested variant here, - // as will load variant from IndexedDB given the attempt number - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/c1"]; - }), - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let orderC1 = stateVariables["/c1"].stateValues.choiceOrder; - let orderC2 = stateVariables["/c2"].stateValues.choiceOrder; - - let orderC3 = stateVariables["/c3"].stateValues.choiceOrder; - let orderC4 = stateVariables["/c4"].stateValues.choiceOrder; - - let textC1 = stateVariables["/c1"].stateValues.choiceTexts; - let textC2 = stateVariables["/c2"].stateValues.choiceTexts; - - let textC3 = stateVariables["/c3"].stateValues.choiceTexts; - let textC4 = stateVariables["/c4"].stateValues.choiceTexts; - - let allOrders = [ - ...orderC1, - ...orderC2, - ...orderC3, - ...orderC4, - ]; - let allTexts = [...textC1, ...textC2, ...textC3, ...textC4]; - expect(allOrders).eqls(originalChoiceOrders); - expect(allTexts).eqls(originalChoiceTexts); - - // click a choice input so that data is saved to IndexedDB - cy.get(cesc2(`#/c1_choice1_input`)).should("be.checked"); - cy.get(cesc2(`#/c1_choice2_input`)).click(); - cy.get(cesc2(`#/c1v`)).should("have.text", textC1[1]); - cy.get(cesc2(`#/c1_choice1_input`)).should( - "not.be.checked", - ); - cy.get(cesc2(`#/c1_choice2_input`)).should("be.checked"); - }); - }); - } - }); - - it("excluded sequence items, reload", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 4; ind++) { - let doenetML = ` - ${ind} - - - -

Enter $m: $m

-

Enter $n: $n

- - `; - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - let indexChosen1, indexChosen2; - let m, n; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - indexChosen1 = - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices[0]; - indexChosen2 = - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices[0]; - m = stateVariables["/m"].stateValues.value; - n = stateVariables["/n"].stateValues.value; - - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `${m}{enter}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput2") + " textarea").type( - `${n}{enter}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - - cy.wait(2000); // wait for 2 second debounce - cy.reload(); - - // don't need to give requested variant here, - // as will load variant from IndexedDB given the attempt number - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/m"]; - }), - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices[0], - ).eq(indexChosen1); - expect( - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices[0], - ).eq(indexChosen2); - expect(stateVariables["/m"].stateValues.value).eq(m); - expect(stateVariables["/n"].stateValues.value).eq(n); - }); - - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - - cy.get(cesc("#\\/_mathinput1") + " textarea").type(`{end}X`, { - force: true, - }); - cy.get(cesc("#\\/_mathinput2") + " textarea").type(`{end}X`, { - force: true, - }); - cy.get(cesc("#\\/_mathinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput2_submit")).click(); - cy.get(cesc("#\\/_mathinput1_incorrect")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_incorrect")).should("be.visible"); - - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput2") + " textarea").type( - `{end}{backspace}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput2_submit")).click(); - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - }); - } - }); - - it("excluded combinations of sequence items, reload", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - cy.log("Test a bunch of variants"); - for (let ind = 1; ind <= 4; ind++) { - let doenetML = ` - ${ind} - - - - -

Enter $m: $m

-

Enter $x2: $x2

-

Enter $l1: $l1

- `; - - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - let indicesChosen1, indicesChosen2, indicesChosen3; - let m, n, x1, x2, l1, l2; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - indicesChosen1 = [ - ...stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices, - ]; - m = stateVariables["/m"].stateValues.value; - n = stateVariables["/n"].stateValues.value; - - indicesChosen2 = [ - ...stateVariables["/_selectfromsequence2"].stateValues - .selectedIndices, - ]; - x1 = stateVariables["/x1"].stateValues.value; - x2 = stateVariables["/x2"].stateValues.value; - - indicesChosen3 = [ - ...stateVariables["/_selectfromsequence3"].stateValues - .selectedIndices, - ]; - l1 = stateVariables["/l1"].stateValues.value; - l2 = stateVariables["/l2"].stateValues.value; - - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `${m}{enter}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput2") + " textarea").type( - `${me.fromAst(x2).toString()}{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/_textinput1_input")).type(`${l1}{enter}`); - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - - cy.wait(2000); // wait for 2 second debounce - cy.reload(); - - // don't need to give requested variant here, - // as will load variant from IndexedDB given the attempt number - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/m"]; - }), - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices, - ).eqls(indicesChosen1); - expect(stateVariables["/m"].stateValues.value).eq(m); - expect(stateVariables["/n"].stateValues.value).eq(n); - expect( - stateVariables["/_selectfromsequence2"].stateValues - .selectedIndices, - ).eqls(indicesChosen2); - expect( - me - .fromAst(stateVariables["/x1"].stateValues.value) - .equals(me.fromAst(x1)), - ).be.true; - expect( - me - .fromAst(stateVariables["/x2"].stateValues.value) - .equals(me.fromAst(x2)), - ).be.true; - expect( - stateVariables["/_selectfromsequence1"].stateValues - .selectedIndices, - ).eqls(indicesChosen1); - expect(stateVariables["/l1"].stateValues.value).eq(l1); - expect(stateVariables["/l2"].stateValues.value).eq(l2); - }); - - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - - cy.get(cesc("#\\/_mathinput1") + " textarea").type(`{end}X`, { - force: true, - }); - cy.get(cesc("#\\/_mathinput2") + " textarea").type(`{end}X`, { - force: true, - }); - cy.get(cesc("#\\/_textinput1_input")).type(`{end}X`); - cy.get(cesc("#\\/_mathinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput2_submit")).click(); - cy.get(cesc("#\\/_textinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput1_incorrect")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_incorrect")).should("be.visible"); - cy.get(cesc("#\\/_textinput1_incorrect")).should("be.visible"); - - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_mathinput2") + " textarea").type( - `{end}{backspace}`, - { - force: true, - }, - ); - cy.get(cesc("#\\/_textinput1_input")).type(`{end}{backspace}`); - cy.get(cesc("#\\/_mathinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput2_submit")).click(); - cy.get(cesc("#\\/_textinput1_submit")).click(); - cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); - cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - }); - } - }); - - it("replacements of composites are not included in generated variant info", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - a - b - c - -

Selected value: $ci

-

Enter . $n

-
- - $g{name="g2"} - - $g{name="g3" link="false"} - -

Enter . $m

- `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 1${doenetML}`, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - let choices = ["a", "b", "c"]; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let choiceOrder = stateVariables["/g/ci"].stateValues.choiceOrder; - let n = stateVariables["/g/n"].stateValues.value; - let m = stateVariables["/m"].stateValues.value; - - let mathinput1Name = - stateVariables[`/g/ans`].stateValues.inputChildren[0] - .componentName; - let mathinput2Name = - stateVariables[`/g2/ans`].stateValues.inputChildren[0] - .componentName; - let mathinput3Name = - stateVariables[`/g3/ans`].stateValues.inputChildren[0] - .componentName; - let mathinput4Name = - stateVariables[`/ans`].stateValues.inputChildren[0] - .componentName; - - let mathinput1Anchor = cesc2("#" + mathinput1Name) + " textarea"; - let answer1Correct = cesc2("#" + mathinput1Name + "_correct"); - let answer1Incorrect = cesc2("#" + mathinput1Name + "_incorrect"); - let answer1Submit = cesc2("#" + mathinput1Name + "_submit"); - - let mathinput2Anchor = cesc2("#" + mathinput2Name) + " textarea"; - let answer2Correct = cesc2("#" + mathinput2Name + "_correct"); - let answer2Incorrect = cesc2("#" + mathinput2Name + "_incorrect"); - let answer2Submit = cesc2("#" + mathinput2Name + "_submit"); - - let mathinput3Anchor = cesc2("#" + mathinput3Name) + " textarea"; - let answer3Correct = cesc2("#" + mathinput3Name + "_correct"); - let answer3Incorrect = cesc2("#" + mathinput3Name + "_incorrect"); - let answer3Submit = cesc2("#" + mathinput3Name + "_submit"); - - let mathinput4Anchor = cesc2("#" + mathinput4Name) + " textarea"; - let answer4Correct = cesc2("#" + mathinput4Name + "_correct"); - let answer4Incorrect = cesc2("#" + mathinput4Name + "_incorrect"); - let answer4Submit = cesc2("#" + mathinput4Name + "_submit"); - - cy.get(`label[for=${cesc2("/g/ci_choice1_input")}]`).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - cy.get(`label[for=${cesc2("/g/ci_choice2_input")}]`).should( - "have.text", - choices[choiceOrder[1] - 1], - ); - cy.get(`label[for=${cesc2("/g/ci_choice3_input")}]`).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - cy.get(`label[for=${cesc2("/g2/ci_choice1_input")}]`).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - cy.get(`label[for=${cesc2("/g2/ci_choice2_input")}]`).should( - "have.text", - choices[choiceOrder[1] - 1], - ); - cy.get(`label[for=${cesc2("/g2/ci_choice3_input")}]`).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - cy.get(`label[for=${cesc2("/g3/ci_choice1_input")}]`).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - cy.get(`label[for=${cesc2("/g3/ci_choice2_input")}]`).should( - "have.text", - choices[choiceOrder[1] - 1], - ); - cy.get(`label[for=${cesc2("/g3/ci_choice3_input")}]`).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - - cy.get(cesc2(`#/g/_p2`)).should("have.text", `Enter ${n}. `); - cy.get(cesc2(`#/g2/_p2`)).should("have.text", `Enter ${n}. `); - cy.get(cesc2(`#/g3/_p2`)).should("have.text", `Enter ${n}. `); - cy.get(cesc2(`#/_p1`)).should("have.text", `Enter ${m}. `); - - cy.get(cesc2(`#/g/ci_choice2_input`)).click(); - cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g3/ci_choice2_input`)).should("not.be.checked"); - - cy.get(cesc2(`#/g/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g2/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g3/_p1`)).should("have.text", `Selected value: `); - - cy.get(cesc2(`#/g3/ci_choice1_input`)).click(); - cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g3/ci_choice1_input`)).should("be.checked"); - - cy.get(cesc2(`#/g/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g2/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g3/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[0] - 1]}`, - ); - - cy.get(mathinput2Anchor).type(`${n}{enter}`, { force: true }); - cy.get(answer1Correct).should("be.visible"); - cy.get(answer2Correct).should("be.visible"); - cy.get(answer3Submit).should("be.visible"); - cy.get(answer4Submit).should("be.visible"); - - cy.get(mathinput3Anchor).type(`${n}{enter}`, { force: true }); - cy.get(answer3Correct).should("be.visible"); - - cy.get(mathinput4Anchor).type(`${m}{enter}`, { force: true }); - cy.get(answer4Correct).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/g2/n"].stateValues.value).eq(n); - expect(stateVariables["/g3/n"].stateValues.value).eq(n); - expect(stateVariables["/g2/ci"].stateValues.choiceOrder).eqls( - choiceOrder, - ); - expect(stateVariables["/g3/ci"].stateValues.choiceOrder).eqls( - choiceOrder, - ); - - expect(stateVariables["/g/ci"].stateValues.selectedValues).eqls( - [choices[choiceOrder[1] - 1]], - ); - expect( - stateVariables["/g2/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[1] - 1]]); - expect( - stateVariables["/g3/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - - expect( - stateVariables["/g/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/g2/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/g3/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/ans"].stateValues.submittedResponses, - ).eqls([m]); - }); - - cy.wait(2000); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - 1${doenetML}`, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - return stateVariables["/ans"]; - }), - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/g/n"].stateValues.value).eq(n); - expect(stateVariables["/g2/n"].stateValues.value).eq(n); - expect(stateVariables["/g3/n"].stateValues.value).eq(n); - expect(stateVariables["/m"].stateValues.value).eq(m); - - expect(stateVariables["/g/ci"].stateValues.choiceOrder).eqls( - choiceOrder, - ); - expect(stateVariables["/g2/ci"].stateValues.choiceOrder).eqls( - choiceOrder, - ); - expect(stateVariables["/g3/ci"].stateValues.choiceOrder).eqls( - choiceOrder, - ); - - expect(stateVariables["/g/ci"].stateValues.selectedValues).eqls( - [choices[choiceOrder[1] - 1]], - ); - expect( - stateVariables["/g2/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[1] - 1]]); - expect( - stateVariables["/g3/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - - expect( - stateVariables["/g/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/g2/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/g3/ans"].stateValues.submittedResponses, - ).eqls([n]); - expect( - stateVariables["/ans"].stateValues.submittedResponses, - ).eqls([m]); - }); - - cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); - cy.get(cesc2(`#/g3/ci_choice1_input`)).should("be.checked"); - - cy.get(cesc2(`#/g/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g2/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g3/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[0] - 1]}`, - ); - - cy.get(cesc2(`#/g/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g2/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[1] - 1]}`, - ); - cy.get(cesc2(`#/g3/_p1`)).should( - "have.text", - `Selected value: ${choices[choiceOrder[0] - 1]}`, - ); - - cy.get(answer1Correct).should("be.visible"); - cy.get(answer2Correct).should("be.visible"); - cy.get(answer3Correct).should("be.visible"); - cy.get(answer4Correct).should("be.visible"); - - cy.get(mathinput1Anchor).type( - `{end}{backspace}{backspace}${n + 1}`, - { - force: true, - }, - ); - cy.get(answer2Submit).click(); - cy.get(answer1Incorrect).should("be.visible"); - cy.get(answer2Incorrect).should("be.visible"); - - cy.get(mathinput2Anchor).type(`{end}{backspace}{backspace}${n}`, { - force: true, - }); - cy.get(answer1Submit).click(); - cy.get(answer1Correct).should("be.visible"); - cy.get(answer2Correct).should("be.visible"); + it("nested selects, reload", () => { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_allowLocalState").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); - cy.get(mathinput3Anchor).type( - `{end}{backspace}{backspace}${n + 1}`, - { - force: true, - }, - ); - cy.get(answer3Submit).click(); - cy.get(answer3Incorrect).should("be.visible"); - cy.get(mathinput3Anchor).type(`{end}{backspace}{backspace}${n}`, { - force: true, - }); - cy.get(answer3Submit).click(); - cy.get(answer3Correct).should("be.visible"); + let doenetML = ` + - cy.get(mathinput4Anchor).type( - `{end}{backspace}{backspace}${m + 1}`, - { - force: true, - }, - ); - cy.get(answer4Submit).click(); - cy.get(answer4Incorrect).should("be.visible"); - cy.get(mathinput4Anchor).type(`{end}{backspace}{backspace}${m}`, { - force: true, - }); - cy.get(answer4Submit).click(); - cy.get(answer4Correct).should("be.visible"); - }); - }); + + + + + + + +

+ + + + +

Enter item $item as text: $(p/item)

+ `; - it("document inherits variants from single problem", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); + let firstStringsToInd = { + "Favorite color:": 0, + "Selected number:": 1, + "Chosen letter:": 2, + "Variable:": 3, + }; - cy.log("get both options and then they repeat"); - for (let ind = 1; ind <= 3; ind++) { + cy.log("Test a bunch of variants"); + for (let ind = 1; ind <= 5; ind++) { if (ind > 1) { cy.get("#testRunner_toggleControls").click(); cy.get("#testRunner_newAttempt").click(); @@ -5556,27 +54,10 @@ describe("Specifying single variant document tests", function () { cy.reload(); } - let doenetML = ` - - - ${ind} - - - -

Enter $fruit: - $fruit -

-
- `; - cy.window().then(async (win) => { win.postMessage( { - doenetML, - requestedVariantIndex: ind, + doenetML: `${ind}${doenetML}`, }, "*", ); @@ -5584,58 +65,64 @@ describe("Specifying single variant document tests", function () { // to wait for page to load cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - let fruit = ["apple", "orange"][(ind - 1) % 2]; - cy.window().then(async (win) => { let stateVariables = await win.returnAllStateVariables1(); + let p = stateVariables["/p"]; - let textinputName = cesc2( - stateVariables["/_answer1"].stateValues.inputChildren[0] - .componentName, - ); - let textinputAnchor = "#" + textinputName + "_input"; - let textinputSubmitAnchor = "#" + textinputName + "_submit"; - let textinputCorrectAnchor = "#" + textinputName + "_correct"; - let textinputIncorrectAnchor = - "#" + textinputName + "_incorrect"; - - expect(stateVariables["/fruit"].stateValues.value).eq(fruit); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["apple", "orange"]); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq(fruit); + let variantInd = firstStringsToInd[p.activeChildren[0].trim()]; + expect(variantInd).not.eq(undefined); - cy.get(textinputAnchor).type(`${fruit}{enter}`); + let secondValue = + stateVariables[p.activeChildren[1].componentName] + .stateValues.value; - cy.get(textinputCorrectAnchor).should("be.visible"); + if (variantInd === 0) { + let i = [ + "red", + "orange", + "green", + "white", + "chartreuse", + ].indexOf(secondValue); + expect(i).not.eq(-1); + } else if (variantInd === 1) { + let num = secondValue; + expect(Number.isInteger(num)).eq(true); + if (num > 0) { + expect(num).gte(1000); + expect(num).lte(2000); + } else { + expect(num).gte(-1000); + expect(num).lte(-900); + } + } else if (variantInd === 2) { + let i = ["a", "b", "c", "d", "e", "f", "g"].indexOf( + secondValue, + ); + expect(i).not.eq(-1); + } else { + let i = ["u", "v", "w", "x", "z", "y"].indexOf(secondValue); + expect(i).not.eq(-1); + } - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([fruit]); - }); + cy.get(cesc("#\\/_textinput1_input")).type( + `${secondValue}{enter}`, + ); + cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); - cy.wait(2000); // wait for 1 second debounce + cy.wait(2000); // wait for 2 second debounce cy.reload(); + // don't need to give requested variant here, + // as will load variant from IndexedDB given the attempt number cy.window().then(async (win) => { win.postMessage( { - doenetML, - requestedVariantIndex: ind, + doenetML: `${ind}${doenetML}`, }, "*", ); }); - // to wait for page to load cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); @@ -5644,756 +131,370 @@ describe("Specifying single variant document tests", function () { cy.window().then(async (win) => { let stateVariables = await win.returnAllStateVariables1(); - return stateVariables["/_answer1"]; + return stateVariables["/_textinput1"]; }), ); - cy.get(textinputAnchor).should("have.value", `${fruit}`); - cy.get(textinputCorrectAnchor).should("be.visible"); - + cy.get(cesc("#\\/_textinput1_correct")).should("be.visible"); cy.window().then(async (win) => { let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([fruit]); - }); - - cy.get(textinputAnchor).type(`{end}s`); - cy.get(textinputSubmitAnchor).click(); - cy.get(textinputIncorrectAnchor).should("be.visible"); + let p = stateVariables["/p"]; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([fruit + "s"]); - }); + let variantInd2 = + firstStringsToInd[p.activeChildren[0].trim()]; + expect(variantInd2).eq(variantInd); - cy.get(textinputAnchor).type(`{end}{backspace}`); - cy.get(textinputSubmitAnchor).click(); - cy.get(textinputCorrectAnchor).should("be.visible"); + let secondValue2 = + stateVariables[p.activeChildren[1].componentName] + .stateValues.value; + expect(secondValue2).eq(secondValue); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([fruit]); + cy.get(cesc("#\\/_textinput1_input")).type(`{end}X`); + cy.get(cesc("#\\/_textinput1_submit")).click(); + cy.get(cesc("#\\/_textinput1_incorrect")).should( + "be.visible", + ); + cy.get(cesc("#\\/_textinput1_input")).type( + `{end}{backspace}`, + ); + cy.get(cesc("#\\/_textinput1_submit")).click(); + cy.get(cesc("#\\/_textinput1_correct")).should( + "be.visible", + ); }); }); } }); - it("adding non-random component does not change what is selected in a variant", () => { - // random piece 1 has more than 100 options so doesn't attempt to use non-random unique variants - let randomPiece1 = ` - - `; - - let randomPiece2 = ` - - `; - - let randomPiece3 = ` - - `; - - let randomPiece4 = ` -
- - - Random number - -
- `; - - let nonRandom1 = ` - Hello - `; - - let nonRandom2 = ` - -

one

-

two

-
- `; - - let nonRandom3 = ` - - - - - - - `; - - let nonRandom4 = ` -
- New section -

content

-
- `; - - let doenetML1 = `1` + randomPiece1 + randomPiece2; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: doenetML1, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - let n, a; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - n = stateVariables["/n"].stateValues.value; - a = stateVariables["/a"].stateValues.value; - }); - - let doenetML2 = - `2` + - randomPiece1 + - nonRandom1 + - randomPiece2 + - nonRandom2 + - nonRandom3 + - nonRandom4; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: doenetML2, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(n); - expect(stateVariables["/a"].stateValues.value).eq(a); - }); - - let doenetML3 = - `3` + - randomPiece1 + - randomPiece2 + - randomPiece3 + - randomPiece4; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: doenetML3, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `3`); - - let w1, w2, w3, m; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n2 = stateVariables["/n"].stateValues.value; - expect(n2).not.eq(n); - n = n2; - a = stateVariables["/a"].stateValues.value; - w1 = stateVariables["/w1"].stateValues.value; - w2 = stateVariables["/w2"].stateValues.value; - w3 = stateVariables["/w3"].stateValues.value; - m = stateVariables["/m"].stateValues.value; - }); - - let doenetML4 = - `4` + - randomPiece1 + - nonRandom1 + - randomPiece2 + - nonRandom2 + - randomPiece3 + - nonRandom3 + - randomPiece4 + - nonRandom4; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: doenetML4, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `4`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(n); - expect(stateVariables["/a"].stateValues.value).eq(a); - expect(stateVariables["/w1"].stateValues.value).eq(w1); - expect(stateVariables["/w2"].stateValues.value).eq(w2); - expect(stateVariables["/w3"].stateValues.value).eq(w3); - expect(stateVariables["/m"].stateValues.value).eq(m); - }); - }); - - it("variantsToInclude and variantsToExclude", () => { - cy.log("get two variants with no include/exclude"); - - let baseDoenetMLa = ` - - Selected number: - - `; - - let values = []; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "5 { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToInclude"); + it("choiceinputs, reload", () => { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_allowLocalState").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); - let baseDoenetMLb = ` - - Selected number: - + let doenetML = ` + +

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

+ + + + + +

+

$c1.selectedValue{assignNames="c1v"}

`; - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - }); + cy.log("Test a bunch of variants"); + for (let ind = 1; ind <= 4; ind++) { + if (ind > 1) { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_newAttempt").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); + cy.reload(); + } - cy.log("get same variants when add variantsToExclude"); + cy.window().then(async (win) => { + win.postMessage( + { + doenetML: `${ind}${doenetML}`, + requestedVariantIndex: ind, + }, + "*", + ); + }); + // to wait for page to load + cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - let baseDoenetMLc = ` - - Selected number: - - `; + cy.window().then(async (win) => { + let stateVariables = await win.returnAllStateVariables1(); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - }); + let textC1 = stateVariables["/c1"].stateValues.choiceTexts; + let textC2 = stateVariables["/c2"].stateValues.choiceTexts; - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "3 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); + // click a choice input so that data is saved to IndexedDB + cy.get(cesc2(`#/c1_choice1_input`)).click(); + cy.get(cesc2(`#/c1v`)).should("have.text", textC1[0]); + cy.get(cesc2(`#/c1_choice1_input`)).should("be.checked"); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - }); + cy.wait(2000); // wait for 2 second debounce + cy.reload(); - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); + // don't need to give requested variant here, + // as will load variant from IndexedDB given the attempt number + cy.window().then(async (win) => { + win.postMessage( + { + doenetML: `${ind}${doenetML}`, + }, + "*", + ); + }); + // to wait for page to load + cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - let baseDoenetMLd = ` - - Selected number: - - `; + // wait until core is loaded + cy.waitUntil(() => + cy.window().then(async (win) => { + let stateVariables = + await win.returnAllStateVariables1(); + return stateVariables["/c1"]; + }), + ); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { + let stateVariables = await win.returnAllStateVariables1(); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); + let orderC1 = stateVariables["/c1"].stateValues.choiceOrder; + let orderC2 = stateVariables["/c2"].stateValues.choiceOrder; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - }); + let orderC3 = stateVariables["/c3"].stateValues.choiceOrder; + let orderC4 = stateVariables["/c4"].stateValues.choiceOrder; - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); + let allOrders = [ + ...orderC1, + ...orderC2, + ...orderC3, + ...orderC4, + ]; + let allTexts = [...textC1, ...textC2, ...textC3, ...textC4]; + expect(allOrders).eqls(originalChoiceOrders); + expect(allTexts).eqls(originalChoiceTexts); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - }); + // click a choice input so that data is saved to IndexedDB + cy.get(cesc2(`#/c1_choice1_input`)).should("be.checked"); + cy.get(cesc2(`#/c1_choice2_input`)).click(); + cy.get(cesc2(`#/c1v`)).should("have.text", textC1[1]); + cy.get(cesc2(`#/c1_choice1_input`)).should( + "not.be.checked", + ); + cy.get(cesc2(`#/c1_choice2_input`)).should("be.checked"); + }); + }); + } }); - it("variantsToInclude and variantsToExclude in problem as only child ", () => { - cy.log("get two variants with no include/exclude"); + it("excluded sequence items, reload", () => { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_allowLocalState").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); - let baseDoenetMLa = ` - - Hello! - - Selected number: - - - `; + cy.log("Test a bunch of variants"); + for (let ind = 1; ind <= 4; ind++) { + let doenetML = ` + ${ind} + + + +

Enter $m: $m

+

Enter $n: $n

- let values = []; + `; + if (ind > 1) { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_newAttempt").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); + cy.reload(); + } - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 2, - }, - "*", - ); - }); + cy.window().then(async (win) => { + win.postMessage( + { + doenetML, + requestedVariantIndex: ind, + }, + "*", + ); + }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + // to wait for page to load + cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + let indexChosen1, indexChosen2; + let m, n; - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 5, - }, - "*", - ); - }); + cy.window().then(async (win) => { + let stateVariables = await win.returnAllStateVariables1(); + indexChosen1 = + stateVariables["/_selectfromsequence1"].stateValues + .selectedIndices[0]; + indexChosen2 = + stateVariables["/_selectfromsequence1"].stateValues + .selectedIndices[0]; + m = stateVariables["/m"].stateValues.value; + n = stateVariables["/n"].stateValues.value; + + cy.get(cesc("#\\/_mathinput1") + " textarea").type( + `${m}{enter}`, + { + force: true, + }, + ); + cy.get(cesc("#\\/_mathinput2") + " textarea").type( + `${n}{enter}`, + { + force: true, + }, + ); + cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); + cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + cy.wait(2000); // wait for 2 second debounce + cy.reload(); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + // don't need to give requested variant here, + // as will load variant from IndexedDB given the attempt number + cy.window().then(async (win) => { + win.postMessage( + { + doenetML, + }, + "*", + ); + }); + // to wait for page to load + cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - cy.log("get same variants when add variantsToInclude"); + // wait until core is loaded + cy.waitUntil(() => + cy.window().then(async (win) => { + let stateVariables = + await win.returnAllStateVariables1(); + return stateVariables["/m"]; + }), + ); - let baseDoenetMLb = ` - - Hello! - - Selected number: - - - `; + cy.window().then(async (win) => { + let stateVariables = await win.returnAllStateVariables1(); + expect( + stateVariables["/_selectfromsequence1"].stateValues + .selectedIndices[0], + ).eq(indexChosen1); + expect( + stateVariables["/_selectfromsequence1"].stateValues + .selectedIndices[0], + ).eq(indexChosen2); + expect(stateVariables["/m"].stateValues.value).eq(m); + expect(stateVariables["/n"].stateValues.value).eq(n); + }); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 1, - }, - "*", - ); - }); + cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); + cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + cy.get(cesc("#\\/_mathinput1") + " textarea").type(`{end}X`, { + force: true, + }); + cy.get(cesc("#\\/_mathinput2") + " textarea").type(`{end}X`, { + force: true, + }); + cy.get(cesc("#\\/_mathinput1_submit")).click(); + cy.get(cesc("#\\/_mathinput2_submit")).click(); + cy.get(cesc("#\\/_mathinput1_incorrect")).should("be.visible"); + cy.get(cesc("#\\/_mathinput2_incorrect")).should("be.visible"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.get(cesc("#\\/_mathinput1") + " textarea").type( + `{end}{backspace}`, + { + force: true, + }, + ); + cy.get(cesc("#\\/_mathinput2") + " textarea").type( + `{end}{backspace}`, + { + force: true, + }, + ); + cy.get(cesc("#\\/_mathinput1_submit")).click(); + cy.get(cesc("#\\/_mathinput2_submit")).click(); + cy.get(cesc("#\\/_mathinput1_correct")).should("be.visible"); + cy.get(cesc("#\\/_mathinput2_correct")).should("be.visible"); + }); + } + }); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 2, - }, - "*", - ); - }); + it("replacements of composites are not included in generated variant info, reload", () => { + cy.get("#testRunner_toggleControls").click(); + cy.get("#testRunner_allowLocalState").click(); + cy.wait(100); + cy.get("#testRunner_toggleControls").click(); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + let doenetML = ` + + + a + b + c + +

Selected value: $ci

+

Enter . $n

+
- cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + $g{name="g2"} - cy.log("get same variants when add variantsToExclude"); + $g{name="g3" link="false"} - let baseDoenetMLc = ` - - Hello! - - Selected number: - - +

Enter . $m

`; cy.window().then(async (win) => { win.postMessage( { - doenetML: baseDoenetMLc, + doenetML: ` + 1${doenetML}`, requestedVariantIndex: 1, }, "*", @@ -6401,762 +502,319 @@ describe("Specifying single variant document tests", function () { }); // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + cy.get(cesc("#\\/_text1")).should("have.text", `1`); + + let choices = ["a", "b", "c"]; cy.window().then(async (win) => { let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLc, - requestedVariantIndex: 3, - }, - "*", - ); - }); + let choiceOrder = stateVariables["/g/ci"].stateValues.choiceOrder; + let n = stateVariables["/g/n"].stateValues.value; + let m = stateVariables["/m"].stateValues.value; - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + let mathinput1Name = + stateVariables[`/g/ans`].stateValues.inputChildren[0] + .componentName; + let mathinput2Name = + stateVariables[`/g2/ans`].stateValues.inputChildren[0] + .componentName; + let mathinput3Name = + stateVariables[`/g3/ans`].stateValues.inputChildren[0] + .componentName; + let mathinput4Name = + stateVariables[`/ans`].stateValues.inputChildren[0] + .componentName; - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); + let mathinput1Anchor = cesc2("#" + mathinput1Name) + " textarea"; + let answer1Correct = cesc2("#" + mathinput1Name + "_correct"); + let answer1Incorrect = cesc2("#" + mathinput1Name + "_incorrect"); + let answer1Submit = cesc2("#" + mathinput1Name + "_submit"); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + let mathinput2Anchor = cesc2("#" + mathinput2Name) + " textarea"; + let answer2Correct = cesc2("#" + mathinput2Name + "_correct"); + let answer2Incorrect = cesc2("#" + mathinput2Name + "_incorrect"); + let answer2Submit = cesc2("#" + mathinput2Name + "_submit"); - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); + let mathinput3Anchor = cesc2("#" + mathinput3Name) + " textarea"; + let answer3Correct = cesc2("#" + mathinput3Name + "_correct"); + let answer3Incorrect = cesc2("#" + mathinput3Name + "_incorrect"); + let answer3Submit = cesc2("#" + mathinput3Name + "_submit"); - let baseDoenetMLd = ` - - Hello! - - Selected number: - - - `; + let mathinput4Anchor = cesc2("#" + mathinput4Name) + " textarea"; + let answer4Correct = cesc2("#" + mathinput4Name + "_correct"); + let answer4Incorrect = cesc2("#" + mathinput4Name + "_incorrect"); + let answer4Submit = cesc2("#" + mathinput4Name + "_submit"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 1, - }, - "*", + cy.get(`label[for=${cesc2("/g/ci_choice1_input")}]`).should( + "have.text", + choices[choiceOrder[0] - 1], + ); + cy.get(`label[for=${cesc2("/g/ci_choice2_input")}]`).should( + "have.text", + choices[choiceOrder[1] - 1], + ); + cy.get(`label[for=${cesc2("/g/ci_choice3_input")}]`).should( + "have.text", + choices[choiceOrder[2] - 1], + ); + cy.get(`label[for=${cesc2("/g2/ci_choice1_input")}]`).should( + "have.text", + choices[choiceOrder[0] - 1], + ); + cy.get(`label[for=${cesc2("/g2/ci_choice2_input")}]`).should( + "have.text", + choices[choiceOrder[1] - 1], + ); + cy.get(`label[for=${cesc2("/g2/ci_choice3_input")}]`).should( + "have.text", + choices[choiceOrder[2] - 1], + ); + cy.get(`label[for=${cesc2("/g3/ci_choice1_input")}]`).should( + "have.text", + choices[choiceOrder[0] - 1], + ); + cy.get(`label[for=${cesc2("/g3/ci_choice2_input")}]`).should( + "have.text", + choices[choiceOrder[1] - 1], + ); + cy.get(`label[for=${cesc2("/g3/ci_choice3_input")}]`).should( + "have.text", + choices[choiceOrder[2] - 1], ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); + cy.get(cesc2(`#/g/_p2`)).should("have.text", `Enter ${n}. `); + cy.get(cesc2(`#/g2/_p2`)).should("have.text", `Enter ${n}. `); + cy.get(cesc2(`#/g3/_p2`)).should("have.text", `Enter ${n}. `); + cy.get(cesc2(`#/_p1`)).should("have.text", `Enter ${m}. `); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.get(cesc2(`#/g/ci_choice2_input`)).click(); + cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g3/ci_choice2_input`)).should("not.be.checked"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 2, - }, - "*", + cy.get(cesc2(`#/g/_p1`)).should( + "have.text", + `Selected value: ${choices[choiceOrder[1] - 1]}`, ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("not.exist"); - cy.get(cesc("#\\/_text1")).should("have.text", `Hello!`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); + cy.get(cesc2(`#/g2/_p1`)).should( + "have.text", + `Selected value: ${choices[choiceOrder[1] - 1]}`, + ); + cy.get(cesc2(`#/g3/_p1`)).should("have.text", `Selected value: `); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - }); + cy.get(cesc2(`#/g3/ci_choice1_input`)).click(); + cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g3/ci_choice1_input`)).should("be.checked"); - it("variantsToInclude and variantsToExclude in problem, extra child", () => { - cy.log("get two variants with no include/exclude"); + cy.get(cesc2(`#/g/_p1`)).should( + "have.text", + `Selected value: ${choices[choiceOrder[1] - 1]}`, + ); + cy.get(cesc2(`#/g2/_p1`)).should( + "have.text", + `Selected value: ${choices[choiceOrder[1] - 1]}`, + ); + cy.get(cesc2(`#/g3/_p1`)).should( + "have.text", + `Selected value: ${choices[choiceOrder[0] - 1]}`, + ); - let baseDoenetMLa = ` - - - Selected number: - - - `; - let allDocVariants = [ - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "aa", - "ab", - "ac", - "ad", - "ae", - "af", - "ag", - "ah", - "ai", - "aj", - "ak", - "al", - "am", - "an", - "ao", - "ap", - "aq", - "ar", - "as", - "at", - "au", - "av", - "aw", - "ax", - "ay", - "az", - "ba", - "bb", - "bc", - "bd", - "be", - "bf", - "bg", - "bh", - "bi", - "bj", - "bk", - "bl", - "bm", - "bn", - "bo", - "bp", - "bq", - "br", - "bs", - "bt", - "bu", - "bv", - "bw", - "bx", - "by", - "bz", - "ca", - "cb", - "cc", - "cd", - "ce", - "cf", - "cg", - "ch", - "ci", - "cj", - "ck", - "cl", - "cm", - "cn", - "co", - "cp", - "cq", - "cr", - "cs", - "ct", - "cu", - "cv", - ]; + cy.get(mathinput2Anchor).type(`${n}{enter}`, { force: true }); + cy.get(answer1Correct).should("be.visible"); + cy.get(answer2Correct).should("be.visible"); + cy.get(answer3Submit).should("be.visible"); + cy.get(answer4Submit).should("be.visible"); - let values = []; + cy.get(mathinput3Anchor).type(`${n}{enter}`, { force: true }); + cy.get(answer3Correct).should("be.visible"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { + let stateVariables = await win.returnAllStateVariables1(); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + expect(stateVariables["/g2/n"].stateValues.value).eq(n); + expect(stateVariables["/g3/n"].stateValues.value).eq(n); + expect(stateVariables["/g2/ci"].stateValues.choiceOrder).eqls( + choiceOrder, + ); + expect(stateVariables["/g3/ci"].stateValues.choiceOrder).eqls( + choiceOrder, + ); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "5 { - let stateVariables = await win.returnAllStateVariables1(); - values.push(stateVariables["/n"].stateValues.value); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.wait(2000); // wait for 1 second debounce + cy.reload(); - cy.log("get same variants when add variantsToInclude"); + cy.window().then(async (win) => { + win.postMessage( + { + doenetML: ` + 1${doenetML}`, + requestedVariantIndex: 1, + }, + "*", + ); + }); - let baseDoenetMLb = ` - - - Selected number: - - - `; + // to wait for page to load + cy.get(cesc("#\\/_text1")).should("have.text", `1`); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 + cy.window().then(async (win) => { + let stateVariables = await win.returnAllStateVariables1(); + return stateVariables["/ans"]; + }), ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `1`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.window().then(async (win) => { + let stateVariables = await win.returnAllStateVariables1(); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + expect(stateVariables["/g/ci"].stateValues.selectedValues).eqls( + [choices[choiceOrder[1] - 1]], + ); + expect( + stateVariables["/g2/ci"].stateValues.selectedValues, + ).eqls([choices[choiceOrder[1] - 1]]); + expect( + stateVariables["/g3/ci"].stateValues.selectedValues, + ).eqls([choices[choiceOrder[0] - 1]]); - cy.log("get same variants when add variantsToExclude"); + expect( + stateVariables["/g/ans"].stateValues.submittedResponses, + ).eqls([n]); + expect( + stateVariables["/g2/ans"].stateValues.submittedResponses, + ).eqls([n]); + expect( + stateVariables["/g3/ans"].stateValues.submittedResponses, + ).eqls([n]); + expect( + stateVariables["/ans"].stateValues.submittedResponses, + ).eqls([m]); + }); - let baseDoenetMLc = ` - - - Selected number: - - - `; + cy.get(cesc2(`#/g/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g2/ci_choice2_input`)).should("be.checked"); + cy.get(cesc2(`#/g3/ci_choice1_input`)).should("be.checked"); - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.get(answer1Correct).should("be.visible"); + cy.get(answer2Correct).should("be.visible"); + cy.get(answer3Correct).should("be.visible"); + cy.get(answer4Correct).should("be.visible"); - cy.window().then(async (win) => { - win.postMessage( + cy.get(mathinput1Anchor).type( + `{end}{backspace}{backspace}${n + 1}`, { - doenetML: "3 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); - - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); + cy.get(answer2Submit).click(); + cy.get(answer1Incorrect).should("be.visible"); + cy.get(answer2Incorrect).should("be.visible"); - let baseDoenetMLd = ` - - - Selected number: - - - `; + cy.get(mathinput2Anchor).type(`{end}{backspace}{backspace}${n}`, { + force: true, + }); + cy.get(answer1Submit).click(); + cy.get(answer1Correct).should("be.visible"); + cy.get(answer2Correct).should("be.visible"); - cy.window().then(async (win) => { - win.postMessage( + cy.get(mathinput3Anchor).type( + `{end}{backspace}{backspace}${n + 1}`, { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[0]); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); + cy.get(answer3Submit).click(); + cy.get(answer3Incorrect).should("be.visible"); + cy.get(mathinput3Anchor).type(`{end}{backspace}{backspace}${n}`, { + force: true, + }); + cy.get(answer3Submit).click(); + cy.get(answer3Correct).should("be.visible"); - cy.window().then(async (win) => { - win.postMessage( + cy.get(mathinput4Anchor).type( + `{end}{backspace}{backspace}${m + 1}`, { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(values[1]); - - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); + cy.get(answer4Submit).click(); + cy.get(answer4Incorrect).should("be.visible"); + cy.get(mathinput4Anchor).type(`{end}{backspace}{backspace}${m}`, { + force: true, + }); + cy.get(answer4Submit).click(); + cy.get(answer4Correct).should("be.visible"); }); }); }); diff --git a/packages/test-cypress/cypress/e2e/variants/uniquevariants.cy.js b/packages/test-cypress/cypress/e2e/variants/uniquevariants.cy.js deleted file mode 100644 index b04217ddc..000000000 --- a/packages/test-cypress/cypress/e2e/variants/uniquevariants.cy.js +++ /dev/null @@ -1,5295 +0,0 @@ -import { cesc, cesc2 } from "@doenet/utils"; - -describe("Specifying unique variant tests", function () { - beforeEach(() => { - cy.clearIndexedDB(); - cy.visit("/"); - }); - - it("single select", () => { - let values = ["u", "v", "w", "x", "y", "z"]; - - cy.log("get all values in order and they repeat in next variants"); - for (let ind = 1; ind <= 18; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "have.text", - values[(ind - 1) % 6], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - values[(ind - 1) % 6], - ); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - }); - } - }); - - it("single selectfromsequence", () => { - cy.log("get all values in order and they repeat in next variants"); - for (let ind = 1; ind <= 15; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x")).should("have.text", ((ind - 1) % 5) + 1); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - ((ind - 1) % 5) + 1, - ); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e"]); - }); - } - }); - - it("selectfromsequence with excludes", () => { - cy.log("get all values in order and they repeat in next variants"); - for (let ind = 1; ind <= 12; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - let letters = ["c", "e", "i", "m"]; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x")).should("have.text", letters[(ind - 1) % 4]); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - letters[(ind - 1) % 4], - ); - }); - } - }); - - it("select and selectfromsequence combination", () => { - let valuesW = ["m", "n"]; - let valuesX = ["x", "y", "z"]; - let valuesY = [2, 3, 4]; - let valuesZ = [3, 7]; - - let values = []; - for (let w of valuesW) { - for (let x of valuesX) { - for (let y of valuesY) { - for (let z of valuesZ) { - values.push([w, x, y, z].join(",")); - } - } - } - } - let valuesFound = []; - - let numVariants = - valuesW.length * valuesX.length * valuesY.length * valuesZ.length; - - let wsFound = [], - xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get all values in variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newW = stateVariables["/w"].stateValues.value; - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newW, newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 3) { - wsFound.push(newW); - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(wsFound.slice(0, 2).sort()).eqls(valuesW); - expect(xsFound.sort()).eqls(valuesX); - expect(ysFound.sort()).eqls(valuesY); - expect(zsFound.slice(0, 2).sort()).eqls(valuesZ); - }); - - cy.log("values begin to repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 15; ind += 3) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newW = stateVariables["/w"].stateValues.value; - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newW, newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("select multiple", () => { - let valuesSingle = ["w", "x", "y", "z"]; - let valuesFound = []; - let values = []; - for (let x of valuesSingle) { - for (let y of valuesSingle) { - if (y == x) { - continue; - } - for (let z of valuesSingle) { - if (z === x || z === y) { - continue; - } - values.push([x, y, z].join(",")); - } - } - } - - let numVariants = values.length; - - let xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 4) { - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(xsFound.sort()).eqls(valuesSingle); - expect(ysFound.sort()).eqls(valuesSingle); - expect(zsFound.sort()).eqls(valuesSingle); - }); - - cy.log("values begin to repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("select multiple with replacement", () => { - let valuesSingle = ["x", "y", "z"]; - let valuesFound = []; - let values = []; - for (let x of valuesSingle) { - for (let y of valuesSingle) { - for (let z of valuesSingle) { - values.push([x, y, z].join(",")); - } - } - } - - let numVariants = values.length; - let xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 3) { - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(xsFound.sort()).eqls(valuesSingle); - expect(ysFound.sort()).eqls(valuesSingle); - expect(zsFound.sort()).eqls(valuesSingle); - }); - - cy.log("values begin to repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("select multiple from sequence", () => { - let valuesSingle = ["w", "x", "y", "z"]; - let valuesFound = []; - let values = []; - for (let x of valuesSingle) { - for (let y of valuesSingle) { - if (y == x) { - continue; - } - for (let z of valuesSingle) { - if (z === x || z === y) { - continue; - } - values.push([x, y, z].join(",")); - } - } - } - - let numVariants = values.length; - let xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 4) { - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(xsFound.sort()).eqls(valuesSingle); - expect(ysFound.sort()).eqls(valuesSingle); - expect(zsFound.sort()).eqls(valuesSingle); - }); - - cy.log("values begin to repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("select multiple from sequence with replacement", () => { - let valuesSingle = ["x", "y", "z"]; - let valuesFound = []; - let values = []; - for (let x of valuesSingle) { - for (let y of valuesSingle) { - for (let z of valuesSingle) { - values.push([x, y, z].join(",")); - } - } - } - - let numVariants = values.length; - let xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 3) { - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(xsFound.sort()).eqls(valuesSingle); - expect(ysFound.sort()).eqls(valuesSingle); - expect(zsFound.sort()).eqls(valuesSingle); - }); - - cy.log("values begin to repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("limit variants", () => { - let valuesSingle = ["u", "v", "w", "x", "y", "z"]; - let valuesFound = []; - let values = []; - for (let w of valuesSingle) { - for (let x of valuesSingle) { - for (let y of valuesSingle) { - for (let z of valuesSingle) { - values.push([w, x, y, z].join(",")); - } - } - } - } - - let numVariants = 10; - let wsFound = [], - xsFound = [], - ysFound = [], - zsFound = []; - - cy.log("get unique values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newW = stateVariables["/w"].stateValues.value; - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newW, newX, newY, newZ].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - - if (ind <= 6) { - wsFound.push(newW); - xsFound.push(newX); - ysFound.push(newY); - zsFound.push(newZ); - } - }); - } - - cy.log("all individual options selected in first variants"); - cy.window().then(async (win) => { - expect(wsFound.sort()).eqls(valuesSingle); - expect(xsFound.sort()).eqls(valuesSingle); - expect(ysFound.sort()).eqls(valuesSingle); - expect(zsFound.sort()).eqls(valuesSingle); - }); - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= 2 * numVariants + 3; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newW = stateVariables["/w"].stateValues.value; - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newZ = stateVariables["/z"].stateValues.value; - let newValue = [newW, newX, newY, newZ].join(","); - - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("selects of selectfromsequence", () => { - let valuesFound = []; - let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; - let numVariants = values.length; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x"].stateValues.value; - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); - - if (ind === 3) { - cy.log("all individual groups selected in first variants"); - cy.window().then(async (win) => { - expect(valuesFound.some((x) => x <= 2)).eq(true); - expect( - valuesFound.some((x) => x >= 101 && x <= 103), - ).eq(true); - expect( - valuesFound.some((x) => x >= 201 && x <= 204), - ).eq(true); - }); - } - - if (ind === 6) { - cy.log( - "all individual groups selected twice in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(2); - }); - } - - if (ind === 8) { - cy.log( - "most individual groups selected three times in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(3); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(3); - }); - } - }); - } - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x"].stateValues.value; - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("selects of selects", () => { - let valuesFound = []; - let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; - let numVariants = values.length; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - 1 2 - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x"].stateValues.value; - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); - - if (ind === 3) { - cy.log("all individual groups selected in first variants"); - cy.window().then(async (win) => { - expect(valuesFound.some((x) => x <= 2)).eq(true); - expect( - valuesFound.some((x) => x >= 101 && x <= 103), - ).eq(true); - expect( - valuesFound.some((x) => x >= 201 && x <= 204), - ).eq(true); - }); - } - - if (ind === 6) { - cy.log( - "all individual groups selected twice in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(2); - }); - } - - if (ind === 8) { - cy.log( - "most individual groups selected three times in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(3); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(3); - }); - } - }); - } - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - 1 2 - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x"].stateValues.value; - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("selects of paragraphs of selects/selectfromsequence", () => { - let valuesFound = []; - let values = [1, 2, 101, 102, 103, 201, 202, 203, 204]; - let numVariants = values.length; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - 1 2

- - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x/n"].stateValues.value; - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i"]); - - if (ind === 3) { - cy.log("all individual groups selected in first variants"); - cy.window().then(async (win) => { - expect(valuesFound.some((x) => x <= 2)).eq(true); - expect( - valuesFound.some((x) => x >= 101 && x <= 103), - ).eq(true); - expect( - valuesFound.some((x) => x >= 201 && x <= 204), - ).eq(true); - }); - } - - if (ind === 6) { - cy.log( - "all individual groups selected twice in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(2); - }); - } - - if (ind === 8) { - cy.log( - "most individual groups selected three times in first variants", - ); - cy.window().then(async (win) => { - expect( - valuesFound.reduce( - (a, c) => a + (c <= 2 ? 1 : 0), - 0, - ), - ).eq(2); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(3); - expect( - valuesFound.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(3); - }); - } - }); - } - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - 1 2

- - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newValue = stateVariables["/x/n"].stateValues.value; - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("selects of selects, select multiple", () => { - let valuesFound = []; - let valuesSingle = [1, 2, 101, 102, 103, 201, 202, 203, 204]; - let values = []; - for (let x of valuesSingle) { - for (let y of valuesSingle) { - if (Math.abs(y - x) > 5) { - values.push([x, y].join(",")); - } - } - } - let numVariants = values.length; - - cy.log("get unique values in first variants"); - for (let ind = 1; ind <= 20; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - 1 2 - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newValue = [newX, newY].join(","); - expect(values.includes(newValue)).eq(true); - expect(valuesFound.includes(newValue)).eq(false); - valuesFound.push(newValue); - }); - } - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 20; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - 1 2 - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let newX = stateVariables["/x"].stateValues.value; - let newY = stateVariables["/y"].stateValues.value; - let newValue = [newX, newY].join(","); - expect(newValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - - cy.log("selects all individual groups equally in first variants"); - let valuesFound1 = []; - let valuesFound2 = []; - for (let pass = 0; pass < 12; pass++) { - for (let ind = pass * 3 + 1; ind <= (pass + 1) * 3; ind++) { - // reload every 10 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 10 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - 1 2 - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - valuesFound1.push(stateVariables["/x"].stateValues.value); - valuesFound2.push(stateVariables["/y"].stateValues.value); - }); - } - cy.window().then(async (win) => { - expect( - valuesFound1.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), - ).eq(pass + 1); - expect( - valuesFound1.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(pass + 1); - expect( - valuesFound1.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(pass + 1); - expect( - valuesFound2.reduce((a, c) => a + (c <= 2 ? 1 : 0), 0), - ).eq(pass + 1); - expect( - valuesFound2.reduce( - (a, c) => a + (c >= 101 && c <= 103 ? 1 : 0), - 0, - ), - ).eq(pass + 1); - expect( - valuesFound2.reduce( - (a, c) => a + (c >= 201 && c <= 204 ? 1 : 0), - 0, - ), - ).eq(pass + 1); - }); - } - }); - - it("deeper nesting of selects/selectfromsequence", () => { - let doenetML = ` - - - - - - -

- - - - - - `; - - let valuesFound = []; - - let colorsA = [ - "red", - "orange", - "yellow", - "magenta", - "maroon", - "fuchsia", - "scarlet", - ]; - let colorsB = ["green", "chartreuse", "turquoise"]; - let colorsC = ["white", "black"]; - let allColors = [...colorsA, ...colorsB, ...colorsC]; - - let letters = [...Array(26)].map((_, i) => - String.fromCharCode("a".charCodeAt(0) + i), - ); - - let variables = ["u", "v", "w", "x", "y", "z"]; - - let categories = [ - "Favorite color:", - "Selected number:", - "Chosen letter:", - "Variable:", - ]; - - let numVariants = 24; - - let colorsFound = []; - let numbersFound = []; - let lettersFound = []; - let variablesFound = []; - let categoriesFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - // reload every 8 times to keep it from slowing down - // (presumably due to garbage collecting) - if (ind % 8 === 0) { - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let category = stateVariables["/p"].activeChildren[0].trim(); - expect(categories.includes(category)).eq(true); - - let component = - stateVariables[ - stateVariables["/p"].activeChildren.filter( - (x) => x.componentName, - )[0].componentName - ]; - let newValue = component.stateValues.value; - if (category === categories[0]) { - expect(allColors.includes(newValue)).eq(true); - colorsFound.push(newValue); - } else if (category === categories[1]) { - let validNum = - Number.isInteger(newValue) && - ((newValue >= 1000 && newValue <= 2000) || - (newValue >= -1000 && newValue <= -900)); - expect(validNum).eq(true); - numbersFound.push(newValue); - } else if (category === categories[2]) { - expect(letters.includes(newValue)).eq(true); - lettersFound.push(newValue); - } else { - expect(variables.includes(newValue)).eq(true); - variablesFound.push(newValue); - } - - let combinedValue = [category, newValue].join(","); - - expect(valuesFound.includes(combinedValue)).eq(false); - valuesFound.push(combinedValue); - - categoriesFound.push(category); - - if (ind === 4) { - cy.log("all individual groups selected in first variants"); - cy.window().then(async (win) => { - for (let ind = 0; ind < 4; ind++) { - expect( - categoriesFound.includes(categories[ind]), - ).eq(true); - } - }); - } - - if (ind === 8) { - cy.log( - "all individual groups selected twice in first variants", - ); - cy.window().then(async (win) => { - for (let ind = 0; ind < 4; ind++) { - expect( - categoriesFound - .slice(4, 8) - .includes(categories[ind]), - ).eq(true); - } - }); - } - }); - } - - cy.log( - "the 24 values are distributed 6 to each category and evenly distributed across subcategories", - ); - cy.window().then(async (win) => { - let colorsFoundSet = new Set(colorsFound); - expect(colorsFoundSet.size).eq(6); - expect( - colorsA.reduce( - (a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), - 0, - ), - ).eq(2); - expect( - colorsB.reduce( - (a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), - 0, - ), - ).eq(2); - expect( - colorsC.reduce( - (a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), - 0, - ), - ).eq(2); - - expect(numbersFound.reduce((a, c) => a + (c > 0 ? 1 : 0), 0)).eq(3); - expect(numbersFound.reduce((a, c) => a + (c < 0 ? 1 : 0), 0)).eq(3); - - expect(lettersFound.length).eq(6); - expect(variablesFound.length).eq(6); - - expect(variablesFound.sort()).eqls(variables); - }); - - cy.log("values repeat in next variants"); - cy.reload(); - for (let ind = numVariants + 1; ind <= numVariants + 25; ind += 5) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let category = stateVariables["/p"].activeChildren[0].trim(); - let component = - stateVariables[ - stateVariables["/p"].activeChildren.filter( - (x) => x.componentName, - )[0].componentName - ]; - let newValue = component.stateValues.value; - let combinedValue = [category, newValue].join(","); - expect(combinedValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("select problems of selects/selectfromsequence", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - - - -

Enter the color $(p/color): $(p/color)

- - - - - -

Enter the word $(p/word): $(p/word)

- - - - - `; - - let valuesFound = []; - - let colorsA = [ - "red", - "orange", - "yellow", - "magenta", - "maroon", - "fuchsia", - "scarlet", - ]; - let colorsB = ["green", "chartreuse", "turquoise"]; - let allColors = [...colorsA, ...colorsB]; - - let wordsA = ["run", "walk", "jump", "skip"]; - let wordsB = [ - "soft", - "scary", - "large", - "empty", - "residual", - "limitless", - ]; - let allWords = [...wordsA, ...wordsB]; - - let letters = [...Array(26)].map((_, i) => - String.fromCharCode("a".charCodeAt(0) + i), - ); - - let categories = ["Favorite color", "Selected word", "Chosen letter"]; - - let numVariants = 6; - - let categoriesFound = []; - let colorsFound = []; - let wordsFound = []; - let lettersFound = []; - - cy.log("get all values in first variants"); - for (let ind = 1; ind <= numVariants; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - let category, newValue; - - let textinputName; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - textinputName = - stateVariables[`/problem/ans`].stateValues.inputChildren[0] - .componentName; - category = stateVariables["/problem"].stateValues.title; - expect(categories.includes(category)).eq(true); - - let component = - stateVariables[ - stateVariables[ - stateVariables["/problem"].activeChildren.filter( - (x) => x.componentName, - )[1].componentName - ].activeChildren[1].componentName - ]; - newValue = component.stateValues.value; - if (category === categories[0]) { - expect(allColors.includes(newValue)).eq(true); - colorsFound.push(newValue); - } else if (category === categories[1]) { - expect(allWords.includes(newValue)).eq(true); - wordsFound.push(newValue); - } else if (category === categories[2]) { - expect(letters.includes(newValue)).eq(true); - lettersFound.push(newValue); - } - - let combinedValue = [category, newValue].join(","); - - expect(valuesFound.includes(combinedValue)).eq(false); - valuesFound.push(combinedValue); - - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - categoriesFound.push(category); - - if (ind === 3) { - cy.log("all individual groups selected in first variants"); - cy.window().then(async (win) => { - for (let ind = 0; ind < 3; ind++) { - expect( - categoriesFound.includes(categories[ind]), - ).eq(true); - } - }); - } - - if (ind === 6) { - cy.log( - "all individual groups selected twice in first variants", - ); - cy.window().then(async (win) => { - for (let ind = 0; ind < 3; ind++) { - expect( - categoriesFound - .slice(3) - .includes(categories[ind]), - ).eq(true); - } - }); - } - }); - - cy.window().then(async (win) => { - let textinputAnchor = cesc2("#" + textinputName) + "_input"; - let answerCorrect = cesc2("#" + textinputName + "_correct"); - let answerIncorrect = cesc2("#" + textinputName + "_incorrect"); - let answerSubmit = cesc2("#" + textinputName + "_submit"); - - cy.get(textinputAnchor).type(`${newValue}{enter}`); - - cy.get(answerCorrect).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/problem/ans"].stateValues - .creditAchieved, - ).eq(1); - expect( - stateVariables["/problem/ans"].stateValues - .submittedResponses, - ).eqls([newValue]); - expect(stateVariables[textinputName].stateValues.value).eq( - newValue, - ); - }); - - cy.wait(1500); // wait for 1 second debounce - - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/problem/ans"]; - }), - ); - - cy.get(answerCorrect).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/problem/ans"].stateValues - .creditAchieved, - ).eq(1); - expect( - stateVariables["/problem/ans"].stateValues - .submittedResponses, - ).eqls([newValue]); - expect(stateVariables[textinputName].stateValues.value).eq( - newValue, - ); - }); - - cy.get(textinputAnchor).type(`{end}X`); - cy.get(answerSubmit).click(); - cy.get(answerIncorrect).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/problem/ans"].stateValues - .creditAchieved, - ).eq(0); - expect( - stateVariables["/problem/ans"].stateValues - .submittedResponses, - ).eqls([newValue + "X"]); - expect(stateVariables[textinputName].stateValues.value).eq( - newValue + "X", - ); - }); - - cy.get(textinputAnchor).type(`{end}{backspace}`); - cy.get(answerSubmit).click(); - cy.get(answerCorrect).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/problem/ans"].stateValues - .creditAchieved, - ).eq(1); - expect( - stateVariables["/problem/ans"].stateValues - .submittedResponses, - ).eqls([newValue]); - expect(stateVariables[textinputName].stateValues.value).eq( - newValue, - ); - }); - }); - } - - cy.window().then(async (win) => { - let colorsFoundSet = new Set(colorsFound); - expect(colorsFoundSet.size).eq(2); - expect( - colorsA.reduce( - (a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), - 0, - ), - ).eq(1); - expect( - colorsB.reduce( - (a, c) => a + (colorsFoundSet.has(c) ? 1 : 0), - 0, - ), - ).eq(1); - - let wordsFoundSet = new Set(wordsFound); - expect(wordsFoundSet.size).eq(2); - expect( - wordsA.reduce((a, c) => a + (wordsFoundSet.has(c) ? 1 : 0), 0), - ).eq(1); - expect( - wordsB.reduce((a, c) => a + (wordsFoundSet.has(c) ? 1 : 0), 0), - ).eq(1); - }); - - cy.log("values repeat in next variants"); - for (let ind = numVariants + 1; ind <= numVariants + 6; ind += 2) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let category = stateVariables["/problem"].stateValues.title; - let component = - stateVariables[ - stateVariables[ - stateVariables["/problem"].activeChildren.filter( - (x) => x.componentName, - )[1].componentName - ].activeChildren[1].componentName - ]; - let newValue = component.stateValues.value; - let combinedValue = [category, newValue].join(","); - expect(combinedValue).eq(valuesFound[(ind - 1) % numVariants]); - }); - } - }); - - it("can get unique with map without variants", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - - - - - - -

N:

- `; - - cy.log("get all values in order and they repeat in next variants"); - for (let ind = 1; ind <= 4; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x")).should("have.text", ((ind - 1) % 3) + 1); - - cy.get(cesc("#\\/p1")).should("have.text", "letter: a"); - cy.get(cesc("#\\/p2")).should("not.exist"); - - cy.get(cesc("#\\/n") + " textarea").type( - "{end}{backspace}3{enter}", - { - force: true, - }, - ); - cy.get(cesc("#\\/p1")).should("have.text", "letter: a"); - cy.get(cesc("#\\/p2")).should("have.text", "letter: b"); - cy.get(cesc("#\\/p3")).should("have.text", "letter: c"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - ((ind - 1) % 3) + 1, - ); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[1].componentName - ].stateValues.value, - ).eq("a"); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[1].componentName - ].stateValues.value, - ).eq("b"); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[1].componentName - ].stateValues.value, - ).eq("c"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - }); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - return stateVariables["/x"]; - }), - ); - - cy.get(cesc("#\\/x")).should("have.text", ((ind - 1) % 3) + 1); - - cy.get(cesc("#\\/p1")).should("have.text", "letter: a"); - cy.get(cesc("#\\/p2")).should("have.text", "letter: b"); - cy.get(cesc("#\\/p3")).should("have.text", "letter: c"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - ((ind - 1) % 3) + 1, - ); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[1].componentName - ].stateValues.value, - ).eq("a"); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[1].componentName - ].stateValues.value, - ).eq("b"); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[1].componentName - ].stateValues.value, - ).eq("c"); - }); - - cy.get(cesc("#\\/n") + " textarea").type( - "{end}{backspace}4{enter}", - { - force: true, - }, - ); - cy.get(cesc("#\\/p1")).should("have.text", "letter: a"); - cy.get(cesc("#\\/p2")).should("have.text", "letter: b"); - cy.get(cesc("#\\/p3")).should("have.text", "letter: c"); - cy.get(cesc("#\\/p4")).should("have.text", "letter: d"); - } - }); - - it("single shuffled choiceinput", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - red - blue - green - -

Selected value:

- - `; - - let ordersFound = []; - let choices = ["red", "blue", "green"]; - - cy.log("get all orders in first 6 variants"); - for (let ind = 1; ind <= 6; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(ordersFound.includes(selectedOrder)).eq(false); - ordersFound.push(selectedOrder); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - for (let i = 0; i < 3; i++) { - cy.get(cesc(`#\\/ci_choice${i + 1}_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[i] - 1], - ); - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[i] - 1]]); - }); - } - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/ci"]; - }), - ); - - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[2] - 1]]); - }); - - cy.get(cesc(`#\\/ci_choice1_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - }); - }); - } - - cy.log("7th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 7; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(selectedOrder).eq(ordersFound[0]); - }); - }); - - it("single shuffled choiceinput, choices copied in", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - red - - blue - green - - - - - - -

Selected value:

- - `; - - let ordersFound = []; - let choices = ["red", "blue", "green"]; - - cy.log("get all orders in first 6 variants"); - for (let ind = 1; ind <= 6; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(ordersFound.includes(selectedOrder)).eq(false); - ordersFound.push(selectedOrder); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - for (let i = 0; i < 3; i++) { - cy.get(cesc(`#\\/ci_choice${i + 1}_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[i] - 1], - ); - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[i] - 1]]); - }); - } - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/ci"]; - }), - ); - - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[2] - 1]]); - }); - - cy.get(cesc(`#\\/ci_choice1_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - }); - }); - } - - cy.log("7th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 7; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(selectedOrder).eq(ordersFound[0]); - }); - }); - - it("single shuffled choiceinput sugared inside answer", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - red - blue - green - -

Submitted response:

- - `; - - let ordersFound = []; - let choices = ["red", "blue", "green"]; - - cy.log("get all orders in first 6 variants"); - for (let ind = 1; ind <= 6; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceInputName = - stateVariables["/ans"].stateValues.inputChildren[0] - .componentName; - let choiceOrder = - stateVariables[choiceInputName].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(ordersFound.includes(selectedOrder)).eq(false); - ordersFound.push(selectedOrder); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - for (let i = 0; i < 3; i++) { - cy.get( - "#" + cesc2(choiceInputName) + `_choice${i + 1}_input`, - ).click(); - cy.get("#" + cesc2(choiceInputName) + "_submit").click(); - cy.get(cesc("#\\/sr")).should( - "have.text", - choices[choiceOrder[i] - 1], - ); - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables[choiceInputName].stateValues - .selectedValues, - ).eqls([choices[choiceOrder[i] - 1]]); - }); - } - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/ans"]; - }), - ); - - cy.get(cesc("#\\/sr")).should( - "have.text", - choices[choiceOrder[2] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[choiceInputName].stateValues - .selectedValues, - ).eqls([choices[choiceOrder[2] - 1]]); - }); - - cy.get("#" + cesc2(choiceInputName) + `_choice1_input`).click(); - cy.get("#" + cesc2(choiceInputName) + "_submit").click(); - cy.get(cesc("#\\/sr")).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[choiceInputName].stateValues - .selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - }); - }); - } - - cy.log("7th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 7; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceInputName = - stateVariables["/ans"].stateValues.inputChildren[0] - .componentName; - let choiceOrder = - stateVariables[choiceInputName].stateValues.choiceOrder; - let selectedOrder = choiceOrder.join(","); - expect(selectedOrder).eq(ordersFound[0]); - }); - }); - - it("shuffled choiceinput with selectFromSequence in choices", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - - - -

Selected value:

- `; - - let selectionsFound = []; - - cy.log("get all options in first 8 variants"); - for (let ind = 1; ind <= 8; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let n = stateVariables["/n"].stateValues.value; - let l = stateVariables["/l"].stateValues.value; - let choices = [n.toString(), l]; - let selectedOption = [...choiceOrder, ...choices].join(","); - expect(selectionsFound.includes(selectedOption)).eq(false); - selectionsFound.push(selectedOption); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h"]); - - for (let i = 0; i < 2; i++) { - cy.get(cesc(`#\\/ci_choice${i + 1}_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[i] - 1], - ); - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[i] - 1]]); - }); - } - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/ci"]; - }), - ); - - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[1] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[1] - 1]]); - }); - - cy.get(cesc(`#\\/ci_choice1_input`)).click(); - cy.get(cesc("#\\/selectedValue")).should( - "have.text", - choices[choiceOrder[0] - 1], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/ci"].stateValues.selectedValues, - ).eqls([choices[choiceOrder[0] - 1]]); - }); - }); - } - - cy.log("9th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 9; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let choiceOrder = stateVariables["/ci"].stateValues.choiceOrder; - let n = stateVariables["/n"].stateValues.value; - let l = stateVariables["/l"].stateValues.value; - let choices = [n.toString(), l]; - let selectedOption = [...choiceOrder, ...choices].join(","); - expect(selectedOption).eq(selectionsFound[0]); - }); - }); - - it("shuffle", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - -

- red - blue - green -

-

- - `; - - let ordersFound = []; - let colors = ["red", "blue", "green"]; - - cy.log("get all orders in first 6 variants"); - for (let ind = 1; ind <= 6; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let componentOrder = - stateVariables["/sh"].stateValues.componentOrder; - expect([...componentOrder].sort()).eqls([1, 2, 3]); - - let selectedOrder = componentOrder.join(","); - expect(ordersFound.includes(selectedOrder)).eq(false); - ordersFound.push(selectedOrder); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - cy.get(cesc("#\\/pList")).should( - "have.text", - componentOrder.map((x) => colors[x - 1]).join(", "), - ); - - // check reloading for just one variant - if (ind === 4) { - cy.get(cesc("#\\/bi")).click(); - cy.get(cesc("#\\/b")).should("have.text", "true"); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/b")).should("have.text", "true"); - cy.get(cesc("#\\/bi")).click(); - cy.get(cesc("#\\/b")).should("have.text", "false"); - - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables["/sh"].stateValues.componentOrder, - ).eqls(componentOrder); - }); - } - }); - } - - cy.log("7th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 7; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let componentOrder = - stateVariables["/sh"].stateValues.componentOrder; - let selectedOrder = componentOrder.join(","); - expect(selectedOrder).eq(ordersFound[0]); - - cy.get(cesc("#\\/pList")).should( - "have.text", - componentOrder.map((x) => colors[x - 1]).join(", "), - ); - }); - }); - - it("shuffle, copy in components", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - red - - blue - green - -

- - -

-

- - `; - - let ordersFound = []; - let colors = ["red", "blue", "green"]; - - cy.log("get all orders in first 6 variants"); - for (let ind = 1; ind <= 6; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let componentOrder = - stateVariables["/sh"].stateValues.componentOrder; - expect([...componentOrder].sort()).eqls([1, 2, 3]); - - let selectedOrder = componentOrder.join(","); - expect(ordersFound.includes(selectedOrder)).eq(false); - ordersFound.push(selectedOrder); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - cy.get(cesc("#\\/pList")).should( - "have.text", - componentOrder.map((x) => colors[x - 1]).join(", "), - ); - - // check reloading for just one variant - if (ind === 4) { - cy.get(cesc("#\\/bi")).click(); - cy.get(cesc("#\\/b")).should("have.text", "true"); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/b")).should("have.text", "true"); - cy.get(cesc("#\\/bi")).click(); - cy.get(cesc("#\\/b")).should("have.text", "false"); - - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - expect( - stateVariables["/sh"].stateValues.componentOrder, - ).eqls(componentOrder); - }); - } - }); - } - - cy.log("7th variant repeats first order"); - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - - let ind = 7; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let componentOrder = - stateVariables["/sh"].stateValues.componentOrder; - let selectedOrder = componentOrder.join(","); - expect(selectedOrder).eq(ordersFound[0]); - - cy.get(cesc("#\\/pList")).should( - "have.text", - componentOrder.map((x) => colors[x - 1]).join(", "), - ); - }); - }); - - it("document and problems with unique variants", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - - -

Enter : - $m -

-
- - -

Enter : - $n -

-
- `; - - cy.log("get all 6 options and then they repeat"); - for (let ind = 1; ind <= 8; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - let m = ((ind - 1) % 2) + 1; - let n = ((ind - 1) % 3) + 3; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let mathinputName = cesc2( - stateVariables["/_answer1"].stateValues.inputChildren[0] - .componentName, - ); - let mathinputAnchor = "#" + mathinputName + " textarea"; - let mathinputEditiableFieldAnchor = - "#" + mathinputName + " .mq-editable-field"; - let mathinputSubmitAnchor = "#" + mathinputName + "_submit"; - let mathinputCorrectAnchor = "#" + mathinputName + "_correct"; - let mathinputIncorrectAnchor = - "#" + mathinputName + "_incorrect"; - - let mathinput2Name = cesc2( - stateVariables["/_answer2"].stateValues.inputChildren[0] - .componentName, - ); - let mathinput2Anchor = "#" + mathinput2Name + " textarea"; - let mathinput2EditiableFieldAnchor = - "#" + mathinput2Name + " .mq-editable-field"; - let mathinput2SubmitAnchor = "#" + mathinput2Name + "_submit"; - let mathinput2CorrectAnchor = "#" + mathinput2Name + "_correct"; - let mathinput2IncorrectAnchor = - "#" + mathinput2Name + "_incorrect"; - - expect(stateVariables["/m"].stateValues.value).eq(m); - expect(stateVariables["/n"].stateValues.value).eq(n); - - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - - cy.get(mathinputAnchor).type(`${m}{enter}`, { force: true }); - cy.get(mathinput2Anchor).type(`${n}{enter}`, { force: true }); - - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/_answer1"]; - }), - ); - - cy.get(mathinputEditiableFieldAnchor).should( - "contain.text", - `${m}`, - ); - cy.get(mathinput2EditiableFieldAnchor).should( - "contain.text", - `${n}`, - ); - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - - cy.get(mathinputAnchor).type(`{end}1`, { force: true }); - cy.get(mathinput2Anchor).type(`{end}1`, { force: true }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinput2SubmitAnchor).click(); - cy.get(mathinputIncorrectAnchor).should("be.visible"); - cy.get(mathinput2IncorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m * 10 + 1]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n * 10 + 1]); - }); - - cy.get(mathinputAnchor).type(`{end}{backspace}`, { - force: true, - }); - cy.get(mathinput2Anchor).type(`{end}{backspace}`, { - force: true, - }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinput2SubmitAnchor).click(); - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - }); - } - }); - - it("problems with unique variants, but not document", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - let doenetML = ` - - -

Enter : - $m -

-
- - -

Enter : - $n -

-
- `; - - cy.log("get randomly chosen options for each problem"); - for (let ind = 1; ind <= 3; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let mathinputName = cesc2( - stateVariables["/_answer1"].stateValues.inputChildren[0] - .componentName, - ); - let mathinputAnchor = "#" + mathinputName + " textarea"; - let mathinputEditiableFieldAnchor = - "#" + mathinputName + " .mq-editable-field"; - let mathinputSubmitAnchor = "#" + mathinputName + "_submit"; - let mathinputCorrectAnchor = "#" + mathinputName + "_correct"; - let mathinputIncorrectAnchor = - "#" + mathinputName + "_incorrect"; - - let mathinput2Name = cesc2( - stateVariables["/_answer2"].stateValues.inputChildren[0] - .componentName, - ); - let mathinput2Anchor = "#" + mathinput2Name + " textarea"; - let mathinput2EditiableFieldAnchor = - "#" + mathinput2Name + " .mq-editable-field"; - let mathinput2SubmitAnchor = "#" + mathinput2Name + "_submit"; - let mathinput2CorrectAnchor = "#" + mathinput2Name + "_correct"; - let mathinput2IncorrectAnchor = - "#" + mathinput2Name + "_incorrect"; - - let m = - stateVariables["/_problem1"].stateValues - .generatedVariantInfo.index; - let n = - stateVariables["/_problem2"].stateValues - .generatedVariantInfo.index + 2; - - expect(m).gte(1); - expect(m).lte(2); - expect(n).gte(3); - expect(n).lte(5); - - expect(stateVariables["/m"].stateValues.value).eq(m); - expect(stateVariables["/n"].stateValues.value).eq(n); - - cy.get(mathinputAnchor).type(`${m}{enter}`, { force: true }); - cy.get(mathinput2Anchor).type(`${n}{enter}`, { force: true }); - - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: `${ind}${doenetML}`, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/_answer1"]; - }), - ); - - cy.get(mathinputEditiableFieldAnchor).should( - "contain.text", - `${m}`, - ); - cy.get(mathinput2EditiableFieldAnchor).should( - "contain.text", - `${n}`, - ); - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - - cy.get(mathinputAnchor).type(`{end}1`, { force: true }); - cy.get(mathinput2Anchor).type(`{end}1`, { force: true }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinput2SubmitAnchor).click(); - cy.get(mathinputIncorrectAnchor).should("be.visible"); - cy.get(mathinput2IncorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m * 10 + 1]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n * 10 + 1]); - }); - - cy.get(mathinputAnchor).type(`{end}{backspace}`, { - force: true, - }); - cy.get(mathinput2Anchor).type(`{end}{backspace}`, { - force: true, - }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinput2SubmitAnchor).click(); - cy.get(mathinputCorrectAnchor).should("be.visible"); - cy.get(mathinput2CorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer2"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - expect( - stateVariables["/_answer2"].stateValues - .submittedResponses, - ).eqls([n]); - }); - }); - } - }); - - it("document inherits variants from single problem with unique variants", () => { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_allowLocalState").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - - cy.log("get all 3 options and then they repeat"); - for (let ind = 1; ind <= 4; ind++) { - if (ind > 1) { - cy.get("#testRunner_toggleControls").click(); - cy.get("#testRunner_newAttempt").click(); - cy.wait(100); - cy.get("#testRunner_toggleControls").click(); - cy.reload(); - } - - let doenetML = ` - - -

Enter : - $m -

- ${ind} -
- `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - let m = ((ind - 1) % 3) + 5; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let mathinputName = cesc2( - stateVariables["/_answer1"].stateValues.inputChildren[0] - .componentName, - ); - let mathinputAnchor = "#" + mathinputName + " textarea"; - let mathinputEditiableFieldAnchor = - "#" + mathinputName + " .mq-editable-field"; - let mathinputSubmitAnchor = "#" + mathinputName + "_submit"; - let mathinputCorrectAnchor = "#" + mathinputName + "_correct"; - let mathinputIncorrectAnchor = - "#" + mathinputName + "_incorrect"; - - expect(stateVariables["/m"].stateValues.value).eq(m); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["five", "six", "seven"]); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq(["five", "six", "seven"][(ind - 1) % 3]); - - cy.get(mathinputAnchor).type(`${m}{enter}`, { force: true }); - - cy.get(mathinputCorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - }); - - cy.wait(1500); // wait for 1 second debounce - cy.reload(); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML, - requestedVariantIndex: ind, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - // wait until core is loaded - cy.waitUntil(() => - cy.window().then(async (win) => { - let stateVariables = - await win.returnAllStateVariables1(); - return stateVariables["/_answer1"]; - }), - ); - - cy.get(mathinputEditiableFieldAnchor).should( - "contain.text", - `${m}`, - ); - cy.get(mathinputCorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - }); - - cy.get(mathinputAnchor).type(`{end}1`, { force: true }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinputIncorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(0); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m * 10 + 1]); - }); - - cy.get(mathinputAnchor).type(`{end}{backspace}`, { - force: true, - }); - cy.get(mathinputSubmitAnchor).click(); - cy.get(mathinputCorrectAnchor).should("be.visible"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_answer1"].stateValues.creditAchieved, - ).eq(1); - expect( - stateVariables["/_answer1"].stateValues - .submittedResponses, - ).eqls([m]); - }); - }); - } - }); - - it("no variant control, 1 unique variant", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - hello! - `, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `a`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a"]); - }); - }); - - it("no variant control, single select", () => { - let values = ["u", "v", "w"]; - - cy.log("get all values in order and they repeat in next variants"); - for (let ind = 1; ind <= 4; ind++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "have.text", - values[(ind - 1) % 3], - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - values[(ind - 1) % 3], - ); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - }); - } - }); - - it("no variant control, select and selectFromSequence", () => { - let values = ["u", "v", "w"]; - - cy.log("get first values in order"); - for (let ind = 1; ind <= 3; ind++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "have.text", - values[ind - 1], - ); - cy.get(cesc("#\\/n")).should("have.text", ind.toString()); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/x"].stateValues.value).eq( - values[ind - 1], - ); - expect(stateVariables["/n"].stateValues.value).eq(ind); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants.length, - ).eq(30); - }); - } - }); - - it("no variant control, 100 is still unique variants", () => { - cy.log("get first values in order"); - for (let ind = 1; ind <= 5; ind++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.get(cesc("#\\/n")).should("have.text", ind.toString()); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(ind); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants.length, - ).eq(100); - }); - } - }); - - it("no variant control, 101 is not unique variants", () => { - let foundOneNotInOrder = false; - - cy.log("don't get first values in order"); - for (let ind = 1; ind <= 3; ind++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - if (stateVariables["/n"].stateValues.value !== ind) { - foundOneNotInOrder = true; - } - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants.length, - ).eq(100); - }); - } - - cy.window().then(async (win) => { - expect(foundOneNotInOrder).eq(true); - }); - }); - - it("no variant control, problem with 3 selects", () => { - // Catch bug in enumerateCombinations - // where was indirectly overwriting numVariantsByDescendant - let values = [135, 246, 145, 236, 136, 245, 146, 235]; - - cy.log("get each value exactly one"); - let valuesFound = []; - for (let ind = 1; ind <= 8; ind++) { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - ${ind} - - - - - - `, - requestedVariantIndex: ind, - }, - "*", - ); - }); - // to wait for page to load - cy.get(cesc("#\\/_text1")).should("have.text", `${ind}`); - - 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; - - let val = a * 100 + b * 10 + c; - valuesFound.push(val); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants.length, - ).eq(8); - - cy.get(cesc("#\\/a")).should("have.text", a.toString()); - cy.get(cesc("#\\/b")).should("have.text", b.toString()); - cy.get(cesc("#\\/c")).should("have.text", c.toString()); - }); - } - cy.window().then((win) => { - expect([...valuesFound].sort((a, b) => a - b)).eqls( - [...values].sort((a, b) => a - b), - ); - }); - }); - - it("variantsToInclude and variantsToExclude", () => { - cy.log("get two variants with no include/exclude"); - - let baseDoenetMLa = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "5 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToInclude"); - - let baseDoenetMLb = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToExclude"); - - let baseDoenetMLc = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "3 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); - - let baseDoenetMLd = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - }); - - it("variantsToInclude and variantsToExclude in problem as only child", () => { - cy.log("get two variants with no include/exclude"); - - let baseDoenetMLa = ` - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 5, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToInclude"); - - let baseDoenetMLb = ` - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToExclude"); - - let baseDoenetMLc = ` - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLc, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLc, - requestedVariantIndex: 3, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); - - let baseDoenetMLd = ` - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - }); - - it("variantsToInclude and variantsToExclude in problem, extra child", () => { - cy.log("get two variants with no include/exclude"); - - let baseDoenetMLa = ` - Hello! - - - Selected number: - - - `; - - let allDocVariants = [ - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "aa", - "ab", - "ac", - "ad", - "ae", - "af", - "ag", - "ah", - "ai", - "aj", - "ak", - "al", - "am", - "an", - "ao", - "ap", - "aq", - "ar", - "as", - "at", - "au", - "av", - "aw", - "ax", - "ay", - "az", - "ba", - "bb", - "bc", - "bd", - "be", - "bf", - "bg", - "bh", - "bi", - "bj", - "bk", - "bl", - "bm", - "bn", - "bo", - "bp", - "bq", - "br", - "bs", - "bt", - "bu", - "bv", - "bw", - "bx", - "by", - "bz", - "ca", - "cb", - "cc", - "cd", - "ce", - "cf", - "cg", - "ch", - "ci", - "cj", - "ck", - "cl", - "cm", - "cn", - "co", - "cp", - "cq", - "cr", - "cs", - "ct", - "cu", - "cv", - ]; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLa, - requestedVariantIndex: 5, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(5); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToInclude"); - - let baseDoenetMLb = ` - Hello! - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLb, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log("get same variants when add variantsToExclude"); - - let baseDoenetMLc = ` - Hello! - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLc, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLc, - requestedVariantIndex: 3, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("3"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("c"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c", "d", "e", "f"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(3); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "c", "e", "f", "g", "i"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.log( - "get same variants when add variantsToInclude and variantsToExclude", - ); - - let baseDoenetMLd = ` - Hello! - - - Selected number: - - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 1, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `2`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("1"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("a"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("second"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: baseDoenetMLd, - requestedVariantIndex: 2, - }, - "*", - ); - }); - - // to wait for page to load - cy.get(cesc("#\\/n")).should("have.text", `5`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(5); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("2"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("b"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["a", "b", "c"]); - expect( - stateVariables["/_document1"].sharedParameters.allVariantNames, - ).eqls(allDocVariants); - expect( - stateVariables["/_problem1"].sharedParameters.variantSeed, - ).eq("5"); - expect( - stateVariables["/_problem1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_problem1"].sharedParameters.variantName, - ).eq("e"); - expect( - stateVariables["/_problem1"].sharedParameters - .allPossibleVariants, - ).eqls(["second", "e", "g"]); - expect( - stateVariables["/_problem1"].sharedParameters.allVariantNames, - ).eqls(["first", "second", "c", "d", "e", "f", "g", "h", "i", "j"]); - }); - }); - - it("unique variants determined by numVariants specified, even with variantsToInclude and variantsToExclude", () => { - cy.log("unique variants when numVariants is 1000"); - - let baseDoenetMLa = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(20); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("20"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("t"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["t", "cv"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).eq(100); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("100"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("cv"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["t", "cv"]); - }); - - cy.log("non-unique variants when numVariants is 100"); - - let baseDoenetMLb = ` - - Selected number: - - `; - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "1 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).not.eq(20); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("20"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(1); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("t"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["t", "cv"]); - }); - - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: "2 { - let stateVariables = await win.returnAllStateVariables1(); - expect(stateVariables["/n"].stateValues.value).not.eq(100); - expect( - stateVariables["/_document1"].sharedParameters.variantSeed, - ).eq("100"); - expect( - stateVariables["/_document1"].sharedParameters.variantIndex, - ).eq(2); - expect( - stateVariables["/_document1"].sharedParameters.variantName, - ).eq("cv"); - expect( - stateVariables["/_document1"].sharedParameters - .allPossibleVariants, - ).eqls(["t", "cv"]); - }); - }); -});