mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-05 08:37:43 -04:00
restructure directories and add tests for clay-item
This commit is contained in:
+14
-2
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('../src/scripts/vendor/minified/minified')._;
|
||||
var ClayItem = require('../src/scripts/lib/clay-item');
|
||||
var idCounter = 0;
|
||||
|
||||
/**
|
||||
@@ -8,7 +9,7 @@ var idCounter = 0;
|
||||
* @param {{}} [config]
|
||||
* @returns {{}}
|
||||
*/
|
||||
function fixture(type, config) {
|
||||
function configItem(type, config) {
|
||||
|
||||
var basic = {
|
||||
type: type,
|
||||
@@ -22,4 +23,15 @@ function fixture(type, config) {
|
||||
return _.extend({}, basic, config);
|
||||
}
|
||||
|
||||
module.exports = fixture;
|
||||
/**
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {{}} [config]
|
||||
* @returns {ClayItem}
|
||||
*/
|
||||
function clayItem(type, config) {
|
||||
return new ClayItem(configItem(type, config));
|
||||
}
|
||||
|
||||
module.exports.configItem = configItem;
|
||||
module.exports.clayItem = clayItem;
|
||||
|
||||
+71
-11
@@ -1,9 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var sinon = require('sinon');
|
||||
var ClayItem = require('../../../src/scripts/lib/clay-item');
|
||||
var fixture = require('../../fixture');
|
||||
var items = require('../../../src/scripts/lib/items');
|
||||
var clayItemFixture = require('../../fixture').clayItem;
|
||||
var configItemFixture = require('../../fixture').configItem;
|
||||
var componentRegistry = require('../../../src/scripts/lib/component-registry');
|
||||
|
||||
// add some components to the registry to test
|
||||
componentRegistry.text = require('../../../src/scripts/components/text');
|
||||
componentRegistry.input = require('../../../src/scripts/components/input');
|
||||
componentRegistry.toggle = require('../../../src/scripts/components/toggle');
|
||||
componentRegistry.footer = require('../../../src/scripts/components/footer');
|
||||
componentRegistry.select = require('../../../src/scripts/components/select');
|
||||
|
||||
/**
|
||||
* @param {Object} object
|
||||
@@ -32,36 +41,87 @@ describe('ClayItem', function() {
|
||||
'trigger',
|
||||
'initialize'
|
||||
];
|
||||
var apiItem = new ClayItem(fixture('input'));
|
||||
checkReadOnly(apiItem, properties);
|
||||
var clayItem = clayItemFixture('input');
|
||||
checkReadOnly(clayItem, properties);
|
||||
});
|
||||
|
||||
it('attaches the manipulator methods', function() {
|
||||
Object.keys(items).forEach(function(itemName) {
|
||||
var clayItem = new ClayItem(fixture(itemName));
|
||||
var manipulator = items[itemName].manipulator;
|
||||
Object.keys(componentRegistry).forEach(function(itemName) {
|
||||
var clayItem = clayItemFixture(itemName);
|
||||
var manipulator = componentRegistry[itemName].manipulator;
|
||||
checkReadOnly(clayItem, Object.keys(manipulator));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.id', function() {
|
||||
it('sets id correctly', function() {
|
||||
var config = fixture('input');
|
||||
it('sets id if config has id', function() {
|
||||
var config = configItemFixture('input');
|
||||
var clayItem = new ClayItem(config);
|
||||
assert.strictEqual(clayItem.id, config.id);
|
||||
});
|
||||
|
||||
it('sets id to null if there is no id in the config', function() {
|
||||
var clayItem = clayItemFixture('input', {id: undefined});
|
||||
assert.strictEqual(clayItem.id, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.appKey', function() {
|
||||
it('sets appKey correctly', function() {
|
||||
var config = fixture('input');
|
||||
var config = configItemFixture('input');
|
||||
var clayItem = new ClayItem(config);
|
||||
assert.strictEqual(clayItem.appKey, config.appKey);
|
||||
});
|
||||
|
||||
it('sets appKey to null if there is no appKey in the config', function() {
|
||||
var clayItem = clayItemFixture('input', {appKey: undefined});
|
||||
assert.strictEqual(clayItem.appKey, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.config', function() {
|
||||
it('sets appKey correctly', function() {
|
||||
var config = configItemFixture('input');
|
||||
var clayItem = new ClayItem(config);
|
||||
assert.strictEqual(clayItem.appKey, config.appKey);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$manipulatorTarget', function() {
|
||||
describe('.$element', function() {
|
||||
it('sets $element correctly', function() {
|
||||
var clayItem = clayItemFixture('input');
|
||||
assert.strictEqual(clayItem.$element[0].tagName, 'LABEL');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$manipulatorTarget', function() {
|
||||
it('sets the $manipulatorTarget to the root element if there are no children',
|
||||
function() {
|
||||
var clayItem = clayItemFixture('footer');
|
||||
assert.strictEqual(clayItem.$manipulatorTarget, clayItem.$element);
|
||||
});
|
||||
it('sets the $manipulatorTarget to the correct child element', function() {
|
||||
var clayItem = clayItemFixture('input');
|
||||
assert.strictEqual(clayItem.$manipulatorTarget[0].tagName, 'INPUT');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.initialize()', function() {
|
||||
it('calls component initializer with the ClayItem as context', function() {
|
||||
var initializeSpy = sinon.spy(componentRegistry.select, 'initialize');
|
||||
var clayItem = clayItemFixture('select').initialize();
|
||||
assert(initializeSpy.alwaysCalledOn(clayItem));
|
||||
initializeSpy.restore();
|
||||
});
|
||||
|
||||
it('returns itself for chaining', function() {
|
||||
var clayItem = clayItemFixture('select');
|
||||
assert.strictEqual(clayItem.initialize(), clayItem);
|
||||
});
|
||||
|
||||
it('does nothing if there is no initialize function', function() {
|
||||
assert.doesNotThrow(clayItemFixture('input').initialize);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user