only dispatch manipulator events if the state is actually changed.

This commit is contained in:
Keegan
2016-03-06 14:28:38 +11:00
parent bdcd820f7c
commit 069d4a80da
5 changed files with 104 additions and 20 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
var assert = require('chai').assert;
var fixture = require('../../fixture');
describe('component - color', function() {
describe('component - select', function() {
it('sets the value display to the correct value on change', function() {
var clayConfig = fixture.clayConfig([
{
+15 -8
View File
@@ -19,9 +19,10 @@ describe('manipulators', function() {
it('sets: "' + value + '" and gets: "' + expected + '" then triggers "change"',
function() {
var handlerSpy = sinon.spy();
var clayItem = fixture.clayItem(itemType);
var clayItem = fixture.clayConfig([itemType]).getAllItems()[0];
clayItem.on('change', handlerSpy);
clayItem.set(value);
clayItem.set(value);
assert.deepEqual(clayItem.get(), expected);
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
@@ -45,6 +46,7 @@ describe('manipulators', function() {
false
);
clayItem.disable();
clayItem.disable();
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
true
@@ -73,6 +75,7 @@ describe('manipulators', function() {
true
);
clayItem.enable();
clayItem.enable();
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
false
@@ -100,6 +103,7 @@ describe('manipulators', function() {
false
);
clayItem.hide();
clayItem.hide();
assert.strictEqual(
clayItem.$element[0].classList.contains('hide'),
true
@@ -127,6 +131,7 @@ describe('manipulators', function() {
true
);
clayItem.show();
clayItem.show();
assert.strictEqual(
clayItem.$element[0].classList.contains('hide'),
false
@@ -145,6 +150,7 @@ describe('manipulators', function() {
describe('val', function() {
testSetGet('input', 'test321');
testSetGet('input', 1234, '1234');
testDisable('input');
testEnable('input');
testShow('text');
@@ -152,10 +158,10 @@ describe('manipulators', function() {
});
describe('checked', function() {
testSetGet('toggle', true, 1);
testSetGet('toggle', 1);
testSetGet('toggle', false, 0);
testSetGet('toggle', 0);
testSetGet({type: 'toggle', defaultValue: 0}, true, 1);
testSetGet({type: 'toggle', defaultValue: 0}, 1);
testSetGet({type: 'toggle', defaultValue: 1}, false, 0);
testSetGet({type: 'toggle', defaultValue: 1}, 0);
testDisable('toggle');
testEnable('toggle');
testShow('toggle');
@@ -185,6 +191,7 @@ describe('manipulators', function() {
var item = {
type: 'checkboxgroup',
clayId: 1,
defaultValue: ['two'],
options: [
{ label: '1', value: 'one' },
{ label: '2', value: 'two' },
@@ -207,9 +214,9 @@ describe('manipulators', function() {
testSetGet('color', '0xFF0000', 0xff0000);
testSetGet('color', '#ff0000', 0xff0000);
testSetGet('color', 0xff0000, 0xff0000);
testSetGet('color', '', 0x000000);
testSetGet('color', false, 0x000000);
testSetGet('color', undefined, 0x000000);
testSetGet({type: 'color', defaultValue: 0x00ff00}, '', 0x000000);
testSetGet({type: 'color', defaultValue: 0x00ff00}, false, 0x000000);
testSetGet({type: 'color', defaultValue: 0x00ff00}, undefined, 0x000000);
testDisable('color');
testEnable('color');
testShow('color');