Skip to content

Commit

Permalink
Merge branch '1.5' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickroger committed Oct 19, 2016
2 parents 739a2a0 + 264e810 commit 3f27830
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Resources/public/js/models/ez-locationmodel.js
Expand Up @@ -147,8 +147,12 @@ YUI.add('ez-locationmodel', function (Y) {
locationUpdateStruct.body.LocationUpdate.sortOrder = this.get('sortOrder');
options.api.getContentService().updateLocation(this.get('id'), locationUpdateStruct,
Y.bind(function (error, response) {
var updatedLocation;

if (!error) {
this.set('hidden', (hidden === 'true'));
updatedLocation = this.parse(response);
this.set('hidden', updatedLocation.hidden);
this.set('invisible', updatedLocation.invisible);
}
callback(error, response);
}, this)
Expand Down Expand Up @@ -181,7 +185,7 @@ YUI.add('ez-locationmodel', function (Y) {

/**
* Swap the location with other location
*
*
* @method swap
* @param {Object} options the required for the swap *
* @param {Object} options.api (required) the JS REST client instance
Expand Down Expand Up @@ -319,7 +323,7 @@ YUI.add('ez-locationmodel', function (Y) {

/**
* Returns if the location is a root one
*
*
* @method isRootLocation
* @return {boolean}
*/
Expand Down
26 changes: 22 additions & 4 deletions Tests/js/models/assets/ez-locationmodel-tests.js
Expand Up @@ -558,27 +558,41 @@ YUI.add('ez-locationmodel-tests', function (Y) {
delete this.model;
},

_configureUpdateLocationMock: function (cbError) {
_configureUpdateLocationMock: function (cbError, invisible, hidden) {
var response = {
document: {
Location: {
invisible: invisible,
hidden: hidden,
},
},
};

Mock.expect(this.contentServiceMock, {
method: 'updateLocation',
args: [this.locationId, this.updateStruct, Mock.Value.Function],
run: function (id, struct, cb) {
cb(cbError);
cb(cbError, response);
},
});
},

"Should hide the location": function () {
var options = {api: this.capiMock};

this._configureUpdateLocationMock(false);
this._configureUpdateLocationMock(false, true, true);

this.model.hide(options, this.callback);

Assert.isTrue(
this.model.get('hidden'),
"Attribute hidden should have been set to true"
);
Assert.isTrue(
this.model.get('invisible'),
"Attribute invisible should have been set to true"
);

Assert.isTrue(
this.callbackCalled,
"Callback should have been called"
Expand All @@ -591,14 +605,18 @@ YUI.add('ez-locationmodel-tests', function (Y) {
"Should unhide the location": function () {
var options = {api: this.capiMock};

this._configureUpdateLocationMock(false);
this._configureUpdateLocationMock(false, false, false);

this.model.unhide(options, this.callback);

Assert.isFalse(
this.model.get('hidden'),
"Attribute hidden should have been set to false"
);
Assert.isFalse(
this.model.get('invisible'),
"Attribute invisible should have been set to false"
);
Assert.isTrue(
this.callbackCalled,
"Callback should have been called"
Expand Down

0 comments on commit 3f27830

Please sign in to comment.