Skip to content

Commit

Permalink
Merge branch 'GPII-3699'
Browse files Browse the repository at this point in the history
* GPII-3699:
  GPII-3706: Updated testem to pick up missing `nyc` dependency.
  GPII-3699: Added test to confirm that only one model change occurs per form update.
  GPII-3699: Updated form->model relay to ensure that only one change is fired.
  NOJIRA: Routine update of dependencies.
  • Loading branch information
amb26 committed Feb 16, 2019
2 parents c4a0307 + 0e382a8 commit 5e6e35b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
},
"repository": "https://github.com/GPII/gpii-binder",
"dependencies": {
"infusion": "3.0.0-dev.20181030T133624Z.f977b0fa9"
"infusion": "3.0.0-dev.20181204T213346Z.2ca90f6e6"
},
"devDependencies": {
"eslint": "5.9.0",
"eslint": "5.13.0",
"eslint-config-fluid": "1.3.0",
"gpii-grunt-lint-all": "1.0.5",
"gpii-testem": "2.1.6",
"gpii-testem": "2.1.8-dev.20190212T093057Z.dbd30b2.GPII-3706",
"grunt": "1.0.3",
"node-jqunit": "1.1.8",
"qunitjs": "2.4.1",
"rimraf": "2.6.2",
"rimraf": "2.6.3",
"testem": "2.12.0"
}
}
9 changes: 5 additions & 4 deletions src/js/binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
*/
gpii.binder.changeModelValue = function (that, path, elementValue) {
var transformedValue = gpii.binder.transformPathedValue(that, path, elementValue, "domToModel");
var changes = [];
changes.push({ path: path, type: "DELETE"});

var transaction = that.applier.initiate();
transaction.fireChangeRequest({ path: path, type: "DELETE"});

if (transformedValue !== null && transformedValue !== undefined) {
changes.push({ path: path, value: transformedValue });
transaction.fireChangeRequest({ path: path, value: transformedValue });
}

fluid.fireChanges(that.applier, changes);
transaction.commit();
};

/**
Expand Down
30 changes: 29 additions & 1 deletion tests/static/js/tests-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,36 @@
"use strict";
var gpii = fluid.registerNamespace("gpii");

fluid.registerNamespace("gpii.tests.binder.base");

gpii.tests.binder.base.tallyUpdates = function (that, path) {
console.log("tallying a model change to '" + path + "'.");
var currentCount = fluid.get(that.updateCounter, path) || 0;
currentCount++;
fluid.set(that.updateCounter, path, currentCount);
};

// Base viewComponent used in most tests.
fluid.defaults("gpii.tests.binder.base", {
gradeNames: ["gpii.binder.bindOnCreate"],
model: {
initFromModel: "initialized from model" // The markup will be initialized with this value.
},
members: {
updateCounter: {}
},
selectors: {
initFromModel: "[name='init-from-model']",
initFromMarkup: "[name='init-from-markup']",
updateFromModel: "[name='update-from-model']",
updateFromMarkup: "[name='update-from-markup']",
missingElement: ".not-found-at-all"
},
modelListeners: {
"*": {
funcName: "gpii.tests.binder.base.tallyUpdates",
args: ["{that}", "{change}.path"]
}
}
});

Expand Down Expand Up @@ -115,16 +133,26 @@
name: "Common tests for gpii-binder...",
tests: [
{
name: "Confirm that a form update results in a model update...",
name: "Confirm that a form update results in a single model update...",
type: "test",
sequence: [
// The value should have been changed once based on the value of the markup.
{
funcName: "jqUnit.assertEquals",
args: ["There should have been one initial model relay to populate the field.", 1, "{testEnvironment}.binder.updateCounter.updateFromMarkup"]
},
{
func: "fluid.changeElementValue",
args: ["[name='update-from-markup']", "updated via form element"]
},
{
func: "jqUnit.assertEquals",
args: [ QUnit.config.currentModule + ": Model data should be correctly updated after a form field change...", "updated via form element", "{testEnvironment}.binder.model.updateFromMarkup"]
},
// The tally should now indicate that the value has been updated twice.
{
funcName: "jqUnit.assertEquals",
args: ["There should have been one additional model relay based on the form change.", 2, "{testEnvironment}.binder.updateCounter.updateFromMarkup"]
}
]
},
Expand Down

0 comments on commit 5e6e35b

Please sign in to comment.