Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
EXOGTN-1604 [Edit-Inplace] Add more unit test for JS model
Browse files Browse the repository at this point in the history
  • Loading branch information
phuong_vu authored and vietj committed Oct 26, 2013
1 parent ca58a4f commit 2c1d8f2
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions portal/web/src/test/resources/assets/testJS/LayoutEditorTest.js
Expand Up @@ -15,9 +15,17 @@ module('test Container model', {
});

test("move app in same container test", function() {
//move app 1_1 from position 0 to 1
var cont1 = container.getDescendant('1');
var listener = listenTo(cont1);

//move app 1_1 from position 0 to 1
cont1.addChild('1_1', {at : 1});
//
equal(listener.aCalled.length, 1);
var args = listener.aCalled[0];
equal(args[0].getId(), '1_1');
equal(args[1].getId(), '1');
equal(listener.rCalled.length, 0);

var app1 = container.getDescendant('1_1');
ok(app1, 'app1 should be not null');
Expand All @@ -26,6 +34,9 @@ test("move app in same container test", function() {
});

test("move app to another container test", function() {
var cont1 = container.getDescendant('1');
var cont2 = container.getDescendant('2');

var app1 = container.getDescendant('1_1');
equal(app1.getParent().getId(), '1');
equal(app1.getIndex(), 0);
Expand All @@ -34,17 +45,47 @@ test("move app to another container test", function() {
equal(app2.getParent().getId(), '2');
equal(app2.getIndex(), 1);

//move app 1_1 to container 2 at postion 1
var cont2 = container.getDescendant('2');
cont2.addChild(app1, {at : 1});
//
var listener1 = listenTo(cont1);
var listener2 = listenTo(cont2);

//move app 1_1 to container 2 at postion 1
cont2.addChild('1_1', {at : 1});
equal(app1.getParent().getId(), '2');
equal(app1.getIndex(), 1);

//onRemoveChild event on cont1
equal(listener1.rCalled.length, 1);
equal(listener1.rCalled[0][0].getId(), '1_1');
equal(listener1.aCalled.length, 0);
//onAddChild event on cont2
equal(listener2.aCalled.length, 1);
equal(listener2.aCalled[0][0].getId(), '1_1');
equal(listener2.rCalled.length, 0);

//now app2 is in position 2
equal(app2.getParent().getId(), '2');
equal(app2.getIndex(), 2);
});

test("remove application test", function() {
var cont1 = container.getDescendant('1');
var listener = listenTo(cont1);

cont1.removeChild('1_1');
cont1.removeChild('1_2');
ok(cont1.isEmpty());

//
equal(listener.rCalled.length, 2);
var args = listener.rCalled[0];
equal(args[0].getId(), '1_1');
equal(args[1].getId(), '1');
equal(listener.rCalled[1][0].getId(), '1_2');
//
equal(listener.aCalled.length, 0);
});

test("test create container from JSON", function() {
var data = {id : 'root', childrens: [{id : 'cont1'} , {id : '2', childrens : []}]};
container.set(data);
Expand All @@ -55,7 +96,6 @@ test("test create container from JSON", function() {
equal(container.getChild('2').getChild('2_2'), null);
});


test("test toJSON", function() {
var data = container.toJSON();
equal(data.childrens.length, 2);
Expand Down Expand Up @@ -96,7 +136,7 @@ test("test switchLayout", function() {
//new layout with 1 zone
var oneZone = new PageContainer();
oneZone.addChild(new Container({id : "1"}));
equal(1, oneZone.get("_childrens").length);
equal(1, oneZone.getChildrens().length);
//switch from reverted layout to 1 zone layout
rLayout.switchLayout(oneZone);

Expand Down Expand Up @@ -127,4 +167,21 @@ test("test switchLayout", function() {
equal('2_1', threeZone.getChild('2').at(0).getId());
equal('2_2', threeZone.getChild('2').at(1).getId());
equal(true, threeZone.getChild('3').isEmpty());
});
});

function listenTo(model) {
var listener = {
aCalled: [],
rCalled: [],

onAddChild: function() {
listener.aCalled.push(arguments);
},
onRemoveChild: function() {
listener.rCalled.push(arguments);
}
};
model.on('container.addChild', listener.onAddChild);
model.on('container.removeChild', listener.onRemoveChild);
return listener;
}

0 comments on commit 2c1d8f2

Please sign in to comment.