Skip to content

Instantly share code, notes, and snippets.

@amb26
Created March 11, 2021 17:27
Show Gist options
  • Select an option

  • Save amb26/02b8d01687da0c547eb2d362d6cbb242 to your computer and use it in GitHub Desktop.

Select an option

Save amb26/02b8d01687da0c547eb2d362d6cbb242 to your computer and use it in GitHub Desktop.
Boolean lensed components
// Linked from https://github.com/fluid-project/infusion/pull/1038/files#diff-6972ab970b7ccb5a497ebc0fc51a19df59946de2ba24f58b1577c4ae40546f8cR1005-R1036
fluid.defaults("fluid.tests.fluid6390booleanRoot", {
gradeNames: "fluid.modelComponent",
model: {
shouldComponentExist: 1
},
dynamicComponents: {
conditionalComponent: {
source: "{that}.model.shouldComponentExist",
type: "fluid.component"
}
}
});
jqUnit.test("FLUID-6390: Lensed components from a boolean", function () {
var that = fluid.tests.fluid6390booleanRoot();
jqUnit.assertTrue("Conditional component should have been constructed", fluid.isComponent(that.conditionalComponent));
that.conditionalComponent.destroy();
jqUnit.assertEquals("Destruction of component should have unset model value", false, that.model.shouldComponentExist);
jqUnit.assertUndefined("Conditional component should not have been reconstructed", that.conditionalComponent);
that.applier.change("shouldComponentExist", true);
jqUnit.assertTrue("Conditional component should have been reconstructed", fluid.isComponent(that.conditionalComponent));
jqUnit.assertEquals("Model flag should not have been unset", true, that.model.shouldComponentExist);
that.applier.change("shouldComponentExist", false);
jqUnit.assertUndefined("Conditional component should have been destroyed", that.conditionalComponent);
jqUnit.assertEquals("Model flag should not have been reset", false, that.model.shouldComponentExist);
var thatWithout = fluid.tests.fluid6390booleanRoot({
model: {
shouldComponentExist: null
}
});
jqUnit.assertUndefined("Conditional component should not have been constructed on startup", thatWithout.conditionalComponent);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment