From 689537c7afa699533f222d99ae47c2b91be6db1f Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Fri, 28 Apr 2017 10:44:55 +0200 Subject: [PATCH 1/3] tests: remove duplicate sf-schema tests --- src/directives/sf-schema.directive.spec.js | 191 --------------------- 1 file changed, 191 deletions(-) diff --git a/src/directives/sf-schema.directive.spec.js b/src/directives/sf-schema.directive.spec.js index b662b3385..93af13372 100644 --- a/src/directives/sf-schema.directive.spec.js +++ b/src/directives/sf-schema.directive.spec.js @@ -2217,197 +2217,6 @@ describe('sf-schema.directive.js', function() { }); }); - it('should not add "has-success" class to radios field if a correct value is entered, but disableSuccessState is set on form', function () { - var field = { - name: 'radios', - property: { - type: 'boolean', - }, - form: { - key: ["field"], - type: "radios", - titleMap: [ - { - "value": false, - "name": "No way" - }, - { - "value": true, - "name": "OK" - } - ] - } - }; - - inject(function($compile, $rootScope) { - var scope = $rootScope.$new(); - scope.model = {} - scope.schema = { - type: 'object', - properties: { - field: field.property - } - }; - scope.form = [field.form]; - - var tmpl = angular.element('
'); - $compile(tmpl)(scope); - runSync(scope, tmpl); - var ngModelCtrl = tmpl.find('.field').scope().ngModel; - ngModelCtrl.$valid = true; - ngModelCtrl.$pristine = false; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-success').should.be.true; - scope.form[0].disableSuccessState = true; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-success').should.be.false; - }); - }); - - it('should not add "has-error" class to radios field if invalid value is entered, but disableErrorState is set on form', function () { - var field = { - name: 'radios', - property: { - type: 'boolean', - }, - form: { - key: ["field"], - type: "radios", - titleMap: [ - { - "value": false, - "name": "No way" - }, - { - "value": true, - "name": "OK" - } - ] - } - }; - - inject(function($compile, $rootScope) { - var scope = $rootScope.$new(); - scope.model = { - field: field.errorValue - } - scope.schema = { - type: 'object', - properties: { - field: field.property - } - }; - scope.form = [field.form]; - - var tmpl = angular.element('
'); - $compile(tmpl)(scope); - runSync(scope, tmpl); - var ngModelCtrl = tmpl.find('.field').scope().ngModel; - ngModelCtrl.$invalid = true; - ngModelCtrl.$pristine = false; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-error').should.be.true; - scope.form[0].disableErrorState = true; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-error').should.be.false; - }); - }); - - it('should not add "has-success" class to radios-inline field if a correct value is entered, but disableSuccessState is set on form', function () { - var field = { - name: 'radios', - property: { - type: 'boolean', - }, - form: { - key: ["field"], - type: "radios", - titleMap: [ - { - "value": false, - "name": "No way" - }, - { - "value": true, - "name": "OK" - } - ] - } - }; - - inject(function($compile, $rootScope) { - var scope = $rootScope.$new(); - scope.model = {} - scope.schema = { - type: 'object', - properties: { - field: field.property - } - }; - scope.form = [field.form]; - - var tmpl = angular.element('
'); - $compile(tmpl)(scope); - runSync(scope, tmpl); - var ngModelCtrl = tmpl.find('.field').scope().ngModel; - ngModelCtrl.$valid = true; - ngModelCtrl.$pristine = false; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-success').should.be.true; - scope.form[0].disableSuccessState = true; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-success').should.be.false; - }); - }); - - it('should not add "has-error" class to radios-inline field if invalid value is entered, but disableErrorState is set on form', function () { - var field = { - name: 'radios', - property: { - type: 'boolean', - }, - form: { - key: ["field"], - type: "radios", - titleMap: [ - { - "value": false, - "name": "No way" - }, - { - "value": true, - "name": "OK" - } - ] - } - }; - - inject(function($compile, $rootScope) { - var scope = $rootScope.$new(); - scope.model = { - field: field.errorValue - } - scope.schema = { - type: 'object', - properties: { - field: { type: 'boolean' } - } - }; - scope.form = [field.form]; - - var tmpl = angular.element('
'); - $compile(tmpl)(scope); - runSync(scope, tmpl); - var ngModelCtrl = tmpl.find('.field').scope().ngModel; - ngModelCtrl.$invalid = true; - ngModelCtrl.$pristine = false; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-error').should.be.true; - scope.form[0].disableErrorState = true; - $rootScope.$apply(); - tmpl.find('.field').hasClass('has-error').should.be.false; - }); - }); /* TODO it('should handle onChange for array type', function () { From 0a2075518891ee97713adf5428cc67d94cbe2bd2 Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Fri, 28 Apr 2017 10:46:14 +0200 Subject: [PATCH 2/3] tests: sf-field tests for form.key generation issue json-schema-form/angular-schema-form#870 --- src/directives/sf-field.directive.spec.js | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/directives/sf-field.directive.spec.js diff --git a/src/directives/sf-field.directive.spec.js b/src/directives/sf-field.directive.spec.js new file mode 100644 index 000000000..c31e67bf4 --- /dev/null +++ b/src/directives/sf-field.directive.spec.js @@ -0,0 +1,80 @@ +chai.should(); + +var runSync = function (scope, tmpl) { + var directiveScope = tmpl.isolateScope(); + var stub = sinon.stub(directiveScope, 'resolveReferences', function(schema, form) { + directiveScope.render(schema, form); + }); + scope.$apply(); +} + +describe('sf-field.directive.js',function() { + beforeEach(module('schemaForm')); + beforeEach( + module(function($sceProvider){ + $sceProvider.enabled(false); + }) + ); + + var keyTests = [ + { + name: 'array of objects', + targetKey: ['arrayOfObjects', 0, 'stringVal'], + schema: { + type: 'object', + properties: { + arrayOfObjects: { + type: 'array', + items: { + type: 'object', + properties: { + stringVal: { + type: 'string', + 'x-schema-form': { + htmlClass: 'targetKey' + } + } + } + } + } + } + }, + }, + + { + name: 'array of strings', + targetKey: ['arrayOfStrings', 0], + schema: { + type: 'object', + properties: { + arrayOfStrings: { + type: 'array', + items: { + type: 'string', + 'x-schema-form': { + htmlClass: 'targetKey' + } + } + } + } + } + } + ]; + + keyTests.forEach(function(keyTest) { + it('should generate correct form keys for ' + keyTest.name, function(done) { + inject(function($compile,$rootScope) { + var scope = $rootScope.$new(); + scope.model = {}; + scope.schema = keyTest.schema; + + var tmpl = angular.element('
'); + + $compile(tmpl)(scope); + runSync(scope, tmpl); + + tmpl.children().find('.targetKey').scope().form.key.should.deep.equal(keyTest.targetKey); + }); + }); + }); +}); From 45f993e8fc3bd8f0fb1f04537c19ec874bba9350 Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Fri, 28 Apr 2017 10:47:20 +0200 Subject: [PATCH 3/3] tests: use mocha reporter and enable diffs mocha reporter is better than dots + progress but especially for diff output as it is needed to see deep comparisons between arrays/objects (for example while looking at wrong keys in the sf-field.directive tests) --- karma.conf.js | 6 +++++- package.json | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index 0e9b9204f..b024a62db 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -34,7 +34,11 @@ module.exports = function(config) { // test results reporter to use // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' - reporters: ['dots','progress','coverage','growler'], + reporters: ['mocha','coverage','growler'], + + mochaReporter: { + showDiff: true + }, preprocessors: { 'src/**/*.js': ['coverage'] diff --git a/package.json b/package.json index 91f48cc24..eacf40b8f 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "babel-polyfill": "^6.16.0", "babel-preset-es2015": "^6.18.0", "chai": "^3.5.0", + "diff": "^3.2.0", "html-webpack-externals-plugin": "^2.1.2", "karma": "^1.3.0", "karma-babel-preprocessor": "^6.0.1", @@ -58,6 +59,7 @@ "karma-coverage": "^1.1.1", "karma-growler-reporter": "0.0.1", "karma-mocha": "^1.3.0", + "karma-mocha-reporter": "^2.2.3", "karma-phantomjs-launcher": "^1.0.2", "karma-webpack": "^1.8.0", "mocha": "^3.2.0",