Skip to content

Commit ba709f0

Browse files
committed
Spec updates
1 parent bd18295 commit ba709f0

7 files changed

+123
-54
lines changed

src/directives/schema-validate.directive.spec.js

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,33 @@ var runSync = function (scope, tmpl) {
66
directiveScope.render(schema, form);
77
});
88
scope.$apply();
9-
}
9+
};
1010

11-
describe('directive', function() {
11+
describe('schema-validate.directive.js', function() {
12+
var exampleSchema;
1213
beforeEach(module('schemaForm'));
1314
beforeEach(
1415
module(function($sceProvider) {
1516
$sceProvider.enabled(false);
17+
exampleSchema = {
18+
"type": "object",
19+
"title": "Person",
20+
"properties": {
21+
"name": {
22+
"title": "Name",
23+
"type": "string",
24+
"minLength": 10
25+
},
26+
"email": {
27+
"type": "string",
28+
"maxLength": 255,
29+
"format": "email",
30+
"email": true
31+
}
32+
}
33+
};
1634
})
35+
1736
);
1837

1938
tv4.defineError('EMAIL', 10001, 'Invalid email address');
@@ -29,98 +48,82 @@ describe('directive', function() {
2948
return null;
3049
});
3150

32-
exampleSchema = {
33-
"type": "object",
34-
"title": "Person",
35-
"properties": {
36-
"name": {
37-
"title": "Name",
38-
"type": "string",
39-
"minLength": 10
40-
},
41-
"email": {
42-
"type": "string",
43-
"maxLength": 255,
44-
"format": "email",
45-
"email": true
46-
}
47-
}
48-
};
4951

5052
it('should validate the form on event [ノಠ益ಠ]ノ彡┻━┻', function() {
5153

52-
tmpl = angular.element(
53-
'<div>' +
54-
'<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>' +
55-
'<input class="validate" type="button" ng-click="validate_all()" />' +
56-
'</div>'
57-
);
54+
tmpl = angular.element('<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>');
5855

5956
inject(function($compile,$rootScope) {
6057
var scope = $rootScope.$new();
61-
scope.obj = { "name": "Json" };
58+
scope.obj = { "name": "Freddy" };
6259

6360
scope.schema = exampleSchema;
6461

65-
scope.form = ["*"];
62+
scope.form = [
63+
"*",
64+
{
65+
"type": "button",
66+
"style": "validate",
67+
"onClick": "validate_all()"
68+
}
69+
];
6670

6771
scope.validate_all = function() {
6872
scope.$broadcast('schemaFormValidate');
6973
};
7074

7175
$compile(tmpl)(scope);
72-
tmpl.find('form').each(function() {
73-
runSync(scope, $(this));
74-
});
76+
runSync(scope, tmpl);
7577

76-
var form = tmpl.find('form').eq(0).controller('form');
78+
var form = tmpl.eq(0).controller('form');
7779

7880
form.$valid.should.be.true;
7981
scope.validate_all.should.not.have.beenCalled;
80-
tmpl.find('input.validate').click();
82+
tmpl.find('button.validate').click();
8183
scope.validate_all.should.have.beenCalledOnce;
8284
form.$valid.should.be.false;
83-
8485
});
8586
});
8687

8788
it('should process custom tv4 errors', function() {
8889

89-
tmpl = angular.element(
90-
'<div>' +
91-
'<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>' +
92-
'<input class="validate" type="button" ng-click="validate_all()" />{{obj}}' +
93-
'</div>'
94-
);
90+
tmpl = angular.element('<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>');
9591

9692
inject(function($compile,$rootScope) {
9793
var scope = $rootScope.$new();
9894
scope.obj = { "email": "NULL" };
9995

10096
scope.schema = exampleSchema;
10197

102-
scope.form = [{
103-
"key": "email",
104-
"placeholder": "Enter contact email",
105-
"feedback": false
106-
}];
98+
scope.form = [
99+
{
100+
"key": "email",
101+
"placeholder": "Enter contact email",
102+
"feedback": false
103+
},
104+
{
105+
"type": "button",
106+
"style": "validate",
107+
"onClick": "validate_all()"
108+
}
109+
];
107110

108111
scope.validate_all = function() {
109112
scope.$broadcast('schemaFormValidate');
110113
};
111114

112115
$compile(tmpl)(scope);
113-
tmpl.find('form').each(function() {
114-
runSync(scope, $(this));
115-
});
116+
runSync(scope, tmpl);
116117

117-
var form = tmpl.find('form').eq(0).controller('form');
118+
var form = tmpl.eq(0).controller('form');
118119

119120
form.$valid.should.be.true;
120121
scope.validate_all.should.not.have.beenCalled;
121-
tmpl.find('input.validate').click();
122+
angular.element(tmpl.find('#testform-email')).val('invalid').trigger('input');
123+
tmpl.find('button.validate').click();
122124
scope.validate_all.should.have.beenCalledOnce;
123125
form.$valid.should.be.false;
126+
form.$error['tv4-10001'].should.be.false;
124127
});
125128
});
126129

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
chai.should();
2+
3+
var runSync = function (scope, tmpl) {
4+
var directiveScope = tmpl.isolateScope();
5+
var stub = sinon.stub(directiveScope, 'resolveReferences', function(schema, form) {
6+
directiveScope.render(schema, form);
7+
});
8+
scope.$apply();
9+
}
10+
11+
describe('sf-array.directive.js', function() {
12+
var exampleSchema;
13+
beforeEach(module('schemaForm'));
14+
beforeEach(
15+
module(function($sceProvider) {
16+
$sceProvider.enabled(false);
17+
18+
exampleSchema = {
19+
"type": "object",
20+
"properties": {
21+
"names": {
22+
"type": "array",
23+
"description": "foobar",
24+
"items": {
25+
"title": "Name",
26+
"type": "string",
27+
"default": 6
28+
}
29+
}
30+
}
31+
};
32+
})
33+
);
34+
35+
it('should not throw needless errors on validate [ノಠ益ಠ]ノ彡┻━┻', function(done) {
36+
37+
tmpl = angular.element('<form name="testform" sf-schema="schema" sf-form="form" sf-model="model" json="{{model | json}}"></form>');
38+
39+
inject(function($compile, $rootScope) {
40+
var scope = $rootScope.$new();
41+
scope.model = {};
42+
43+
scope.schema = exampleSchema;
44+
45+
scope.form = ["*"];
46+
47+
$compile(tmpl)(scope);
48+
runSync(scope, tmpl);
49+
50+
tmpl.find('div.help-block').text().should.equal('foobar');
51+
52+
var add = tmpl.find('button').eq(1);
53+
add.click();
54+
55+
$rootScope.$apply();
56+
57+
setTimeout(function() {
58+
var errors = tmpl.find('.help-block');
59+
errors.text().should.equal('foobar');
60+
done();
61+
}, 0)
62+
//tmpl.$valid.should.be.true;
63+
64+
});
65+
});
66+
});

src/directives/sf-message.directive.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var runSync = function (scope, tmpl) {
88
scope.$apply();
99
}
1010

11-
describe('directive',function() {
11+
describe('sf-message.directive.js',function() {
1212
beforeEach(module('schemaForm'));
1313
beforeEach(
1414
module(function($sceProvider){

src/directives/sf-schema.directive.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var runSync = function (scope, tmpl) {
88
scope.$apply();
99
}
1010

11-
describe('directive', function() {
11+
describe('sf-schema.directive.js', function() {
1212
beforeEach(module('schemaForm'));
1313
beforeEach(
1414
//We don't need no sanitation. We don't need no thought control.

src/services/schema-form-decorators.provider.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
chai.should();
22

3-
describe('schemaFormDecorators', function() {
3+
describe('schema-form-decorators.provider.js', function() {
44
beforeEach(module('schemaForm'));
55

66
// describe('#legacy #createDecorator', function() {

src/services/schema-form.provider.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
chai.should();
22

3-
describe('schemaForm', function() {
3+
describe('schema-form.provider.js', function() {
44
beforeEach(module('schemaForm'));
55
describe('#defaults()', function() {
66
it('should generate default form def from a schema', function() {

src/services/sf-error-message.provider.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
chai.should();
22

3-
describe('schemaFormServices', function() {
3+
describe('sf-error-message.provider.js', function() {
44
beforeEach(module('schemaForm'));
55

66
describe('#sfErrorMessage', function() {

0 commit comments

Comments
 (0)