button-plugin-test.js revision 6b37812e1912808e0a6ae05310e3e71ddd5038ad
YUI.add('button-plugin-test', function (Y) {
var Assert = Y.Assert,
ArrayAssert = Y.ArrayAssert,
suite;
suite = new Y.Test.Suite('Buttons');
suite.add(new Y.Test.Case({
name: 'button plugin factory',
setUp : function () {
this.label = "Hello";
Y.one("#container").setContent('<button id="testButton">' + this.label + '</button>');
},
tearDown: function () {
Y.one('#container').empty(true);
},
'node.plug(Y.Plugin.Button, config) should return a Y.Node instance with Button functionality': function () {
var oldLabel = this.label;
var newLabel = 'World';
var node = Y.one("#testButton");
var button;
Assert.areSame(oldLabel, node.getContent());
Assert.isFalse(node.get('disabled'));
Assert.areNotSame(node, button);
button = Y.one("#testButton").plug(Y.Plugin.Button, {
label: newLabel,
disabled: true
});
Assert.areSame(node, button);
Assert.isInstanceOf(Y.Node, button);
Assert.areSame(newLabel, node.getContent());
Assert.isTrue(node.get('disabled'));
},
'Y.Plugin.Button.createNode(srcNode) should return a Y.Node instance with Button functionality': function () {
var oldLabel = this.label;
var newLabel = 'World';
var node = Y.one("#testButton");
var button;
Assert.areSame(oldLabel, node.getContent());
Assert.isFalse(node.get('disabled'));
Assert.areNotSame(node, button);
button = Y.Plugin.Button.createNode(Y.one("#testButton"));
node.set('label', newLabel);
button.set('disabled', true);
Assert.areSame(node, button);
Assert.isInstanceOf(Y.Node, button);
Assert.areSame(newLabel, node.getContent());
Assert.isTrue(node.get('disabled'));
},
'Y.Plugin.Button.createNode(srcNode, config) should return a Y.Node instance with Button functionality': function () {
var oldLabel = this.label;
var newLabel = 'World';
var node = Y.one("#testButton");
var button;
Assert.areSame(oldLabel, node.getContent());
Assert.isFalse(node.get('disabled'));
Assert.areNotSame(node, button);
button = Y.Plugin.Button.createNode(Y.one("#testButton"), {
'label': newLabel,
'disabled': true
});
Assert.areSame(node, button);
Assert.isInstanceOf(Y.Node, button);
Assert.areSame(newLabel, node.getContent());
Assert.isTrue(node.get('disabled'));
},
'Y.Plugin.Button.createNode(config) should return a Y.Node instance with Button functionality': function () {
var oldLabel = this.label;
var newLabel = 'World';
var node = Y.one("#testButton");
var button;
Assert.areSame(oldLabel, node.getContent());
Assert.isFalse(node.get('disabled'));
Assert.areNotSame(node, button);
button = Y.Plugin.Button.createNode({
srcNode: Y.one("#testButton"),
label: newLabel,
disabled: true
});
Assert.areSame(node, button);
Assert.isInstanceOf(Y.Node, button);
Assert.areSame(newLabel, node.getContent());
Assert.isTrue(node.get('disabled'));
}
}));
Y.Test.Runner.add(suite);
}, '@VERSION@', {
requires: ['button-plugin', 'test']
});