Skip to content

Commit dce84a7

Browse files
committed
Midway tests under jshint
1 parent e9bbc7c commit dce84a7

9 files changed

+882
-387
lines changed

.jshintrc

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"moment": false,
4444

4545
/* jasmine / karma */
46+
"xit": false,
47+
"xdescribe": false,
4648
"it": false,
4749
"iit": false,
4850
"describe": false,

Gruntfile.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/midway/conditionalsSpec.js

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
1-
describe('Condition display', function() {
1+
'use strict';
22

3-
var $httpBackend;
3+
describe('Condition display', function () {
44

5-
beforeEach(function () {
6-
angular.mock.module('formsAngular');
7-
});
5+
var $httpBackend;
86

9-
afterEach(function () {
10-
$httpBackend.verifyNoOutstandingExpectation();
11-
$httpBackend.verifyNoOutstandingRequest();
12-
});
7+
beforeEach(function () {
8+
angular.mock.module('formsAngular');
9+
});
10+
11+
afterEach(function () {
12+
$httpBackend.verifyNoOutstandingExpectation();
13+
$httpBackend.verifyNoOutstandingRequest();
14+
});
1315

14-
describe('fixed value', function () {
16+
describe('fixed value', function () {
1517

16-
var scope, ctrl;
18+
var scope, ctrl;
1719

18-
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location) {
19-
$httpBackend = _$httpBackend_;
20-
$httpBackend.whenGET('/api/schema/collection').respond({
21-
"name": {"instance": "String"},
22-
"hide_me": {"instance": "String", "options": {"form": {"showIf": {"lhs": 0, "comp": "eq", "rhs": 1}}}},
23-
"show_me": {"instance": "String", "options": {"form": {"showIf": {"lhs": 1, "comp": "eq", "rhs": 1}}}}
24-
});
25-
scope = $rootScope.$new();
26-
$location.$$path = '/collection/new';
27-
ctrl = $controller("BaseCtrl", {$scope: scope});
28-
$httpBackend.flush();
29-
}));
20+
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location) {
21+
$httpBackend = _$httpBackend_;
22+
$httpBackend.whenGET('/api/schema/collection').respond({
23+
'name': {'instance': 'String'},
24+
'hide_me': {'instance': 'String', 'options': {'form': {'showIf': {'lhs': 0, 'comp': 'eq', 'rhs': 1}}}},
25+
'show_me': {'instance': 'String', 'options': {'form': {'showIf': {'lhs': 1, 'comp': 'eq', 'rhs': 1}}}}
26+
});
27+
scope = $rootScope.$new();
28+
$location.$$path = '/collection/new';
29+
ctrl = $controller('BaseCtrl', {$scope: scope});
30+
$httpBackend.flush();
31+
}));
3032

31-
it('can hide fields', function () {
32-
expect(scope.formSchema.length).toBe(2);
33-
expect(scope.formSchema[0].name).toBe('name');
34-
expect(scope.formSchema[1].name).toBe('show_me');
35-
});
33+
it('can hide fields', function () {
34+
expect(scope.formSchema.length).toBe(2);
35+
expect(scope.formSchema[0].name).toBe('name');
36+
expect(scope.formSchema[1].name).toBe('show_me');
3637
});
38+
});
3739

38-
xdescribe('shows simple variable value field', function () {
40+
xdescribe('shows simple variable value field', function () {
3941
// Can't get this to work - the element isn't there in updateDataDependentDisplay
40-
var scope, ctrl;
42+
var scope, ctrl, elm;
4143

42-
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location, $compile) {
43-
$httpBackend = _$httpBackend_;
44-
$httpBackend.whenGET('/api/schema/collection').respond({
45-
"name": {"instance": "String"},
46-
"change_me": {"instance": "String", "options": {"form": {"showIf": {"lhs": "$name", "comp": "ne", "rhs": "hide"}}}}
47-
});
48-
scope = $rootScope.$new();
49-
$location.$$path = '/collection/new';
50-
ctrl = $controller("BaseCtrl", {$scope: scope});
51-
$httpBackend.flush();
52-
53-
scope.record.name = 'hide';
54-
elm = angular.element(
55-
'<form name="myForm" class="form-horizontal compact">' +
56-
'<form-input schema="formSchema"></form-input>' +
57-
'</form>');
58-
$compile(elm)(scope);
59-
scope.$digest();
60-
}));
61-
62-
it('can hide fields', function () {
63-
expect(elm.find('#cg_f_change_me')).toHaveClass('cond-hide');
64-
});
44+
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location, $compile) {
45+
$httpBackend = _$httpBackend_;
46+
$httpBackend.whenGET('/api/schema/collection').respond({
47+
'name': {'instance': 'String'},
48+
'change_me': {'instance': 'String', 'options': {'form': {'showIf': {'lhs': '$name', 'comp': 'ne', 'rhs': 'hide'}}}}
49+
});
50+
scope = $rootScope.$new();
51+
$location.$$path = '/collection/new';
52+
ctrl = $controller('BaseCtrl', {$scope: scope});
53+
$httpBackend.flush();
54+
scope.record.name = 'hide';
55+
elm = angular.element(
56+
'<form name="myForm" class="form-horizontal compact">' +
57+
'<form-input schema="formSchema"></form-input>' +
58+
'</form>');
59+
$compile(elm)(scope);
60+
scope.$digest();
61+
}));
6562

63+
it('can hide fields', function () {
64+
expect(elm.find('#cg_f_change_me')).toHaveClass('cond-hide');
6665
});
6766

67+
});
68+
6869
});
6970

test/midway/directiveSpec.js

+94-81
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,106 @@
1+
'use strict';
2+
13
// Tests for the friends directive
24

35
describe('directive with form', function () {
4-
var elm, scope, ctrl, $httpBackend,
5-
schema = {
6-
"surname":{"enumValues":[],"regExp":null,"path":"surname","instance":"String","validators":[[null,"Path `{PATH}` is required.","required"]],"setters":[],"getters":[],"options":{"required":true,"list":{}},"_index":null,"isRequired":true,"$conditionalHandlers":{}},
7-
"forename":{"enumValues":[],"regExp":null,"path":"forename","instance":"String","validators":[],"setters":[],"getters":[],"options":{"list":true},"_index":null,"$conditionalHandlers":{}},
8-
"friendList":{"schema":{"friend":{"path":"friend","instance":"ObjectID","validators":[],"setters":[],"getters":[],"options":{"ref":"a_unadorned_mongoose","form":{"select2":{"fngAjax":true}}},"_index":null,"$conditionalHandlers":{}},"type":{"enumValues":["best friend","partner","colleague","acquaintance","other"],"regExp":null,"path":"type","instance":"String","validators":[[null,"`{VALUE}` is not a valid enum value for path `{PATH}`.","enum"]],"setters":[],"getters":[],"options":{"enum":["best friend","partner","colleague","acquaintance","other"]},"_index":null,"$conditionalHandlers":{}}},"options":{"form":{"directive":"friends"}}},
9-
"_id":{"path":"_id","instance":"ObjectID","validators":[],"setters":[null],"getters":[],"options":{"auto":true},"_index":null,"$conditionalHandlers":{}}},
10-
oneFriend = {"_id":"123","surname":"Fitzgerald","forename":"Patrick","friendList":[{"friend":"666a6075b320153869b17599","type":"colleague"}]};
11-
12-
// load the form code
13-
beforeEach(function() {
14-
angular.mock.module('formsAngular');
15-
angular.mock.module('myDemoApp');
16-
angular.mock.module('demo/template/friends.html');
17-
angular.mock.module('template/form-button-bs2.html');
6+
var elm, scope, ctrl, $httpBackend,
7+
schema = {
8+
'surname': {'path': 'surname', 'instance': 'String', 'validators': [
9+
[null, 'Path `{PATH}` is required.', 'required']
10+
], 'options': {'required': true, 'list': {}}, '_index': null, 'isRequired': true, '$conditionalHandlers': {}},
11+
'forename': {'path': 'forename', 'instance': 'String', 'options': {'list': true}, '_index': null, '$conditionalHandlers': {}},
12+
'friendList': {'schema': {'friend': {'path': 'friend', 'instance': 'ObjectID', 'options': {'ref': 'a_unadorned_mongoose', 'form': {
13+
'select2': {'fngAjax': true}
14+
}}, '_index': null, '$conditionalHandlers': {}}, 'type': {'enumValues': ['best friend', 'partner', 'colleague', 'acquaintance', 'other'], 'path': 'type', 'instance': 'String', 'validators': [
15+
[null, '`{VALUE}` is not a valid enum value for path `{PATH}`.', 'enum']
16+
], 'options': {'enum': ['best friend', 'partner', 'colleague', 'acquaintance', 'other']}, '_index': null, '$conditionalHandlers': {}}}, 'options': {'form': {'directive': 'friends'}}},
17+
'_id': {'path': '_id', 'instance': 'ObjectID', 'setters': [null], 'options': {'auto': true}, '_index': null, '$conditionalHandlers': {}}
18+
},
19+
oneFriend = {'_id': '123', 'surname': 'Fitzgerald', 'forename': 'Patrick', 'friendList': [
20+
{'friend': '666a6075b320153869b17599', 'type': 'colleague'}
21+
]};
22+
23+
// load the form code
24+
beforeEach(function () {
25+
angular.mock.module('formsAngular');
26+
angular.mock.module('myDemoApp');
27+
angular.mock.module('demo/template/friends.html');
28+
angular.mock.module('template/form-button-bs2.html');
29+
});
30+
31+
afterEach(function () {
32+
$httpBackend.verifyNoOutstandingExpectation();
33+
$httpBackend.verifyNoOutstandingRequest();
34+
});
35+
36+
describe('basic friends form', function () {
37+
38+
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location, $compile) {
39+
$httpBackend = _$httpBackend_;
40+
$httpBackend.whenGET('/api/schema/collection').respond(schema);
41+
$httpBackend.whenGET('/api/collection/123').respond(oneFriend);
42+
elm = angular.element('<div><div form-buttons></div><form-input schema="formSchema"></form-input></div>');
43+
scope = $rootScope.$new();
44+
$location.$$path = '/collection/123/edit';
45+
ctrl = $controller('BaseCtrl', {$scope: scope});
46+
$httpBackend.flush();
47+
$compile(elm)(scope);
48+
scope.$digest();
49+
}));
50+
51+
it('disables save button until a change is made', function () {
52+
expect(scope.isSaveDisabled()).toEqual(true);
53+
});
54+
55+
it('disables cancel button until a change is made', function () {
56+
expect(scope.isCancelDisabled()).toEqual(true);
1857
});
1958

20-
afterEach(function () {
21-
$httpBackend.verifyNoOutstandingExpectation();
22-
$httpBackend.verifyNoOutstandingRequest();
59+
it('enables save button when a change is made', function () {
60+
var elem = angular.element(elm.find('input:first')[0]);
61+
elem.val('Voronin');
62+
elem.change();
63+
expect(scope.isSaveDisabled()).toEqual(false);
2364
});
2465

25-
describe('basic friends form', function () {
26-
27-
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, $location, $compile) {
28-
$httpBackend = _$httpBackend_;
29-
$httpBackend.whenGET('/api/schema/collection').respond(schema);
30-
$httpBackend.whenGET('/api/collection/123').respond(oneFriend);
31-
elm = angular.element('<div><div form-buttons></div><form-input schema="formSchema"></form-input></div>');
32-
scope = $rootScope.$new();
33-
$location.$$path = '/collection/123/edit';
34-
ctrl = $controller("BaseCtrl", {$scope: scope});
35-
$httpBackend.flush();
36-
$compile(elm)(scope);
37-
scope.$digest();
38-
}));
39-
40-
it('disables save button until a change is made', function () {
41-
expect(scope.isSaveDisabled()).toEqual(true);
42-
});
43-
44-
it('disables cancel button until a change is made', function () {
45-
expect(scope.isCancelDisabled()).toEqual(true);
46-
});
47-
48-
it('enables save button when a change is made', function () {
49-
var elem = angular.element(elm.find('input:first')[0]);
50-
elem.val('Voronin');
51-
elem.change();
52-
expect(scope.isSaveDisabled()).toEqual(false);
53-
});
54-
55-
it('enables cancel button when a change is made', function () {
56-
var elem = angular.element(elm.find('input:first')[0]);
57-
elem.val('Voronin');
58-
elem.change();
59-
expect(scope.isCancelDisabled()).toEqual(false);
60-
});
61-
62-
it('shows the friend type', function() {
63-
var elem = angular.element(elm.find('.friends:first')[0]);
64-
expect(elem.text()).toMatch(/colleague/);
65-
});
66-
67-
it('shows the friend name', function() {
68-
$httpBackend.whenGET('/api/a_unadorned_mongoose/666a6075b320153869b17599').respond({"_id":"666a6075b320153869b17599","surname":"TestPerson2","forename":"Andrew","weight":142,"eyeColour":"Brown","accepted":true});
69-
var friend = scope.record.friendList[0];
70-
scope.frdShowDetails(friend);
71-
$httpBackend.flush();
72-
var elem = angular.element(elm.find('.friends-head')[0]);
73-
expect(elem.text()).toMatch(/Andrew/);
74-
expect(elem.text()).toMatch(/TestPerson2/);
75-
});
76-
77-
xit('disables save friend button until a change is made', function() {
78-
scope.frdShowAddForm();
79-
expect(scope.frdIsFriendSaveDisabled()).toEqual(true);
80-
});
81-
82-
xit('enables save friend button when a change is made', function() {
83-
scope.frdShowAddForm();
84-
var elem = angular.element(elm.find('#newFriendForm input:last')[0]);
85-
elem.val('New comment');
86-
elem.change();
87-
expect(scope.frdIsFriendSaveDisabled()).toEqual(false);
88-
})
66+
it('enables cancel button when a change is made', function () {
67+
var elem = angular.element(elm.find('input:first')[0]);
68+
elem.val('Voronin');
69+
elem.change();
70+
expect(scope.isCancelDisabled()).toEqual(false);
71+
});
72+
73+
it('shows the friend type', function () {
74+
var elem = angular.element(elm.find('.friends:first')[0]);
75+
expect(elem.text()).toMatch(/colleague/);
76+
});
8977

78+
it('shows the friend name', function () {
79+
$httpBackend.whenGET('/api/a_unadorned_mongoose/666a6075b320153869b17599').respond(
80+
{'_id': '666a6075b320153869b17599', 'surname': 'TestPerson2', 'forename': 'Andrew', 'weight': 142, 'eyeColour': 'Brown', 'accepted': true}
81+
);
82+
var friend = scope.record.friendList[0];
83+
scope.frdShowDetails(friend);
84+
$httpBackend.flush();
85+
var elem = angular.element(elm.find('.friends-head')[0]);
86+
expect(elem.text()).toMatch(/Andrew/);
87+
expect(elem.text()).toMatch(/TestPerson2/);
9088
});
9189

90+
xit('disables save friend button until a change is made', function () {
91+
scope.frdShowAddForm();
92+
expect(scope.frdIsFriendSaveDisabled()).toEqual(true);
93+
});
94+
95+
xit('enables save friend button when a change is made', function () {
96+
scope.frdShowAddForm();
97+
var elem = angular.element(elm.find('#newFriendForm input:last')[0]);
98+
elem.val('New comment');
99+
elem.change();
100+
expect(scope.frdIsFriendSaveDisabled()).toEqual(false);
101+
});
102+
103+
});
104+
92105
});
93106

0 commit comments

Comments
 (0)