|
| 1 | +'use strict'; |
| 2 | + |
1 | 3 | // Tests for the friends directive
|
2 | 4 |
|
3 | 5 | 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); |
18 | 57 | });
|
19 | 58 |
|
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); |
23 | 64 | });
|
24 | 65 |
|
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 | + }); |
89 | 77 |
|
| 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/); |
90 | 88 | });
|
91 | 89 |
|
| 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 | + |
92 | 105 | });
|
93 | 106 |
|
0 commit comments