Skip to content

Commit

Permalink
Update attribute warning even if hidden (#25)
Browse files Browse the repository at this point in the history
Fixed by correctly updating composites in response to unmatched children inside attributes
  • Loading branch information
dqnykamp committed Sep 3, 2023
1 parent 82e1b79 commit ca3c8ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
38 changes: 19 additions & 19 deletions packages/doenetml/src/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2106,32 +2106,32 @@ export default class Core {
parent.childrenMatchedWithPlaceholders = false;
parent.matchedCompositeChildrenWithPlaceholders = true;

let unmatchedChildrenTypes = [];
for (let child of childGroupResults.unmatchedChildren) {
if (typeof child === "string") {
unmatchedChildrenTypes.push("string");
} else {
unmatchedChildrenTypes.push(
"<" + child.componentType + ">",
);
if (
this.componentInfoObjects.isInheritedComponentType({
inheritedComponentType: child.componentType,
baseComponentType: "_composite",
})
) {
parent.matchedCompositeChildrenWithPlaceholders = false;
}
}
}

if (parent.doenetAttributes.isAttributeChildFor) {
let attributeForComponentType =
parent.ancestors[0].componentClass.componentType;
this.unmatchedChildren[parent.componentName] = {
message: `Invalid format for attribute ${parent.doenetAttributes.isAttributeChildFor} of <${attributeForComponentType}>.`,
};
} else {
let unmatchedChildrenTypes = [];
for (let child of childGroupResults.unmatchedChildren) {
if (typeof child === "string") {
unmatchedChildrenTypes.push("string");
} else {
unmatchedChildrenTypes.push(
"<" + child.componentType + ">",
);
if (
this.componentInfoObjects.isInheritedComponentType({
inheritedComponentType: child.componentType,
baseComponentType: "_composite",
})
) {
parent.matchedCompositeChildrenWithPlaceholders = false;
}
}
}

this.unmatchedChildren[parent.componentName] = {
message: `Invalid children for <${
parent.componentType
Expand Down
26 changes: 26 additions & 0 deletions packages/test-cypress/cypress/e2e/errorsAndWarnings/warnings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,30 @@ describe("Warning Tests", function () {
expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(50);
});
});

it("No erroneous attribute warning in hidden component", () => {
cy.window().then(async (win) => {
win.postMessage(
{
doenetML: `
<boolean name="hide">true</boolean>
<section hide="$hide">
<p hide='$hide'>double hide</p>
</section>
`,
},
"*",
);
});

cy.get(cesc2("#/hide")).should("have.text", "true");

cy.window().then(async (win) => {
let errorWarnings = await win.returnErrorWarnings1();

expect(errorWarnings.errors.length).eq(0);
expect(errorWarnings.warnings.length).eq(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe("SelectRandomNumbers Tag Tests", function () {
let varX = me.math.variance(samples, "uncorrected");

expect(meanX).closeTo(100, 2);
expect(varX).closeTo(100, 30);
expect(varX).closeTo(100, 40);

let firstSelect =
stateVariables[
Expand Down Expand Up @@ -1241,7 +1241,7 @@ describe("SelectRandomNumbers Tag Tests", function () {
let meanX = me.math.mean(samples);
let varX = me.math.variance(samples, "uncorrected");

expect(meanX).closeTo(1, 0.4);
expect(meanX).closeTo(1, 0.5);
expect(varX).closeTo((9 ** 2 - 1) / 12, 1);

let firstSelect =
Expand Down

0 comments on commit ca3c8ab

Please sign in to comment.