mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-02 07:07:46 -04:00
add tests for manipulators
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
'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 = {
|
||||
html: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('innerHTML');
|
||||
},
|
||||
set: function(value) {
|
||||
return this.$manipulatorTarget.set('innerHTML', value)
|
||||
.trigger('change');
|
||||
this.$manipulatorTarget.set('innerHTML', value);
|
||||
return this.trigger('change');
|
||||
}
|
||||
},
|
||||
val: {
|
||||
@@ -15,33 +31,21 @@ module.exports = {
|
||||
return this.$manipulatorTarget.get('value');
|
||||
},
|
||||
set: function(value) {
|
||||
return this.$manipulatorTarget.set('value', value)
|
||||
.trigger('change');
|
||||
this.$manipulatorTarget.set('value', value)
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: function() {
|
||||
return this.$manipulatorTarget.set('disabled', true)
|
||||
.trigger('disabled');
|
||||
},
|
||||
enable: function() {
|
||||
return this.$manipulatorTarget.set('disabled', false)
|
||||
.trigger('enabled');
|
||||
}
|
||||
disable: disable,
|
||||
enable: enable
|
||||
},
|
||||
checked: {
|
||||
get: function() {
|
||||
return this.$manipulatorTarget.get('checked');
|
||||
},
|
||||
set: function(value) {
|
||||
return this.$manipulatorTarget.set('checked', value)
|
||||
.trigger('change');
|
||||
this.$manipulatorTarget.set('checked', value)
|
||||
return this.trigger('change');
|
||||
},
|
||||
disable: function() {
|
||||
return this.$manipulatorTarget.set('disabled', true)
|
||||
.trigger('change');
|
||||
},
|
||||
enable: function() {
|
||||
return this.$manipulatorTarget.set('disabled', false)
|
||||
.trigger('change');
|
||||
}
|
||||
disable: disable,
|
||||
enable: enable
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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