/
spec.js
256 lines (216 loc) · 7.92 KB
/
spec.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
describe('Task list', function() {
var applicationUrl = 'http://localhost:8000';
// In order to isolate the tests, local storage data is clear between
// test suites since the app stores data exclusively in local storage.
afterEach(function() {
browser.executeScript('window.localStorage.clear();');
});
// This is a cheap way to get `jasmine.before`
var before = function(callback) {
it('', function() {
callback();
});
};
// Page objects
var elements = {
getNewTodoInput: function() { return element(by.model('newTodo')); },
getTaskInList: function(index) { return element.all(by.css('.task')).get(index); },
getTaskEditInputInList: function(index) { return element.all(by.css('.edit')).get(index); },
getTaskCompleteToggleInList: function(index) { return element.all(by.css('.toggle')).get(index); },
getTaskDeleteButtonInList: function(index) { return element.all(by.css('.destroy')).get(index); },
getMainViewLink: function() { return element(by.css('.main-link')); },
getCompletedViewLink: function() { return element(by.css('.completed-link')); },
getClearCompletedTasksButton: function() { return element(by.id('clear-completed')); },
getTodoCount: function() { return element(by.id('todo-count')).evaluate('remainingCount'); },
getTaskListCount: function() { return element.all(by.css('.task')).count(); }
};
var addTask = function(taskText) {
elements.getNewTodoInput().sendKeys(taskText);
browser.actions().sendKeys(protractor.Key.ENTER).perform();
};
var editTask = function(index, taskTextToAppend) {
browser.actions().doubleClick(elements.getTaskInList(index)).perform();
elements.getTaskEditInputInList(index).sendKeys(taskTextToAppend);
browser.actions().sendKeys(protractor.Key.ENTER).perform();
};
var completeTask = function(index) {
browser.actions().mouseMove(elements.getTaskInList(index)).perform();
browser.actions().click(elements.getTaskCompleteToggleInList(index)).perform();
};
var deleteTask = function(optionalIndex) {
var index = optionalIndex || 0;
browser.actions().mouseMove(elements.getTaskInList(index)).perform();
browser.actions().click(elements.getTaskDeleteButtonInList(index)).perform();
};
var navigateToMainView = function() {
browser.actions().click(elements.getMainViewLink()).perform();
};
var navigateToCompletedView = function() {
browser.actions().click(elements.getCompletedViewLink()).perform();
};
var clearCompletedTasks = function() {
browser.actions().click(elements.getClearCompletedTasksButton()).perform();
};
describe('adding a task', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
});
it('shows the task in the list', function() {
expect(elements.getTaskInList(0).getText()).toBe('task a');
});
it('represents the task in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('1 item left');
});
});
describe('editing a task', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
editTask(0, ' - edited');
});
it('shows the edited task in the list', function() {
expect(elements.getTaskInList(0).getText()).toBe('task a - edited');
});
it('represents the edited task in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('1 item left');
});
});
describe('completing a task', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
completeTask(0);
navigateToCompletedView();
});
it('shows the task in the completed list', function() {
expect(elements.getTaskInList(0).getText()).toBe('task a');
});
it('does not represent the task in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('0 items left');
});
});
describe('clearing a completed task', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
completeTask(0);
navigateToCompletedView();
clearCompletedTasks();
});
it('does not show the task in the completed list', function() {
expect(elements.getTaskListCount()).toBe(0);
});
it('does not represent the task in the task count', function() {
expect(elements.getTodoCount().isDisplayed()).toBe(false);
});
});
describe('deleting a task', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
deleteTask();
});
it('does not show the task in the list', function() {
expect(elements.getTaskListCount()).toBe(0);
});
it('does not represent the task in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('');
});
});
describe('adding multiple tasks', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
addTask('task b');
addTask('task c');
});
it('shows the tasks in the list', function() {
['a', 'b', 'c'].forEach(function(char, index) {
elements.getTaskInList(index).getText().then(function(text) {
expect(text).toBe('task ' + char);
});
});
});
it('represents the tasks in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('3 items left');
});
});
describe('editing multiple tasks', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
addTask('task b');
addTask('task c');
editTask(0, ' - edited');
editTask(1, ' - edited');
editTask(2, ' - edited');
});
it('shows the edited tasks in the list', function() {
['a', 'b', 'c'].forEach(function(char, index) {
elements.getTaskInList(index).getText().then(function(text) {
expect(text).toBe('task ' + char + ' - edited');
});
});
});
it('represents the edited tasks in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('3 items left');
});
});
describe('completing multiple tasks', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
addTask('task b');
addTask('task c');
completeTask(0);
completeTask(1);
completeTask(2);
navigateToCompletedView();
});
it('shows the completed tasks in the completed list', function() {
['a', 'b', 'c'].forEach(function(char, index) {
expect(elements.getTaskInList(index).getText()).toBe('task ' + char);
});
});
it('does not represent the task in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('0 items left');
});
});
describe('clearing multiple completed tasks', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
addTask('task b');
addTask('task c');
completeTask(0);
completeTask(1);
completeTask(2);
navigateToCompletedView();
clearCompletedTasks();
});
it('does not show the tasks in the completed list', function() {
expect(elements.getTaskListCount()).toBe(0);
});
it('does not represent the task in the task count', function() {
expect(elements.getTodoCount().isDisplayed()).toBe(false);
});
});
describe('deleting multiple tasks', function() {
before(function() {
browser.get(applicationUrl);
addTask('task a');
addTask('task b');
addTask('task c');
deleteTask();
deleteTask();
deleteTask();
});
it('does not show the tasks in the list', function() {
expect(elements.getTaskListCount()).toBe(0);
});
it('does not represent the tasks in the task count', function() {
expect(elements.getTodoCount().getText()).toBe('');
});
});
});