Improved form test
diff --git a/views/ngXosLib/karma.conf.js b/views/ngXosLib/karma.conf.js
index 0a78683..39c2d0a 100644
--- a/views/ngXosLib/karma.conf.js
+++ b/views/ngXosLib/karma.conf.js
@@ -12,6 +12,7 @@
});
var files = bowerComponents.concat([
+ 'node_modules/babel-polyfill/dist/polyfill.js',
'xosHelpers/src/**/*.module.js',
'xosHelpers/src/**/*.js',
'xosHelpers/spec/**/*.test.js'
diff --git a/views/ngXosLib/package.json b/views/ngXosLib/package.json
index 9e8906c..11183a6 100644
--- a/views/ngXosLib/package.json
+++ b/views/ngXosLib/package.json
@@ -24,6 +24,7 @@
"swagger-js-codegen": "^1.1.5"
},
"devDependencies": {
+ "babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"browser-sync": "^2.12.3",
"concat": "^2.0.0",
diff --git a/views/ngXosLib/xosHelpers/spec/ui/form.test.js b/views/ngXosLib/xosHelpers/spec/ui/form.test.js
index 4cd3fec..4b33a5a 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/form.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/form.test.js
@@ -82,14 +82,14 @@
}));
describe('the _getFieldFormat method', () => {
- xit('should return string', () => {
+ it('should return string', () => {
expect(service._getFieldFormat('string')).toEqual('string');
});
it('should return number', () => {
expect(service._getFieldFormat(1)).toEqual('number');
expect(service._getFieldFormat('1')).toEqual('number');
});
- xit('should return boolean', () => {
+ it('should return boolean', () => {
expect(service._getFieldFormat(false)).toEqual('boolean');
expect(service._getFieldFormat(true)).toEqual('boolean');
});
@@ -101,16 +101,16 @@
});
});
- xit('should convert the fields array in an empty form object', () => {
+ it('should convert the fields array in an empty form object', () => {
expect(service.parseModelField(fields)).toEqual(modelField);
});
- xit('should combine modelField and customField in a form object', () => {
+ it('should combine modelField and customField in a form object', () => {
expect(service.buildFormStructure(modelField, customField, model)).toEqual(formObject);
});
});
- xdescribe('The xos-form component', () => {
+ describe('The xos-form component', () => {
let element, scope, isolatedScope;
@@ -153,13 +153,11 @@
class: 'success'
}
],
- fields: [
- {
- first_name: {
- label: 'Custom Label'
- }
+ fields: {
+ first_name: {
+ label: 'Custom Label'
}
- ]
+ }
};
scope.model = {
@@ -190,7 +188,7 @@
});
it('should render 8 field', () => {
- expect(isolatedScope.formField.length).toEqual(8);
+ expect(Object.keys(isolatedScope.formField).length).toEqual(8);
var field = element[0].getElementsByTagName('input');
expect(field.length).toEqual(8);
});
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form.component.js b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form.component.js
index f33c639..cd5e1ca 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form.component.js
@@ -63,7 +63,7 @@
template: `
<ng-form name="vm.config.formName || 'form'">
<div class="form-group" ng-repeat="field in vm.formField">
- <label>{{vm.formatLabel(field.label)}}</label>
+ <label>{{field.label}}</label>
<input type="text" name="" class="form-control" ng-model="vm.ngModel[field]"/>
</div>
<div class="form-group" ng-if="vm.config.actions">
@@ -80,7 +80,7 @@
`,
bindToController: true,
controllerAs: 'vm',
- controller: function($scope, $log, _, LabelFormatter, XosFormHelpers){
+ controller: function($scope, $log, _, XosFormHelpers){
if(!this.config){
throw new Error('[xosForm] Please provide a configuration via the "config" attribute');
@@ -90,8 +90,6 @@
throw new Error('[xosForm] Please provide an action list in the configuration');
}
- this.formatLabel = LabelFormatter.format;
-
this.excludedField = ['id', 'validators', 'created', 'updated', 'deleted', 'backend_status'];
if(this.config && this.config.exclude){
this.excludedField = this.excludedField.concat(this.config.exclude);
@@ -103,7 +101,7 @@
if(!model){
return;
}
- this.formField = XosFormHelpers.buildFormStructure(_.difference(Object.keys(model), this.excludedField));
+ this.formField = XosFormHelpers.buildFormStructure(XosFormHelpers.parseModelField(_.difference(Object.keys(model), this.excludedField)), this.config.fields, model);
});
}
@@ -114,7 +112,7 @@
this._getFieldFormat = (value) => {
// check if is date
- if (_.isDate(value)){
+ if (_.isDate(value) || (!Number.isNaN(Date.parse(value)) && Date.parse(value) > 0)){
return 'date';
}