Skip to content

Commit

Permalink
FLUID-5059: Added more unit tests to ensure the sourceApplier listene…
Browse files Browse the repository at this point in the history
…rs added by the model relay are cleaned up at the destroy of the model relay itself.
  • Loading branch information
cindyli committed Jul 16, 2013
1 parent 479183e commit 64be46e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/webapp/components/uiOptions/js/ModelRelay.js
Expand Up @@ -44,16 +44,16 @@ var fluid_1_5 = fluid_1_5 || {};
},
removeListeners: {
funcName: "fluid.uiOptions.modelRelay.removeListeners",
args: ["{that}.options.rules", "{that}.options.sourceApplier", "{that}.options.listenerNamespaces"]
args: ["{that}.options.sourceApplier.modelChanged", "{that}.options.listenerNamespaces"]
}
},
sourceApplier: null, // must be supplied by implementors
rules: {} // must be supplied by implementors, in format: "externalModelKey": "internalModelKey"
});

fluid.uiOptions.modelRelay.removeListeners = function (rules, applier, namespaces) {
fluid.uiOptions.modelRelay.removeListeners = function (modelChanged, namespaces) {
fluid.each(namespaces, function (namespace) {
applier.removeListener(namespace);
modelChanged.removeListener(namespace);
});
};

Expand Down
77 changes: 64 additions & 13 deletions src/webapp/tests/component-tests/uiOptions/js/ModelRelayTests.js
Expand Up @@ -22,7 +22,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
* Unit tests for fluid.uiOptions.modelRelay
*******************************************************************************/

var resultValue;
var resultValue, resultWrapperValue;

fluid.defaults("fluid.tests.modelRelay", {
gradeNames: ["fluid.test.testEnvironment", "autoInit"],
Expand All @@ -39,64 +39,115 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
fluid.defaults("fluid.uiOptions.modelRelayWrapper", {
gradeNames: ["fluid.modelComponent", "fluid.eventedComponent", "autoInit"],
model: {
wrapperValue: null
wrapperValue: null,
anotherValue: null
},
components: {
modelRelayImpl: {
type: "fluid.uiOptions.modelRelay",
options: {
sourceApplier: "{modelRelayWrapper}.applier",
rules: {
"wrapperValue": "value"
"wrapperValue": "value",
"anotherValue": "anotherInternalValue"
},
model: {
value: null
value: null,
anotherInternalValue: null
},
finalInit: "fluid.uiOptions.modelRelay.finalInit"
listeners: {
onCreate: {
listener: "fluid.uiOptions.modelRelay.init",
args: "{that}"
}
}
}
}
},
listeners: {
onCreate: {
listener: "fluid.uiOptions.modelRelayWrapper.init",
args: "{that}"
}
}
});

fluid.uiOptions.modelRelay.finalInit = function (that) {
fluid.uiOptions.modelRelay.init = function (that) {
that.applier.modelChanged.addListener("value", function (newModel) {
resultValue = newModel.value;
});
};

fluid.tests.checkResult = function (expectedValue) {
fluid.uiOptions.modelRelayWrapper.init = function (that) {
that.applier.modelChanged.addListener("wrapperValue", function (newModel) {
resultWrapperValue = newModel.wrapperValue;
});
};

fluid.tests.checkImplResult = function (expectedValue) {
return function () {
jqUnit.assertEquals("The model change request on the modelRelay has been fired", expectedValue, resultValue);
};
};

fluid.tests.checkWrapperResult = function (expectedValue) {
return function () {
jqUnit.assertEquals("The model change request on the modelRelay has been fired", expectedValue, resultWrapperValue);
};
};

fluid.tests.destroyModelRelayImpl = function (modelRelayWrapper) {
var instantiator = fluid.getInstantiator(modelRelayWrapper);
instantiator.clearComponent(modelRelayWrapper, "modelRelayImpl");
};

fluid.tests.testListenerRemoval = function (sourceApplier, newValue) {
return function () {
sourceApplier.requestChange("wrapperValue", newValue);

jqUnit.assertNotEquals("The listener on the source applier to co-trigger internal applier has been removed and not fired", newValue, resultValue);
};
};

fluid.defaults("fluid.tests.modelRelayTester", {
gradeNames: ["fluid.test.testCaseHolder", "autoInit"],
testOptions: {
newValue1: "This is a test string 1.",
newValue2: "This is a test string 2."
newValue2: "This is a test string 2.",
newValue3: "This is a test string 3."
},
modules: [{
name: "Test model relay component",
tests: [{
expect: 2,
expect: 4,
name: "The applier change request on the modelRelay wrapper triggers the request on the modelRelay itself",
sequence: [{
func: "jqUnit.assertEquals",
args: ["All the listeners registered for the source applier are tracked", 2, "{modelRelayWrapper}.modelRelayImpl.options.listenerNamespaces.length"]
}, {
func: "{modelRelayWrapper}.applier.requestChange",
args: ["wrapperValue", "{that}.options.testOptions.newValue1"]
}, {
listenerMaker: "fluid.tests.checkResult",
listenerMaker: "fluid.tests.checkImplResult",
makerArgs: ["{that}.options.testOptions.newValue1"],
spec: {path: "wrapperValue", priority: "last"},
changeEvent: "{modelRelayWrapper}.applier.modelChanged"
}, {
func: "{modelRelayWrapper}.modelRelayImpl.applier.requestChange",
args: ["value", "{that}.options.testOptions.newValue2"]
}, {
listenerMaker: "fluid.tests.checkResult",
listenerMaker: "fluid.tests.checkWrapperResult",
makerArgs: ["{that}.options.testOptions.newValue2"],
spec: {path: "value", priority: "last"},
changeEvent: "{modelRelayWrapper}.modelRelayImpl.applier.modelChanged"
spec: {path: "wrapperValue", priority: "last"},
changeEvent: "{modelRelayWrapper}.applier.modelChanged"
}, {
func: "fluid.tests.destroyModelRelayImpl",
args: ["{modelRelayWrapper}"]
}, {
listenerMaker: "fluid.tests.testListenerRemoval",
makerArgs: ["{modelRelayWrapper}.applier", "{that}.options.testOptions.newValue3"],
spec: {priority: "last"},
event: "{modelRelayWrapper}.modelRelayImpl.events.onDestroy"
}]
}]
}]
Expand Down

0 comments on commit 64be46e

Please sign in to comment.