Skip to content

Commit

Permalink
tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp committed Oct 11, 2024
1 parent 2a96d86 commit acd7cbf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
1 change: 0 additions & 1 deletion packages/doenetml-worker/src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export default class Core {
};

this.finishCoreConstruction().catch((e) => {
// throw e;
this.rejectInitialized(e);
});
}
Expand Down
119 changes: 60 additions & 59 deletions packages/doenetml-worker/src/test/tagSpecific/answer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,65 +1428,6 @@ describe("Answer tag tests", async () => {
expect(stateVariables["/answer1"].stateValues.creditAchieved).eq(1);
});

async function check_award_based_on_submitted_response(
core: any,
eventually_correct = true,
) {
let errorWarnings = core.errorWarnings;

expect(errorWarnings.errors.length).eq(0);
expect(errorWarnings.warnings.length).eq(1);

expect(errorWarnings.warnings[0].message).contain(
"An award for this answer is based on the answer's own submitted response",
);
expect(errorWarnings.warnings[0].level).eq(1);
expect(errorWarnings.warnings[0].doenetMLrange.lineBegin).eq(2);
expect(errorWarnings.warnings[0].doenetMLrange.charBegin).eq(5);
expect(errorWarnings.warnings[0].doenetMLrange.lineEnd).eq(5);
expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(13);

let stateVariables = await returnAllStateVariables(core);
let mathInputName =
stateVariables["/ans"].stateValues.inputChildren[0].componentName;

// have to submit the correct answer twice before it is marked correct
await updateMathInputValue({
latex: "5",
componentName: mathInputName,
core,
});
await core.requestAction({
componentName: "/ans",
actionName: "submitAnswer",
args: {},
event: null,
});
stateVariables = await returnAllStateVariables(core);

// answer is not correct because the submitted response was initially blank
expect(stateVariables["/ans"].stateValues.creditAchieved).eq(0);
// justSubmitted becomes false at the criteria (based on submitted response)
// change when the answer is submitted
expect(stateVariables["/ans"].stateValues.justSubmitted).eq(false);

await core.requestAction({
componentName: "/ans",
actionName: "submitAnswer",
args: {},
event: null,
});
stateVariables = await returnAllStateVariables(core);

// if `eventually correct` is set to `true`, then
// the second time, the answer is marked correct and justSubmitted stays true
// because the submitted response starts off correct and doesn't change
expect(stateVariables["/ans"].stateValues.creditAchieved).eq(
eventually_correct ? 1 : 0,
);
expect(stateVariables["/ans"].stateValues.justSubmitted).eq(true);
}

it("warning for award depending on submitted response", async () => {
const doenetMLs = [
`
Expand All @@ -1511,6 +1452,66 @@ describe("Answer tag tests", async () => {
</answer>`,
];

async function check_award_based_on_submitted_response(
core: any,
eventually_correct = true,
) {
let errorWarnings = core.errorWarnings;

expect(errorWarnings.errors.length).eq(0);
expect(errorWarnings.warnings.length).eq(1);

expect(errorWarnings.warnings[0].message).contain(
"An award for this answer is based on the answer's own submitted response",
);
expect(errorWarnings.warnings[0].level).eq(1);
expect(errorWarnings.warnings[0].doenetMLrange.lineBegin).eq(2);
expect(errorWarnings.warnings[0].doenetMLrange.charBegin).eq(5);
expect(errorWarnings.warnings[0].doenetMLrange.lineEnd).eq(5);
expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(13);

let stateVariables = await returnAllStateVariables(core);
let mathInputName =
stateVariables["/ans"].stateValues.inputChildren[0]
.componentName;

// have to submit the correct answer twice before it is marked correct
await updateMathInputValue({
latex: "5",
componentName: mathInputName,
core,
});
await core.requestAction({
componentName: "/ans",
actionName: "submitAnswer",
args: {},
event: null,
});
stateVariables = await returnAllStateVariables(core);

// answer is not correct because the submitted response was initially blank
expect(stateVariables["/ans"].stateValues.creditAchieved).eq(0);
// justSubmitted becomes false at the criteria (based on submitted response)
// change when the answer is submitted
expect(stateVariables["/ans"].stateValues.justSubmitted).eq(false);

await core.requestAction({
componentName: "/ans",
actionName: "submitAnswer",
args: {},
event: null,
});
stateVariables = await returnAllStateVariables(core);

// if `eventually correct` is set to `true`, then
// the second time, the answer is marked correct and justSubmitted stays true
// because the submitted response starts off correct and doesn't change
expect(stateVariables["/ans"].stateValues.creditAchieved).eq(
eventually_correct ? 1 : 0,
);
expect(stateVariables["/ans"].stateValues.justSubmitted).eq(true);
}

for (let doenetML of doenetMLs) {
let core = await createTestCore({
doenetML,
Expand Down

0 comments on commit acd7cbf

Please sign in to comment.