Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaulting Y.ButtonCore's template to type=button (#973, #968) #1296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/button/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ButtonCore.prototype = {
* @type {String}
* @default <button/>
*/
TEMPLATE: '<button/>',
TEMPLATE: '<button type="button"/>',

/**
*
Expand Down Expand Up @@ -57,7 +57,7 @@ ButtonCore.prototype = {
* @private
*/
_initNode: function(config) {
if (config.host) {
if (config && config.host) {
this._host = Y.one(config.host);
} else {
this._host = Y.Node.create(this.TEMPLATE);
Expand Down
58 changes: 32 additions & 26 deletions src/button/tests/unit/assets/button-core-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ YUI.add('button-core-test', function (Y) {
var Assert = Y.Assert,
ArrayAssert = Y.ArrayAssert,
suite;

suite = new Y.Test.Suite('button-core');

suite.add(new Y.Test.Case({
Expand All @@ -15,7 +15,7 @@ YUI.add('button-core-test', function (Y) {
host: Y.one("#testButton")
});
},

tearDown: function () {
Y.one('#container').empty(true);
delete this.button;
Expand All @@ -24,10 +24,10 @@ YUI.add('button-core-test', function (Y) {
'Disabling a button should set the `disable` attribute to `true`': function () {
var button = this.button;
var node = button.getNode();

Assert.isFalse(button.get('disabled'));
Assert.isFalse(node.hasClass('yui3-button-disabled'));

button.set('disabled', true);
Assert.isTrue(button.get('disabled'));
Assert.isTrue(node.hasClass('yui3-button-disabled'));
Expand All @@ -36,11 +36,11 @@ YUI.add('button-core-test', function (Y) {
'Enabling a button should set the `disabled` attribute to `false`': function () {
var button = this.button;
var node = button.getNode();

button.disable();
Assert.isTrue(button.get('disabled'));
Assert.isTrue(node.hasClass('yui3-button-disabled'));

button.enable();
Assert.isFalse(button.get('disabled'));
Assert.isFalse(node.hasClass('yui3-button-disabled'));
Expand All @@ -50,48 +50,48 @@ YUI.add('button-core-test', function (Y) {
var button = this.button;
var defaultText = Y.ButtonCore.ATTRS.label.value;
var newText = 'foobar';

button.set('label', newText);
Assert.areEqual(newText, button.get('label'));
},

'Changing the label should change the `innerHTML` value of a button node': function () {
var button = this.button;
var node = button.getNode();
var defaultText = Y.ButtonCore.ATTRS.label.value;
var newText = 'foobar';

button.set('label', newText);
Assert.areEqual(newText, node.get('innerHTML'));
},

'Changing the `disabled` attribute should fire a `disabledChange` event': function () {
var button = this.button;
var eventsTriggered = 0;

Y.augment(button, Y.Attribute);

button.on('disabledChange', function(){
eventsTriggered+=1;
});

Assert.areEqual(0, eventsTriggered);
button.set('disabled', true);
Assert.areEqual(1, eventsTriggered);
button.set('disabled', true);
Assert.areEqual(2, eventsTriggered);
},

'Changing the `label` attribute should fire a `labelChange` event': function () {
var button = this.button;
var eventsTriggered = 0;

Y.augment(button, Y.Attribute);

button.on('labelChange', function(){
eventsTriggered+=1;
});

Assert.areEqual(0, eventsTriggered);
button.set('label', 'something');
Assert.areEqual(1, eventsTriggered);
Expand Down Expand Up @@ -123,48 +123,54 @@ YUI.add('button-core-test', function (Y) {
Assert.areSame('&lt;div&gt;foo&lt;/div&gt;', button.getNode().get('innerHTML'));
}
}));

suite.add(new Y.Test.Case({
name: 'Instantiation',

setUp : function () {

},

tearDown: function () {
Y.one('#container').empty(true);
},

'Creating an unattached button should create a Y.ButtonCore instance': function () {
var button = new Y.ButtonCore({label:'foo'});
Assert.areEqual(button.get('label'), 'foo');
Assert.isInstanceOf(Y.ButtonCore, button);
},

'Modifying the label of a nested button structure should not modify the non-label elements': function () {
Y.one("#container").setContent('<button id="testButton">**<span class="yui3-button-label">Hello</span>**</button>');
var button = new Y.ButtonCore({
host: Y.one("#testButton")
});
var node = button.getNode();

Assert.areEqual(node.get('text'), '**Hello**');
button.set('label', button.get('label') + ' World');
Assert.areEqual(button.get('label'), 'Hello World');
Assert.areEqual(node.get('text'), '**Hello World**');
},

'modifying the `label` attribute should work properly on <input> elements': function () {
Y.one("#container").setContent('<input type="button" id="testButton" value="foo">');
var button = new Y.ButtonCore({
host: Y.one("#testButton")
});

Assert.areEqual(button.get('label'), 'foo');
button.set('label', 'bar');
Assert.areEqual(button.get('label'), 'bar');
}

},

'Buttons should render as type=button': function () {
var button = new Y.ButtonCore();

Assert.areSame('button', button.getNode().get('type'));
}

}));

Y.Test.Runner.add(suite);
Expand Down