add tests for components and refactor test fixtures to not register all components as a side-effect

This commit is contained in:
Keegan
2016-02-11 15:43:12 -08:00
parent 9412908636
commit ba74959919
10 changed files with 143 additions and 61 deletions
+1
View File
@@ -5,6 +5,7 @@ module.exports = {
template: require('../../templates/components/submit.tpl'),
manipulator: 'val',
defaults: {
label: '',
attributes: {}
}
};
+1
View File
@@ -6,6 +6,7 @@ module.exports = {
style: require('../../styles/clay/components/toggle.scss'),
manipulator: 'checked',
defaults: {
label: '',
attributes: {}
}
};
+6 -12
View File
@@ -12,6 +12,7 @@ var returnTo = window.returnTo || 'pebblejs://close#';
var customFn = window.customFn || function() {};
var clayComponents = window.clayComponents || {};
// Register the passed components
_.eachObj(clayComponents, function(key, component) {
ClayConfig.registerComponent(component);
});
@@ -19,18 +20,11 @@ _.eachObj(clayComponents, function(key, component) {
var $mainForm = $('#main-form');
var clayConfig = new ClayConfig(settings, config, $mainForm);
/* istanbul ignore next */ // @todo reassess how to do form submission
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
var self = this;
// add listeners here
$mainForm.on('submit', function(event) {
// Set the return URL depending on the runtime environment
location.href =
returnTo + encodeURIComponent(JSON.stringify(self.getSettings()));
event.preventDefault();
return false;
});
// add listeners here
$mainForm.on('submit', function() {
// Set the return URL depending on the runtime environment
location.href = returnTo +
encodeURIComponent(JSON.stringify(clayConfig.getSettings()));
});
// Run the custom function in the context of the ClayConfig
+10 -1
View File
@@ -190,10 +190,18 @@ function ClayConfig(settings, config, $rootContainer) {
* @param {function} component.manipulator.get - get manipulator method
* @param {{}} component.defaults - template defaults
* @param {function} [component.initialize] - method to scaffold the component
* @return {void}
* @return {boolean} - Returns true if component was registered correctly
*/
ClayConfig.registerComponent = function(component) {
var _component = _.copyObj(component);
if (componentStore[_component.name]) {
console.warn('Component: ' + _component.name +
' is already registered. If you wish to override the existing' +
' functionality, you must provide a new name');
return false;
}
if (typeof _component.manipulator === 'string') {
_component.manipulator = manipulators[component.manipulator];
@@ -216,6 +224,7 @@ ClayConfig.registerComponent = function(component) {
}
componentStore[_component.name] = _component;
return true;
};
module.exports = ClayConfig;