This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
collection_test.js
249 lines (196 loc) · 7.57 KB
/
collection_test.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
'use strict';
/* global __dirname */
var assert = require('assert');
var Actions = require('marionette-client').Actions;
var Collection = require('./lib/collection');
var Home2 = require('./lib/home2');
var EmeServer = require('./eme_server/parent');
var System = require('../../../../apps/system/test/marionette/lib/system');
marionette('Vertical - Collection', function() {
var client = marionette.client(Home2.clientOptions);
var actions, collection, home, selectors, server, system;
suiteSetup(function(done) {
var folder = __dirname + '/fixtures/everythingme';
EmeServer(folder, client, function(err, _server) {
server = _server;
done(err);
});
});
suiteTeardown(function(done) {
server.close(done);
});
setup(function() {
actions = new Actions(client);
selectors = Collection.Selectors;
collection = new Collection(client);
home = new Home2(client);
system = new System(client);
system.waitForStartup();
client.apps.launch(Home2.URL);
home.waitForLaunch();
// Disable Geolocation prompt
var chromeClient = client.scope({ context: 'chrome' });
chromeClient.executeScript(function(origin) {
var mozPerms = navigator.mozPermissionSettings;
mozPerms.set(
'geolocation', 'deny', origin + '/manifest.webapp', origin, false
);
}, [Collection.URL]);
// Update eme server settings
chromeClient.executeScript(function(url) {
navigator.mozSettings.createLock().set({
'everythingme.api.url': url
});
}, [server.url + '/{resource}']);
});
test('create collections', function() {
collection.enterCreateScreen();
var names = [
'Around Me',
'Astrology',
'Autos'
];
collection.selectNew(names);
client.apps.switchToApp(Home2.URL);
// Verify that all collections were created.
names.forEach(function(name) {
collection.getCollectionByName(name);
});
});
test('collection name localization', function() {
var collectionName = 'Entertainment';
collection.enterCreateScreen();
collection.selectNew([collectionName]);
client.apps.switchToApp(Home2.URL);
var collectionIcon =
collection.getCollectionByName(collectionName);
// switch to a different locale
client.executeScript(function() {
navigator.mozSettings.createLock().set({
// this is a dynamicly generated locale from english which is perfect
// for testing this kind of thing since as long as there is an english
// locale this will work.
'language.current': 'qps-ploc'
});
});
var expected = home.l10n(
'/locales-obj/qps-ploc.json',
// XXX: harcoded number 376 taken from the fixture
'collection-categoryId-376'
);
client.waitFor(function() {
return expected === collectionIcon.text();
});
server.failAll();
// Now verify the translation inside of the offline message
collectionIcon.tap();
client.switchToFrame();
client.apps.switchToApp(Collection.URL);
var offlineMessage = client.helper.waitForElement(
selectors.offlineMessage);
// Collections named are stubbed in gaia properties. See:
// shared/locales/collection_categories/collection_categories.fr.properties
assert.ok(offlineMessage.text().indexOf(expected) !== -1);
server.unfailAll();
client.executeScript(function() {
window.dispatchEvent(new CustomEvent('online'));
});
client.helper.waitForElementToDisappear(offlineMessage);
});
test('pin collection web result', function() {
collection.enterCreateScreen();
// A collection name from the cateories_list.json stub
var collectionName = 'Around Me';
collection.selectNew(collectionName);
client.apps.switchToApp(Home2.URL);
// Enter the created collection.
collection.enterCollection(
collection.getCollectionByName(collectionName));
// Count the number of dividers
var numDividers = client.findElements(selectors.allDividers).length;
assert.equal(numDividers, 0, 'there are no dividers');
collection.pin(selectors.firstWebResultNoPinned);
// Wait until a new section is created.
client.waitFor(function() {
var currentDividers = client.findElements(selectors.allDividers).length;
return currentDividers === numDividers + 1;
});
// Compare the position of the first pinned icon to the first web result.
// The pinned icon should be higher than the web result.
var firstWebPosition = client.findElement(selectors.firstWebResultPinned)
.location();
var firstPinnedPosition = client.findElement(selectors.firstPinnedResult)
.location();
assert.equal(firstWebPosition.x, firstPinnedPosition.x,
'items are on the same x-axis');
assert.ok(firstWebPosition.y > firstPinnedPosition.y,
'the web result is below the pinned item');
});
test('edit mode with two pinned objects', function() {
collection.enterCreateScreen();
// A collection name from the cateories_list.json stub
var collectionName = 'Around Me';
collection.selectNew(collectionName);
client.apps.switchToApp(Home2.URL);
// Enter the created collection.
collection.enterCollection(
collection.getCollectionByName(collectionName));
collection.pin(selectors.firstWebResultNoPinned);
collection.pin(selectors.firstWebResultPinned);
// This identifier matches up to an item in categories_list.json
var secondIdentifier = 'http://mozilla2.org/firefox';
var secondPinned = client.helper.waitForElement(
'.icon[data-identifier="' + secondIdentifier + '"]');
var secondLocation = secondPinned.location().x;
var firstPinned = client.helper.waitForElement(
selectors.firstPinnedResult);
actions
.press(firstPinned)
.wait(1)
.move(secondPinned)
.wait(1)
.release()
.wait(1)
.perform();
assert.equal(secondLocation, firstPinned.location().x,
'the first icon has moved to the right.');
assert.ok(secondPinned.location().x < secondLocation,
'the second icon has moved to the left.');
});
test('drag icon (/w entry point) into collection', function() {
var dialerManifest = 'app://communications.gaiamobile.org/manifest.webapp';
var dialerEntryPoint = 'dialer';
collection.enterCreateScreen();
// A collection name from the cateories_list.json stub
var collectionName = 'Around Me';
collection.selectNew(collectionName);
client.apps.switchToApp(Home2.URL);
// Drag the 'Phone' application into the created collection.
// We specifically choose phone because it has an entry point.
var phoneIcon = home.getIcon(dialerManifest, dialerEntryPoint);
var collectionIcon = collection.getCollectionByName(collectionName);
var bodyHeight = client.findElement('body').size().height;
var iconTop = phoneIcon.scriptWith(function(el) {
return el.getBoundingClientRect().top;
});
actions
.press(phoneIcon)
.wait(1)
// Move the phone icon to the bottom of the screen to scroll down.
.moveByOffset(0, bodyHeight - iconTop)
.wait(4)
// Now drop the icon into the collection
.move(collectionIcon)
.release()
.wait(1)
.perform();
// Exit edit mode.
var done = client.helper.waitForElement(Home2.Selectors.editHeaderDone);
done.click();
// Enter the created collection.
collection.enterCollection(collectionIcon);
var firstPinnedIcon = client.findElement(selectors.firstPinnedResult);
assert.equal(firstPinnedIcon.text(),
home.localizedAppName('communications', 'dialer', 'en-US'));
});
});