Merge "ES6ify /gr-button/*"

This commit is contained in:
Becky Siegel
2017-05-15 23:25:00 +00:00
committed by Gerrit Code Review
2 changed files with 32 additions and 30 deletions

View File

@@ -34,8 +34,8 @@
},
listeners: {
'tap': '_handleAction',
'click': '_handleAction',
tap: '_handleAction',
click: '_handleAction',
},
behaviors: [
@@ -52,21 +52,21 @@
'space enter': '_handleCommitKey',
},
_handleAction: function(e) {
_handleAction(e) {
if (this.disabled) {
e.preventDefault();
e.stopImmediatePropagation();
}
},
_disabledChanged: function(disabled) {
_disabledChanged(disabled) {
if (disabled) {
this._enabledTabindex = this.getAttribute('tabindex');
}
this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex);
},
_handleCommitKey: function(e) {
_handleCommitKey(e) {
e.preventDefault();
this.click();
},

View File

@@ -33,63 +33,65 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-select tests', function() {
var element;
var sandbox;
suite('gr-select tests', () => {
let element;
let sandbox;
var addSpyOn = function(eventName) {
var spy = sandbox.spy();
const addSpyOn = function(eventName) {
const spy = sandbox.spy();
element.addEventListener(eventName, spy);
return spy;
};
setup(function() {
setup(() => {
element = fixture('basic');
sandbox = sinon.sandbox.create();
});
teardown(function() {
teardown(() => {
sandbox.restore();
});
['tap', 'click'].forEach(function(eventName) {
test('dispatches ' + eventName + ' event', function() {
var spy = addSpyOn(eventName);
for (const eventName of ['tap', 'click']) {
test('dispatches ' + eventName + ' event', () => {
const spy = addSpyOn(eventName);
MockInteractions.tap(element);
assert.isTrue(spy.calledOnce);
});
});
}
// Keycodes: 32 for Space, 13 for Enter.
[32, 13].forEach(function(key) {
test('dispatches tap event on keycode ' + key, function() {
var tapSpy = sandbox.spy();
for (const key of [32, 13]) {
test('dispatches tap event on keycode ' + key, () => {
const tapSpy = sandbox.spy();
element.addEventListener('tap', tapSpy);
MockInteractions.pressAndReleaseKeyOn(element, key);
assert.isTrue(tapSpy.calledOnce);
})});
});
}
suite('disabled', function() {
setup(function() {
suite('disabled', () => {
setup(() => {
element.disabled = true;
});
['tap', 'click'].forEach(function(eventName) {
test('stops ' + eventName + ' event', function() {
var spy = addSpyOn(eventName);
for (const eventName of ['tap', 'click']) {
test('stops ' + eventName + ' event', () => {
const spy = addSpyOn(eventName);
MockInteractions.tap(element);
assert.isFalse(spy.called);
});
});
}
// Keycodes: 32 for Space, 13 for Enter.
[32, 13].forEach(function(key) {
test('stops tap event on keycode ' + key, function() {
var tapSpy = sandbox.spy();
for (const key of [32, 13]) {
test('stops tap event on keycode ' + key, () => {
const tapSpy = sandbox.spy();
element.addEventListener('tap', tapSpy);
MockInteractions.pressAndReleaseKeyOn(element, key);
assert.isFalse(tapSpy.called);
})});
});
}
});
});
</script>