-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteam-management-test.js
More file actions
137 lines (104 loc) · 3.39 KB
/
Copy pathteam-management-test.js
File metadata and controls
137 lines (104 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import Ember from 'ember';
import { test, module } from 'qunit';
import startApp from '../helpers/start-app';
import login from '../helpers/login';
import mockServer from '../helpers/mock-server';
import { response, buildResponse } from '../helpers/response';
import { loginResponseForSpecificRole } from '../mocks/account';
import { teamResponseWithOwnerLinkage } from '../mocks/team';
import { listOfTeamMembershipsOneOfEachRole } from '../mocks/team-membership';
import { listOfUsersOneForEachRole } from '../mocks/user';
var App, server;
module('Team management', {
beforeEach: function() {
server = mockServer(function() {
this.post('accounts/tokens', response(200, loginResponseForSpecificRole('owner')));
this.get('team', response(200, teamResponseWithOwnerLinkage));
this.get('pages', response(200, { data: [] }));
this.get('plans', response(200, { data: [] }));
});
App = startApp({ subdomain: 'test'});
},
afterEach: function() {
// Todo - Remove this when we update Ember from< 1.11.1
// see https://github.com/emberjs/ember.js/issues/10310#issuecomment-95685137
App.registry = App.buildRegistry();
App.reset();
server.shutdown();
Ember.run(App, 'destroy');
}
});
test('Navigating to "manage" requires authentication', function(assert) {
assert.expect(2);
visit('manage');
andThen(function() {
assert.equal(currentRouteName(), 'login', 'Unauthenticated user gets redirected to "login"');
});
login();
visit('manage');
andThen(function() {
assert.equal(currentRouteName(), 'team.manage', 'Actually navigates to "team.manage"');
});
});
test('Navigating to "manage" requires actually navigates to "team.manage"', function(assert) {
assert.expect(1);
visit('login');
login();
visit('manage');
andThen(function() {
assert.equal(currentRouteName(), 'team.manage', 'The route name is correct');
});
});
test('Team management page contains the button to destroy the team', function(assert) {
assert.expect(1);
visit('login');
login();
visit('manage');
andThen(function() {
assert.equal(find('.disband-team').length, 1, 'The button is present');
});
});
test('Successful disbanding of team asks for confirmation and sends DELETE request to server', function(assert) {
assert.expect(2);
visit('login');
login();
visit('manage');
var oldConfirm = window.confirm;
window.confirm = function() {
assert.ok(true, 'User is asked for confirmation');
return true;
};
server.delete('teams', function() {
assert.ok(true, 'DELETE request is sent to server');
return buildResponse(204);
});
andThen(function() {
click('.disband-team');
});
andThen(function() {
window.confirm = oldConfirm;
});
// TODO: Should somehow figure out navigation testing - site should redirect to regular subdomain here, but we aren't sure how to test it
});
test('Failed disbanding of team shows an error message', function(assert) {
assert.expect(1);
visit('login');
login();
visit('manage');
var oldConfirm = window.confirm;
window.confirm = function() {
return true;
};
server.delete('teams', function() {
return buildResponse(401);
});
andThen(function() {
click('.disband-team');
});
andThen(function() {
assert.equal(find('.error').length, 1, 'An error message is shown');
});
andThen(function() {
window.confirm = oldConfirm;
});
});