Skip to content

Commit 0e446c1

Browse files
committed
add tests for autofocus first form element
introduced by last commit (545f3b0)
1 parent 545f3b0 commit 0e446c1

File tree

9 files changed

+87
-43
lines changed

9 files changed

+87
-43
lines changed

tests/acceptance/create-a-poll-test.js

+40-16
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,30 @@ test('create a default poll', function(assert) {
9393
[false, true, true, true, true],
9494
'status bar has correct items disabled (index)'
9595
);
96+
assert.ok(
97+
pageCreateIndex.pollTypeHasFocus,
98+
'poll type selection has autofocus'
99+
);
96100

97101
pageCreateIndex
98102
.next();
99103

100104
andThen(function() {
101105
assert.equal(currentPath(), 'create.meta');
102106
assert.equal(
103-
pageCreateIndex.statusBar().active,
107+
pageCreateMeta.statusBar().active,
104108
t('create.formStep.meta').toString(),
105109
'status bar shows correct item as current path (meta)'
106110
);
107111
assert.deepEqual(
108-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
112+
pageCreateMeta.statusBar().toArray().map((el) => el.isDisabled),
109113
[false, false, true, true, true],
110114
'status bar has correct items disabled (meta)'
111115
);
116+
assert.ok(
117+
pageCreateMeta.titleHasFocus,
118+
'title input has autofocus'
119+
);
112120

113121
pageCreateMeta
114122
.title('default poll')
@@ -117,12 +125,12 @@ test('create a default poll', function(assert) {
117125
andThen(function() {
118126
assert.equal(currentPath(), 'create.options');
119127
assert.equal(
120-
pageCreateIndex.statusBar().active,
128+
pageCreateOptions.statusBar().active,
121129
t('create.formStep.options.days').toString(),
122130
'status bar shows correct item as current path (options.days)'
123131
);
124132
assert.deepEqual(
125-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
133+
pageCreateOptions.statusBar().toArray().map((el) => el.isDisabled),
126134
[false, false, false, true, true],
127135
'status bar has correct items disabled (options)'
128136
);
@@ -135,31 +143,39 @@ test('create a default poll', function(assert) {
135143
andThen(function() {
136144
assert.equal(currentPath(), 'create.options-datetime');
137145
assert.equal(
138-
pageCreateIndex.statusBar().active,
146+
pageCreateOptionsDatetime.statusBar().active,
139147
t('create.formStep.options-datetime').toString(),
140148
'status bar shows correct item as current path (options-datetime)'
141149
);
142150
assert.deepEqual(
143-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
151+
pageCreateOptionsDatetime.statusBar().toArray().map((el) => el.isDisabled),
144152
[false, false, false, false, true],
145153
'status bar has correct items disabled (options-datetime)'
146154
);
155+
assert.ok(
156+
pageCreateOptionsDatetime.firstTime.inputHasFocus,
157+
'first time input has autofocus'
158+
);
147159

148160
pageCreateOptionsDatetime
149161
.next();
150162

151163
andThen(() => {
152164
assert.equal(currentPath(), 'create.settings');
153165
assert.equal(
154-
pageCreateIndex.statusBar().active,
166+
pageCreateSettings.statusBar().active,
155167
t('create.formStep.settings').toString(),
156168
'status bar shows correct item as current path (settings)'
157169
);
158170
assert.deepEqual(
159-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
171+
pageCreateSettings.statusBar().toArray().map((el) => el.isDisabled),
160172
[false, false, false, false, false],
161173
'status bar has correct items disabled (settings)'
162174
);
175+
assert.ok(
176+
pageCreateSettings.availableAnswersHasFocus,
177+
'available answers selection has autofocus'
178+
);
163179

164180
pageCreateSettings
165181
.next();
@@ -197,6 +213,10 @@ test('create a default poll', function(assert) {
197213
],
198214
'answers are correctly labeled'
199215
);
216+
assert.ok(
217+
pagePollParticipation.nameHasFocus,
218+
'name input has autofocus'
219+
);
200220
});
201221
});
202222
});
@@ -228,12 +248,12 @@ test('create a poll for answering a question', function(assert) {
228248
andThen(function() {
229249
assert.equal(currentPath(), 'create.meta');
230250
assert.equal(
231-
pageCreateIndex.statusBar().active,
251+
pageCreateMeta.statusBar().active,
232252
t('create.formStep.meta').toString(),
233253
'status bar shows correct item as current path (meta)'
234254
);
235255
assert.deepEqual(
236-
pageCreateIndex.statusBar().toArray().map((el) => el.text),
256+
pageCreateMeta.statusBar().toArray().map((el) => el.text),
237257
[
238258
t('create.formStep.type').toString(),
239259
t('create.formStep.meta').toString(),
@@ -243,7 +263,7 @@ test('create a poll for answering a question', function(assert) {
243263
'status bar has correct items'
244264
);
245265
assert.deepEqual(
246-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
266+
pageCreateMeta.statusBar().toArray().map((el) => el.isDisabled),
247267
[false, false, true, true],
248268
'status bar has correct items disabled (meta)'
249269
);
@@ -255,16 +275,20 @@ test('create a poll for answering a question', function(assert) {
255275
andThen(function() {
256276
assert.equal(currentPath(), 'create.options');
257277
assert.equal(
258-
pageCreateIndex.statusBar().active,
278+
pageCreateOptions.statusBar().active,
259279
t('create.formStep.options.text').toString(),
260280
'status bar shows correct item as current path (options.text)'
261281
);
262282
assert.deepEqual(
263-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
283+
pageCreateOptions.statusBar().toArray().map((el) => el.isDisabled),
264284
[false, false, false, true],
265285
'status bar has correct items disabled (options)'
266286
);
267287
expectComponent('create-options-text');
288+
assert.ok(
289+
pageCreateOptions.firstTextOption.inputHasFocus,
290+
'first option input has autofocus'
291+
);
268292

269293
assert.equal(
270294
pageCreateOptions.textOptions().count,
@@ -281,7 +305,7 @@ test('create a poll for answering a question', function(assert) {
281305
'validation errors prevents transition'
282306
);
283307
assert.equal(
284-
pageCreateIndex.statusBar().active,
308+
pageCreateOptions.statusBar().active,
285309
t('create.formStep.options.text').toString(),
286310
'status bar shows correct item as current path (options.text)'
287311
);
@@ -333,12 +357,12 @@ test('create a poll for answering a question', function(assert) {
333357
andThen(function() {
334358
assert.equal(currentPath(), 'create.settings');
335359
assert.equal(
336-
pageCreateIndex.statusBar().active,
360+
pageCreateSettings.statusBar().active,
337361
t('create.formStep.settings').toString(),
338362
'status bar shows correct item as current path (settings)'
339363
);
340364
assert.deepEqual(
341-
pageCreateIndex.statusBar().toArray().map((el) => el.isDisabled),
365+
pageCreateSettings.statusBar().toArray().map((el) => el.isDisabled),
342366
[false, false, false, false],
343367
'status bar has correct items disabled (settings)'
344368
);

tests/integration/components/bs-input-test.js

-24
This file was deleted.

tests/pages/create/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PageObject from 'ember-cli-page-object';
22
import { defaultsForCreate } from 'croodle/tests/pages/defaults';
3+
import { hasFocus } from 'croodle/tests/pages/helpers';
34

45
const {
56
assign
@@ -12,5 +13,6 @@ const {
1213

1314
export default PageObject.create(assign({}, defaultsForCreate, {
1415
pollType: fillable('.poll-type select'),
16+
pollTypeHasFocus: hasFocus('.poll-type select'),
1517
visit: visitable('/create')
1618
}));

tests/pages/create/meta.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PageObject from 'ember-cli-page-object';
22
import { defaultsForCreate } from 'croodle/tests/pages/defaults';
3+
import { hasFocus } from 'croodle/tests/pages/helpers';
34

45
const {
56
assign
@@ -11,5 +12,6 @@ let {
1112

1213
export default PageObject.create(assign({}, defaultsForCreate, {
1314
description: fillable('.description textarea'),
14-
title: fillable('.title input')
15+
title: fillable('.title input'),
16+
titleHasFocus: hasFocus('.title input')
1517
}));

tests/pages/create/options-datetime.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PageObject from 'ember-cli-page-object';
22
import { defaultsForCreate } from 'croodle/tests/pages/defaults';
3+
import { hasFocus } from 'croodle/tests/pages/helpers';
34

45
const {
56
assign
@@ -27,5 +28,10 @@ export default PageObject.create(assign({}, defaultsForCreate, {
2728
labelIsHidden: hasClass('label', 'sr-only'),
2829
time: fillable('input')
2930
}
30-
})
31+
}),
32+
firstTime: {
33+
scope: '.form-group:first',
34+
35+
inputHasFocus: hasFocus('input')
36+
}
3137
}));

tests/pages/create/options.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Ember from 'ember';
22
import PageObject from 'ember-cli-page-object';
33
import { findElementWithAssert } from 'ember-cli-page-object';
44
import { defaultsForCreate } from 'croodle/tests/pages/defaults';
5+
import { hasFocus } from 'croodle/tests/pages/helpers';
56

67
const {
78
assign
@@ -51,5 +52,10 @@ export default PageObject.create(assign({}, defaultsForCreate, {
5152
hasError: hasClass('has-error'),
5253
title: fillable('input')
5354
}
54-
})
55+
}),
56+
firstTextOption: {
57+
scope: '.form-group.option:first',
58+
59+
inputHasFocus: hasFocus('input')
60+
}
5561
}));

tests/pages/create/settings.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import PageObject from 'ember-cli-page-object';
22
import { defaultsForCreate } from 'croodle/tests/pages/defaults';
3+
import { hasFocus } from 'croodle/tests/pages/helpers';
34

45
const {
56
assign
67
} = Object;
78

89
const {
10+
fillable,
911
visitable
1012
} = PageObject;
1113

1214
export default PageObject.create(assign({}, defaultsForCreate, {
15+
availableAnswers: fillable('.answer-type select'),
16+
availableAnswersHasFocus: hasFocus('.answer-type select'),
1317
visit: visitable('/create/settings')
1418
}));

tests/pages/helpers.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { findElement } from 'ember-cli-page-object';
2+
3+
/*
4+
* In Webkit `.is(':focus')` is `false` if document hasn't focus
5+
* which is often the cases in testing and for sure for all test runs in phantomjs.
6+
* Using el === document.activeElement as a work-a-round.
7+
* Background: https://github.com/ariya/phantomjs/issues/10427
8+
*/
9+
10+
export function hasFocus(selector, options = {}) {
11+
return {
12+
isDescriptor: true,
13+
14+
get() {
15+
let [ el ] = findElement(this, selector, options);
16+
let document = el.ownerDocument;
17+
return $(el).is(':focus') || el === document.activeElement;
18+
}
19+
};
20+
}

tests/pages/poll/participation.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import PageObject from 'ember-cli-page-object';
22
import { defaultsForApplication } from 'croodle/tests/pages/defaults';
3+
import { hasFocus } from 'croodle/tests/pages/helpers';
34

45
let {
56
collection,
7+
fillable,
68
text,
79
visitable
810
} = PageObject;
@@ -18,6 +20,8 @@ const urlMatches = function(regExp) {
1820

1921
export default PageObject.create(assign({}, defaultsForApplication, {
2022
description: text('.description'),
23+
name: fillable('.name input'),
24+
nameHasFocus: hasFocus('.name input'),
2125
options: collection({
2226
answers: text('.selections .form-group:eq(0) .radio', { multiple: true }),
2327
itemScope: '.selections .form-group',

0 commit comments

Comments
 (0)