From 6de42ebe05b2d66b0939cefce3cadc733cf99b41 Mon Sep 17 00:00:00 2001 From: David Jensen Date: Fri, 18 Sep 2015 09:55:59 +0200 Subject: [PATCH] Fix for radios-inline tests --- test/directives/schema-form-test.js | 119 +++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 21 deletions(-) diff --git a/test/directives/schema-form-test.js b/test/directives/schema-form-test.js index 144b95a90..3f3aaafc7 100644 --- a/test/directives/schema-form-test.js +++ b/test/directives/schema-form-test.js @@ -1943,26 +1943,6 @@ describe('directive',function(){ ] } }, - { - name: 'radios inline', - property: { - type: 'boolean', - }, - form: { - key: ["field"], - type: "radios-inline", - titleMap: [ - { - "value": false, - "name": "No way" - }, - { - "value": true, - "name": "OK" - } - ] - } - }, { name: 'select', property: { @@ -2115,7 +2095,7 @@ describe('directive',function(){ ] } }; - + inject(function($compile, $rootScope){ var scope = $rootScope.$new(); scope.model = { @@ -2143,6 +2123,103 @@ describe('directive',function(){ }); }); + 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); + $rootScope.$apply(); + var ngModelCtrl = tmpl.children().eq(0).children().eq(0).scope().ngModel; + ngModelCtrl.$valid = true; + ngModelCtrl.$pristine = false; + $rootScope.$apply(); + tmpl.children().eq(0).children().eq(0).hasClass('has-success').should.be.true; + scope.form[0].disableSuccessState = true; + $rootScope.$apply(); + tmpl.children().eq(0).children().eq(0).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: field.property + } + }; + scope.form = [field.form]; + + var tmpl = angular.element('
'); + $compile(tmpl)(scope); + $rootScope.$apply(); + var ngModelCtrl = tmpl.children().eq(0).children().eq(0).scope().ngModel; + ngModelCtrl.$invalid = true; + ngModelCtrl.$pristine = false; + $rootScope.$apply(); + tmpl.children().eq(0).children().eq(0).hasClass('has-error').should.be.true; + scope.form[0].disableErrorState = true; + $rootScope.$apply(); + tmpl.children().eq(0).children().eq(0).hasClass('has-error').should.be.false; + }); + });