Skip to content

Commit

Permalink
Fix for radios-inline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlgj committed Sep 18, 2015
1 parent 7d36108 commit 6de42eb
Showing 1 changed file with 98 additions and 21 deletions.
119 changes: 98 additions & 21 deletions test/directives/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -2115,7 +2095,7 @@ describe('directive',function(){
]
}
};

inject(function($compile, $rootScope){
var scope = $rootScope.$new();
scope.model = {
Expand Down Expand Up @@ -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('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$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('<form name="theForm" sf-schema="schema" sf-form="form" sf-model="model"></form>');
$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;
});
});



Expand Down

0 comments on commit 6de42eb

Please sign in to comment.