tabview-test.js revision 2f0d5a8bc2c94864389d6ba0d6f01483302e43bd
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt SweeneyYUI.add('tabview-test', function(Y) {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var tabview = new Y.TabView({
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney srcNode: '#demo'
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney }),
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney TEST_TIMEOUT = 1000;
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.render();
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Test.Runner.add(new Y.Test.Case({
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney name: 'Y.TabView',
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should return the selected tab': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(0, tabview.get('selection').get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should update the selected tab': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(1);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(1, tabview.get('selection').get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(0);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(0, tabview.get('selection').get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should fire selection change': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var test = this;
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.once('selectionChange', function(e) {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(0, e.prevVal.get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(1, e.newVal.get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney });
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(1);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should add the new tab to the tabview': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var tab = new Y.Tab({ label: 'new tab', content: 'new tab content' }),
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney children = tabview.add(tab);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(1, children.size());
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should remove the selected tab': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(1);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var tab = tabview.get('selection'),
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney index = tab.get('index'),
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney removedTab = tabview.remove(index);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(tab, removedTab);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(0, tabview.get('selection').get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.add(removedTab, 0);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual(1, tabview.get('selection').get('index'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(0);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should fire selectionChange event': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var pass = false;
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.on('selectionChange', function() { pass = true; });
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(1);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.isTrue(pass);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney pass = false;
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tabview.selectChild(0);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.isTrue(pass);
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should set the label': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var tab = new Y.Tab();
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tab.set('label', 'new label');
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual('new label', tab.get('label'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual('new label', tab.get('contentBox').get('text'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney },
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney 'should set the label': function() {
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney var tab = new Y.Tab();
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney tab.set('content', 'new content');
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual('new content', tab.get('content'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney Y.Assert.areEqual('new content', tab.get('panelNode').get('text'));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney }
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney }));
2f0d5a8bc2c94864389d6ba0d6f01483302e43bdMatt Sweeney}, '@VERSION@' ,{requires:['tabview', 'test']});