|
2 | 2 | describe('External Links Data Directive', function() {
|
3 | 3 | var scope;
|
4 | 4 | var element;
|
| 5 | + var toasterSvc, extLinkSvc; |
| 6 | + var mockLinkedAccounts = [ |
| 7 | + { |
| 8 | + provider: 'github', |
| 9 | + data: { |
| 10 | + handle: "github-handle", |
| 11 | + followers: 1, |
| 12 | + publicRepos: 1 |
| 13 | + } |
| 14 | + }, |
| 15 | + { provider: 'stackoverflow', |
| 16 | + data: { |
| 17 | + handle: 'so-handle', |
| 18 | + reputation: 2, |
| 19 | + answers: 2 |
| 20 | + } |
| 21 | + }, |
| 22 | + { |
| 23 | + provider: 'behance', |
| 24 | + data: { |
| 25 | + name: 'behance name', |
| 26 | + projectViews: 3, |
| 27 | + projectAppreciations: 3 |
| 28 | + } |
| 29 | + }, |
| 30 | + { |
| 31 | + provider: 'dribbble', |
| 32 | + data: { |
| 33 | + handle: 'dribbble-handle', |
| 34 | + followers: 4, |
| 35 | + likes: 4 |
| 36 | + } |
| 37 | + }, |
| 38 | + { |
| 39 | + provider: 'bitbucket', |
| 40 | + data: { |
| 41 | + username: 'bitbucket-username', |
| 42 | + followers: 5, |
| 43 | + repositories: 5 |
| 44 | + } |
| 45 | + }, |
| 46 | + { |
| 47 | + provider: 'twitter', |
| 48 | + data: { |
| 49 | + handle: 'twitter-handle', |
| 50 | + noOfTweets: 6, |
| 51 | + followers: 6 |
| 52 | + } |
| 53 | + }, |
| 54 | + { |
| 55 | + provider: 'linkedin', |
| 56 | + data: { |
| 57 | + status: 'pending' |
| 58 | + } |
| 59 | + }, |
| 60 | + { |
| 61 | + provider: 'weblink', |
| 62 | + key: 'somekey' |
| 63 | + } |
| 64 | + ]; |
5 | 65 |
|
6 | 66 | beforeEach(function() {
|
7 | 67 | bard.appModule('topcoder');
|
8 |
| - bard.inject(this, '$compile', '$rootScope'); |
| 68 | + bard.inject(this, '$compile', '$rootScope', 'toaster', 'ExternalWebLinksService', '$q'); |
9 | 69 | scope = $rootScope.$new();
|
| 70 | + |
| 71 | + extLinkSvc = ExternalWebLinksService; |
| 72 | + |
| 73 | + sinon.stub(extLinkSvc, 'removeLink', function(handle, key) { |
| 74 | + var $deferred = $q.defer(); |
| 75 | + if (key === 'throwNotExistsError') { |
| 76 | + $deferred.reject({ |
| 77 | + status: 'WEBLINK_NOT_EXIST', |
| 78 | + msg: 'profile not exists' |
| 79 | + }); |
| 80 | + } else if(key === 'throwFatalError') { |
| 81 | + $deferred.reject({ |
| 82 | + status: 'FATAL_ERROR', |
| 83 | + msg: 'fatal error' |
| 84 | + }); |
| 85 | + } else { |
| 86 | + $deferred.resolve({ |
| 87 | + status: 'SUCCESS' |
| 88 | + }); |
| 89 | + } |
| 90 | + return $deferred.promise; |
| 91 | + }); |
| 92 | + |
| 93 | + toasterSvc = toaster; |
| 94 | + bard.mockService(toaster, { |
| 95 | + pop: $q.when(true), |
| 96 | + default: $q.when(true) |
| 97 | + }); |
10 | 98 | });
|
11 | 99 |
|
12 | 100 | bard.verifyNoOutstandingHttpRequests();
|
13 | 101 |
|
14 | 102 | describe('Linked external accounts', function() {
|
15 |
| - var linkedAccounts = [ |
16 |
| - { |
17 |
| - provider: 'github', |
18 |
| - data: { |
19 |
| - handle: "github-handle", |
20 |
| - followers: 1, |
21 |
| - publicRepos: 1 |
22 |
| - } |
23 |
| - }, |
24 |
| - { provider: 'stackoverflow', |
25 |
| - data: { |
26 |
| - handle: 'so-handle', |
27 |
| - reputation: 2, |
28 |
| - answers: 2 |
29 |
| - } |
30 |
| - }, |
31 |
| - { |
32 |
| - provider: 'behance', |
33 |
| - data: { |
34 |
| - name: 'behance name', |
35 |
| - projectViews: 3, |
36 |
| - projectAppreciations: 3 |
37 |
| - } |
38 |
| - }, |
39 |
| - { |
40 |
| - provider: 'dribbble', |
41 |
| - data: { |
42 |
| - handle: 'dribbble-handle', |
43 |
| - followers: 4, |
44 |
| - likes: 4 |
45 |
| - } |
46 |
| - }, |
47 |
| - { |
48 |
| - provider: 'bitbucket', |
49 |
| - data: { |
50 |
| - username: 'bitbucket-username', |
51 |
| - followers: 5, |
52 |
| - repositories: 5 |
53 |
| - } |
54 |
| - }, |
55 |
| - { |
56 |
| - provider: 'twitter', |
57 |
| - data: { |
58 |
| - handle: 'twitter-handle', |
59 |
| - noOfTweets: 6, |
60 |
| - followers: 6 |
61 |
| - } |
62 |
| - }, |
63 |
| - { |
64 |
| - provider: 'linkedin', |
65 |
| - data: { |
66 |
| - status: 'pending' |
67 |
| - } |
68 |
| - } |
69 |
| - ]; |
| 103 | + var linkedAccounts = null; |
70 | 104 | var externalLinksData;
|
71 | 105 |
|
72 | 106 | beforeEach(function() {
|
| 107 | + linkedAccounts = angular.copy(mockLinkedAccounts); |
73 | 108 | scope.linkedAccounts = linkedAccounts;
|
74 |
| - element = angular.element('<external-links-data linked-accounts-data="linkedAccounts"></external-links-data>)'); |
| 109 | + element = angular.element('<external-links-data linked-accounts-data="linkedAccounts" user-handle="test"></external-links-data>)'); |
75 | 110 | externalLinksData = $compile(element)(scope);
|
76 | 111 | scope.$digest();
|
77 | 112 | });
|
78 | 113 |
|
| 114 | + afterEach(function() { |
| 115 | + linkedAccounts = angular.copy(mockLinkedAccounts); |
| 116 | + scope.linkedAccounts = linkedAccounts; |
| 117 | + }); |
| 118 | + |
79 | 119 | it('should have added linkedAccounts to scope', function() {
|
80 | 120 | expect(element.isolateScope().linkedAccountsData).to.exist;
|
| 121 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should remove weblink ', function() { |
| 125 | + element.isolateScope().deleteAccount({key: 'somekey', provider: 'weblink'}); |
| 126 | + scope.$digest(); |
| 127 | + expect(toasterSvc.pop).to.have.been.calledWith('success').calledOnce; |
81 | 128 | expect(element.isolateScope().linkedAccountsData).to.have.length(7);
|
82 | 129 | });
|
83 | 130 |
|
| 131 | + it('should show success if controller doesn\'t have weblink but API returns success ', function() { |
| 132 | + element.isolateScope().deleteAccount({key: 'somekey1', provider: 'weblink'}); |
| 133 | + scope.$digest(); |
| 134 | + expect(toasterSvc.pop).to.have.been.calledWith('success').calledOnce; |
| 135 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should NOT remove weblink with fatal error ', function() { |
| 139 | + element.isolateScope().deleteAccount({key: 'throwFatalError', provider: 'weblink'}); |
| 140 | + scope.$digest(); |
| 141 | + expect(toasterSvc.pop).to.have.been.calledWith('error', "Whoops!", sinon.match('Sorry!')).calledOnce; |
| 142 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should NOT remove weblink with already removed weblink ', function() { |
| 146 | + element.isolateScope().deleteAccount({key: 'throwNotExistsError', provider: 'weblink'}); |
| 147 | + scope.$digest(); |
| 148 | + expect(toasterSvc.pop).to.have.been.calledWith('error', "Whoops!", sinon.match('not linked')).calledOnce; |
| 149 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 150 | + }); |
| 151 | + |
| 152 | + it('should not do any thing when already a deletion is in progress ', function() { |
| 153 | + element.isolateScope().deletingAccount = true; |
| 154 | + element.isolateScope().deleteAccount({key: 'somekey', provider: 'weblink'}); |
| 155 | + scope.$digest(); |
| 156 | + expect(extLinkSvc.removeLink).not.to.be.called; |
| 157 | + expect(toasterSvc.pop).not.to.be.called; |
| 158 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 159 | + }); |
| 160 | + |
| 161 | + it('should not do any thing for non weblink provider ', function() { |
| 162 | + element.isolateScope().deleteAccount({key: 'somekey', provider: 'stackoverflow'}); |
| 163 | + scope.$digest(); |
| 164 | + expect(extLinkSvc.removeLink).not.to.be.called; |
| 165 | + expect(toasterSvc.pop).not.to.be.called; |
| 166 | + expect(element.isolateScope().linkedAccountsData).to.have.length(8); |
| 167 | + }); |
| 168 | + |
84 | 169 | });
|
85 | 170 | });
|
0 commit comments