mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-06 00:57:21 -04:00
add tests for manipulators
This commit is contained in:
@@ -1,13 +1,29 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {ClayEvents}
|
||||||
|
*/
|
||||||
|
function disable() {
|
||||||
|
this.$manipulatorTarget.set('disabled', true);
|
||||||
|
return this.trigger('disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {ClayEvents}
|
||||||
|
*/
|
||||||
|
function enable() {
|
||||||
|
this.$manipulatorTarget.set('disabled', false);
|
||||||
|
return this.trigger('enabled');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
html: {
|
html: {
|
||||||
get: function() {
|
get: function() {
|
||||||
return this.$manipulatorTarget.get('innerHTML');
|
return this.$manipulatorTarget.get('innerHTML');
|
||||||
},
|
},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
return this.$manipulatorTarget.set('innerHTML', value)
|
this.$manipulatorTarget.set('innerHTML', value);
|
||||||
.trigger('change');
|
return this.trigger('change');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
val: {
|
val: {
|
||||||
@@ -15,33 +31,21 @@ module.exports = {
|
|||||||
return this.$manipulatorTarget.get('value');
|
return this.$manipulatorTarget.get('value');
|
||||||
},
|
},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
return this.$manipulatorTarget.set('value', value)
|
this.$manipulatorTarget.set('value', value)
|
||||||
.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: function() {
|
disable: disable,
|
||||||
return this.$manipulatorTarget.set('disabled', true)
|
enable: enable
|
||||||
.trigger('disabled');
|
|
||||||
},
|
|
||||||
enable: function() {
|
|
||||||
return this.$manipulatorTarget.set('disabled', false)
|
|
||||||
.trigger('enabled');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
checked: {
|
checked: {
|
||||||
get: function() {
|
get: function() {
|
||||||
return this.$manipulatorTarget.get('checked');
|
return this.$manipulatorTarget.get('checked');
|
||||||
},
|
},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
return this.$manipulatorTarget.set('checked', value)
|
this.$manipulatorTarget.set('checked', value)
|
||||||
.trigger('change');
|
return this.trigger('change');
|
||||||
},
|
},
|
||||||
disable: function() {
|
disable: disable,
|
||||||
return this.$manipulatorTarget.set('disabled', true)
|
enable: enable
|
||||||
.trigger('change');
|
|
||||||
},
|
|
||||||
enable: function() {
|
|
||||||
return this.$manipulatorTarget.set('disabled', false)
|
|
||||||
.trigger('change');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = require('chai').assert;
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var fixture = require('../../fixture');
|
||||||
|
|
||||||
|
describe('manipulators', function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} itemType
|
||||||
|
* @param {*} value
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function testSetGet(itemType, value) {
|
||||||
|
describe('.set() and .get()', function() {
|
||||||
|
it('sets and gets the value then triggers a "change" event', function() {
|
||||||
|
var handlerSpy = sinon.spy();
|
||||||
|
var clayItem = fixture.clayItem(itemType);
|
||||||
|
clayItem.on('change', handlerSpy);
|
||||||
|
|
||||||
|
clayItem.set(value);
|
||||||
|
assert.strictEqual(clayItem.get(), value);
|
||||||
|
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||||
|
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} itemType
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function testDisable(itemType) {
|
||||||
|
describe('.disable()', function() {
|
||||||
|
it('disables the field then triggers a "disabled" event', function() {
|
||||||
|
var handlerSpy = sinon.spy();
|
||||||
|
var clayItem = fixture.clayItem(itemType);
|
||||||
|
clayItem.on('disabled', handlerSpy);
|
||||||
|
|
||||||
|
clayItem.disable();
|
||||||
|
assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), true);
|
||||||
|
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||||
|
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} itemType
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
function testEnable(itemType) {
|
||||||
|
describe('.disable()', function() {
|
||||||
|
it('disables the field then triggers an "enabled" event', function() {
|
||||||
|
var handlerSpy = sinon.spy();
|
||||||
|
var clayItem = fixture.clayItem(itemType);
|
||||||
|
clayItem.on('enabled', handlerSpy);
|
||||||
|
|
||||||
|
clayItem.enable();
|
||||||
|
assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), false);
|
||||||
|
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
|
||||||
|
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('html', function() {
|
||||||
|
testSetGet('footer', 'test123');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('val', function() {
|
||||||
|
testSetGet('input', 'test321');
|
||||||
|
testDisable('input');
|
||||||
|
testEnable('input');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checked', function() {
|
||||||
|
testSetGet('toggle', true);
|
||||||
|
testSetGet('toggle', false);
|
||||||
|
testDisable('toggle');
|
||||||
|
testEnable('toggle');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user