unit-tests.html revision 84765788c559bfdead67172a79759ac60c77231b
0N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2362N/A<html>
0N/A<head>
0N/A<title>Panel Tests</title>
0N/A<script type="text/javascript" src="/build/yui/yui-min.js"></script>
0N/A</head>
0N/A
0N/A<body class="yui3-skin-sam">
0N/A<h1>Panel Tests</h1>
0N/A<div id="container"></div>
0N/A<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
0N/A
0N/A<script type="text/javascript">
0N/A(function() {
0N/A YUI({
0N/A filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
0N/A allowRollup: false
0N/A }).use("console", "test", "dump", "panel", function(Y) {
2362N/A
2362N/A
2362N/A // Set up the page
0N/A var ASSERT = Y.Assert,
0N/A ARRAYASSERT = Y.ArrayAssert,
4638N/A BTNRUN = Y.one("#btnRun");
0N/A BTNRUN.set("disabled", false);
0N/A Y.on("click", function(e){
4638N/A Y.Test.Runner.run();
0N/A }, BTNRUN);
0N/A var myConsole = new Y.Console().render();
0N/A
0N/A
0N/A var testBasic = new Y.Test.Case({
0N/A name: "API Tests",
0N/A
0N/A //---------------------------------------------
0N/A // Setup and tear down
0N/A //---------------------------------------------
0N/A
0N/A setUp : function () {
0N/A
0N/A //create recordset
0N/A var template = "<div id='panelContent'></div>";
0N/A Y.one('#container').appendChild(Y.Node.create(template));
0N/A this.panel = null;
0N/A
0N/A //Some Ways to access recordset properties
0N/A //Y.log(rs.getRecordByIndex(0).getValue('a'));
0N/A //Y.log(rs.get('records').length);
0N/A },
0N/A
0N/A tearDown : function () {
0N/A delete this.panel;
0N/A Y.one('#panelContent').remove();
0N/A var mask = Y.one(".yui3-widget-mask");
0N/A if (mask) {
0N/A mask.remove();
0N/A }
0N/A },
0N/A
0N/A
0N/A testBasicPanel : function() {
0N/A var cfg = {
0N/A srcNode: "#panelContent",
4638N/A headerContent: "Test Header Content",
0N/A bodyContent: "TestBodyContent",
0N/A centered:true
0N/A };
0N/A
0N/A this.panel = new Y.Panel(cfg);
0N/A this.panel.render();
0N/A
0N/A var bb = this.panel.get('boundingBox');
0N/A var buttons = this.panel.get('buttons');
0N/A var hd = Y.one('#panelContent .yui3-widget-hd');
0N/A
0N/A //panel is visible
0N/A Y.Assert.areEqual(this.panel.get('visible'), true);
0N/A Y.Assert.areEqual(bb.getStyle('display'), "block");
0N/A
0N/A //the button that is viewable is the close button
4638N/A Y.Assert.areEqual(buttons[0].type, "close");
0N/A Y.Assert.areEqual(buttons.length, 1);
0N/A Y.Assert.isTrue(hd.hasChildNodes());
//there is no mask
var mask = Y.one('.yui3-widget-mask');
Y.Assert.isNull(mask);
},
testModalPanel : function() {
var cfg = {
srcNode: "#panelContent",
headerContent: "Test Header Content",
bodyContent: "TestBodyContent",
centered:true,
modal:true
};
this.panel = new Y.Panel(cfg);
this.panel.render();
var bb = this.panel.get('boundingBox');
var buttons = this.panel.get('buttons');
var hd = Y.one('#panelContent .yui3-widget-hd');
//panel is visible
Y.Assert.areEqual(this.panel.get('visible'), true);
Y.Assert.areEqual(bb.getStyle('display'), "block");
//the button that is viewable is the close button
Y.Assert.areEqual(buttons[0].type, "close");
Y.Assert.areEqual(buttons.length, 1);
Y.Assert.isTrue(hd.hasChildNodes());
//mask is visible
var mask = Y.one('.yui3-widget-mask');
Y.Assert.areEqual(mask.getStyle('display'), "block");
},
testPanelWithHeaderButtons : function() {
var cfg = {
srcNode: "#panelContent",
bodyContent: "TestBodyContent",
centered:true,
buttons: [
{
value: "hd button 1",
action: function(e) {
Y.log('hd button1 clicked');
},
section: Y.WidgetStdMod.HEADER
},
{
value: "hd button 2",
action: function(e) {
Y.log('hd button2 clicked');
},
section: "header"
}
]
};
this.panel = new Y.Panel(cfg);
this.panel.render();
var bb = this.panel.get('boundingBox');
var buttons = this.panel.get('buttons');
var hd = Y.one('#panelContent .yui3-widget-hd');
var wrap = Y.one('#panelContent .yui3-widget-hd .yui3-widget-button-wrapper');
var btns = Y.all('.yui3-button');
//panel is visible
Y.Assert.areEqual(this.panel.get('visible'), true);
Y.Assert.areEqual(bb.getStyle('display'), "block");
//the correct buttons are viewable
Y.Assert.isUndefined(buttons[0].type);
Y.Assert.areEqual(buttons.length, 2);
Y.Assert.isTrue(hd.hasChildNodes());
Y.Assert.isTrue(wrap.hasChildNodes());
Y.Assert.areEqual(btns.size(), 2);
//mask is not visible
var mask = Y.one('.yui3-widget-mask');
Y.Assert.isNull(mask);
},
testPanelWithFooterButtons : function() {
var cfg = {
srcNode: "#panelContent",
bodyContent: "TestBodyContent",
centered:true,
buttons: [
{
value: "ft button 1",
action: function(e) {
Y.log('ft button1 clicked');
},
section: Y.WidgetStdMod.FOOTER
},
{
value: "ft button 2",
action: function(e) {
Y.log('ft button2 clicked');
},
section: "footer"
}
]
};
this.panel = new Y.Panel(cfg);
this.panel.render();
var bb = this.panel.get('boundingBox');
var buttons = this.panel.get('buttons');
var hd = Y.one('#panelContent .yui3-widget-hd');
var ft = Y.one('#panelContent .yui3-widget-ft');
var wrap = Y.one('#panelContent .yui3-widget-ft .yui3-widget-button-wrapper');
var btns = Y.all('.yui3-button');
var btnspan = Y.all('.yui3-button-content');
//panel is visible
Y.Assert.areEqual(this.panel.get('visible'), true);
Y.Assert.areEqual(bb.getStyle('display'), "block");
//the correct buttons are viewable
Y.Assert.isUndefined(buttons[0].type);
Y.Assert.areEqual(buttons.length, 2);
Y.Assert.isNull(hd);
Y.Assert.isTrue(ft.hasChildNodes());
Y.Assert.isTrue(wrap.hasChildNodes());
Y.Assert.areEqual(btns.size(), 2);
Y.Assert.areEqual(btnspan.size(), 2);
Y.Assert.areEqual(btnspan.item(0).getContent(), "ft button 1");
Y.Assert.areEqual(btnspan.item(1).getContent(), "ft button 2");
//mask is not visible
var mask = Y.one('.yui3-widget-mask');
Y.Assert.isNull(mask);
},
testPanelWithChangingButtons: function() {
var cfg = {
srcNode: "#panelContent",
bodyContent: "TestBodyContent",
centered:true,
modal:true
};
this.panel = new Y.Panel(cfg);
this.panel.render();
var bb = this.panel.get('boundingBox');
var buttons = this.panel.get('buttons');
var hd = Y.one('#panelContent .yui3-widget-hd');
var ft = Y.one('#panelContent .yui3-widget-ft');
var wrap = Y.one('#panelContent .yui3-widget-ft .yui3-widget-button-wrapper');
var btns = Y.all('.yui3-button');
var btnspan = Y.all('.yui3-button-content');
//panel is visible
Y.Assert.areEqual(this.panel.get('visible'), true);
Y.Assert.areEqual(bb.getStyle('display'), "block");
//the correct buttons are viewable - only the close button in this case
Y.Assert.areEqual(buttons[0].type, "close");
Y.Assert.areEqual(buttons.length, 1);
Y.Assert.isNull(ft);
Y.Assert.areEqual(btns.size(), 1);
//add a button in to the footer
this.panel.addButton({
value: "ft button 1",
action: function(e) {
Y.log('ft button1 clicked');
},
section: Y.WidgetStdMod.FOOTER
});
ft = Y.one('#panelContent .yui3-widget-ft');
btns = Y.all('.yui3-button');
btnspan = Y.all('.yui3-button-content');
//test to make sure new button is visible
//there should be 2 buttons, the original [x] and the new footer button
Y.Assert.isTrue(ft.hasChildNodes());
Y.Assert.areEqual(btns.size(), 2);
Y.Assert.areEqual(btnspan.size(), 2);
Y.Assert.areEqual(btnspan.item(1).getContent(), "ft button 1");
//add the close button in to the header
this.panel.addButton({
type:"close"
});
hd = Y.one('#panelContent .yui3-widget-hd');
ft = Y.one('#panelContent .yui3-widget-ft');
btns = Y.all('.yui3-button');
btnspan = Y.all('.yui3-button-content');
Y.Assert.isTrue(hd.hasChildNodes());
Y.Assert.isTrue(ft.hasChildNodes());
Y.Assert.areEqual(btns.size(), 3);
Y.Assert.areEqual(btnspan.size(), 3);
Y.Assert.areEqual(btnspan.item(2).getContent(), "ft button 1"); //the last one should be the footer since the first 2 are the header [x] buttons
//mask is visible
var mask = Y.one('.yui3-widget-mask');
Y.Assert.areEqual(mask.getStyle('display'), "block");
}
//---------------------------------------------
// Instantiation
//---------------------------------------------
// testCreateEmptyRecordset: function() {
// var rs = new Y.Recordset(),
// rem;
// rs.on('remove', function(e) {
// rem = e.removed;
// });
// //instantiate empty recordset
// Y.Assert.isTrue(rs instanceof Y.Recordset);
// //perform operations on it
// rs.add({a:1, b:2, c:3});
// Y.ObjectAssert.areEqual(rs.getRecord(0).getValue(), {a:1, b:2, c:3});
// rs.add([{a:'hey', b:'yo', c:'hi!'}, {a:2, b:5, c:6}]);
// Y.ObjectAssert.areEqual(rs.getRecord(2).getValue(), {a:2, b:5, c:6});
// Y.Assert.areEqual(3, rs.getLength());
// rs.remove(2);
// Y.Assert.areEqual(2, rs.getLength());
// Y.ObjectAssert.areEqual(rem[0].getValue(), {a:2, b:5, c:6});
// },
// //---------------------------------------------
// // Get Records
// //---------------------------------------------
// testGetRecords: function() {
// var newRecord,newRecord1, newRecord2, id;
// //this.rs.get('records');
// // var newrs = new Y.Recordset({records: [{a:10,b:10,c:10}]});
// // newrs.get('records');
// //Single Record
// newRecord1 = this.rs.getRecordByIndex(1);
// newRecord2 = this.rs.getRecord(1);
// Y.ObjectAssert.areEqual(newRecord1.getValue(), this.initialData[1]);
// Y.ObjectAssert.areEqual(newRecord1, newRecord2);
// //Multiple Records
// newRecord = this.rs.getRecordsByIndex(1,2);
// Y.ObjectAssert.areEqual(newRecord[0].getValue(), this.initialData[1]);
// Y.ObjectAssert.areEqual(newRecord[1].getValue(), this.initialData[2]);
// //By ID
// id = this.rs.getRecordByIndex(0).get('id');
// newRecord = this.rs.getRecord(id);
// Y.ObjectAssert.areEqual(newRecord, this.rs.getRecordByIndex(0));
// },
});
var suite = new Y.Test.Suite({name:"Panel Test Suite"});
suite.add(testBasic);
Y.Test.Runner.setName("Panel Test Runner");
Y.Test.Runner.add(suite);
Y.Test.Runner.run();
});
})();
</script>
</body>
</html>