@webship-js/immich-steps 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +251 -2
- package/assets/logo.svg +29 -0
- package/package.json +62 -4
- package/tests/features/albums.feature +26 -0
- package/tests/features/api.feature +30 -0
- package/tests/features/library.feature +46 -0
- package/tests/features/sign-in.feature +26 -0
- package/tests/fixtures/webship-test-blue.jpg +0 -0
- package/tests/fixtures/webship-test-green.jpg +0 -0
- package/tests/fixtures/webship-test-red.jpg +0 -0
- package/tests/step-definitions/immich-albums.steps.js +213 -0
- package/tests/step-definitions/immich-auth.steps.js +286 -0
- package/tests/step-definitions/immich-helpers.js +453 -0
- package/tests/step-definitions/immich-library.steps.js +437 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The library's photos: uploading them (through the page's Upload button, or through the API), the timeline and the
|
|
4
|
+
// photo viewer (a photo is named by the date it was taken: "Image taken on May 1, 2024"), its details, favorites,
|
|
5
|
+
// the trash with its Undo, and the library's messages and confirmations, read by their text.
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
10
|
+
const h = require('./immich-helpers');
|
|
11
|
+
|
|
12
|
+
const { friendly, failure } = h;
|
|
13
|
+
|
|
14
|
+
/** The upload's answer read: its asset, or a failure that says what the library did with the file. */
|
|
15
|
+
async function uploaded(page, file, answer) {
|
|
16
|
+
if (!answer) {
|
|
17
|
+
throw failure(page, `Expected the library to take "${file}", but no upload was answered within the wait.`, {
|
|
18
|
+
hint: 'Check that the page is the library\'s timeline (Given I am signed in to the library as "user") and that the file is a photo or a video.',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
let body = {};
|
|
22
|
+
try { body = await answer.json(); } catch (e) { /* not JSON */ }
|
|
23
|
+
if (answer.status() === 200 && body.status === 'duplicate') {
|
|
24
|
+
throw failure(page, `Expected the library to take "${file}", but it holds that file already (a duplicate of asset ${body.id}).`, {
|
|
25
|
+
hint: 'Tag the scenario @removes-test-content, so the files a scenario uploads are removed after it.',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (answer.status() !== 201) {
|
|
29
|
+
throw failure(page, `Expected the library to take "${file}", but it answered ${answer.status()}: ${body.message || JSON.stringify(body).slice(0, 200)}.`, {
|
|
30
|
+
hint: 'Check that the file is one the library takes (a photo or a video) and that the account may upload.',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return body;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Upload a file through the page's Upload button and its file chooser, as a person does; the step waits until the
|
|
38
|
+
* library has taken it and finished with it (its details read, its thumbnail made). The file is from the project's fixtures folder (worldParameters.immich.fixtures), else from
|
|
39
|
+
* the pack's own: webship-test-red.jpg (taken on May 1, 2024), webship-test-blue.jpg (August 15, 2023),
|
|
40
|
+
* webship-test-green.jpg (December 24, 2022).
|
|
41
|
+
*
|
|
42
|
+
* Example #1: When I upload "webship-test-red.jpg" to the library
|
|
43
|
+
* Example #2: When we upload "webship-test-blue.jpg" to the library
|
|
44
|
+
* Example #3: And I upload "webship-test-green.jpg" to the library
|
|
45
|
+
* Example #4: When I upload "holiday-2024.jpg" to the library
|
|
46
|
+
* Example #5: Given I upload "webship-test-red.jpg" to the library
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
When(/^(?:I|we) upload "([^"]+)" to the library$/, async function (file) {
|
|
50
|
+
const page = this.page;
|
|
51
|
+
const filePath = h.fixture(this, file);
|
|
52
|
+
const button = page.getByRole('button', { name: 'Upload', exact: true });
|
|
53
|
+
try {
|
|
54
|
+
await button.waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
55
|
+
} catch (e) {
|
|
56
|
+
throw failure(page, `Expected the library's Upload button, but the page (${page.url()}) has none.`, {
|
|
57
|
+
hint: 'Open the library signed in first: Given I am signed in to the library as "user".',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const chooser = page.waitForEvent('filechooser', { timeout: h.WAIT.page });
|
|
61
|
+
const answer = await h.callOf(page, 'POST', /^\/api\/assets$/, async () => {
|
|
62
|
+
await button.click();
|
|
63
|
+
await (await chooser).setFiles(filePath);
|
|
64
|
+
}, h.WAIT.upload);
|
|
65
|
+
const asset = await uploaded(page, file, answer);
|
|
66
|
+
await h.processed(this, asset.id, { session: true });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Upload a file through the API, signed as the API steps are (a token or an API key): no browser, so it runs in the
|
|
71
|
+
* lane without JavaScript too. The file is found as the page's upload finds it.
|
|
72
|
+
*
|
|
73
|
+
* Example #1: When I upload "webship-test-red.jpg" to the library through the API
|
|
74
|
+
* Example #2: When we upload "webship-test-blue.jpg" to the library through the API
|
|
75
|
+
* Example #3: And I upload "webship-test-green.jpg" to the library through the API
|
|
76
|
+
* Example #4: When I upload "holiday-2024.jpg" to the library through the API
|
|
77
|
+
* Example #5: Given I upload "webship-test-red.jpg" to the library through the API
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
When(/^(?:I|we) upload "([^"]+)" to the library through the API$/, async function (file) {
|
|
81
|
+
const filePath = h.fixture(this, file);
|
|
82
|
+
const headers = h.apiAuth(this);
|
|
83
|
+
const stamp = fs.statSync(filePath).mtime.toISOString();
|
|
84
|
+
const context = this.context || this.page.context();
|
|
85
|
+
let answer;
|
|
86
|
+
try {
|
|
87
|
+
answer = await context.request.post(h.absolute(this, '/api/assets'), {
|
|
88
|
+
headers: { Accept: 'application/json', ...headers },
|
|
89
|
+
multipart: {
|
|
90
|
+
assetData: { name: path.basename(filePath), mimeType: h.mimeOf(filePath), buffer: fs.readFileSync(filePath) },
|
|
91
|
+
fileCreatedAt: stamp,
|
|
92
|
+
fileModifiedAt: stamp,
|
|
93
|
+
filename: path.basename(filePath),
|
|
94
|
+
},
|
|
95
|
+
failOnStatusCode: false,
|
|
96
|
+
timeout: h.WAIT.upload,
|
|
97
|
+
});
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw friendly({ message: `The library did not answer the upload of "${file}".`, cause: e, hint: 'Check that the library is up at the launch URL of cucumber.js (LAUNCH_URL).' });
|
|
100
|
+
}
|
|
101
|
+
let body = {};
|
|
102
|
+
try { body = await answer.json(); } catch (e) { /* not JSON */ }
|
|
103
|
+
if (answer.status() === 200 && body.status === 'duplicate') {
|
|
104
|
+
throw friendly({ message: `Expected the library to take "${file}", but it holds that file already (a duplicate of asset ${body.id}).`, hint: 'Tag the scenario @removes-test-content, so the files a scenario uploads are removed after it.' });
|
|
105
|
+
}
|
|
106
|
+
if (answer.status() !== 201) {
|
|
107
|
+
throw friendly({ message: `Expected the library to take "${file}" through the API, but it answered ${answer.status()}: ${body.message || JSON.stringify(body).slice(0, 200)}.`, hint: answer.status() === 401 ? 'Sign the API in first: Given I am signed in to the library\'s API as "user".' : 'Check that the account (or its key) may upload.' });
|
|
108
|
+
}
|
|
109
|
+
await h.processed(this, body.id, headers['x-api-key'] ? { key: headers['x-api-key'] } : { token: String(headers.Authorization || '').replace(/^Bearer /, '') });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/** The assets of the signed-in API whose original file name is the file's. */
|
|
113
|
+
async function holding(world, file) {
|
|
114
|
+
const auth = h.apiAuth(world);
|
|
115
|
+
const answer = await h.request(world, 'POST', '/api/search/metadata', { ...(auth['x-api-key'] ? { key: auth['x-api-key'] } : { token: String(auth.Authorization || '').replace(/^Bearer /, '') }), json: { originalFileName: file, size: 100 } });
|
|
116
|
+
if (answer.status !== 200) {
|
|
117
|
+
throw friendly({ message: `Expected the library's search to answer, but it answered ${answer.status}: ${h.said(answer)}.`, hint: 'Check that the API is signed in as an account of the library.' });
|
|
118
|
+
}
|
|
119
|
+
return ((answer.data && answer.data.assets && answer.data.assets.items) || []).filter((a) => a.originalFileName === file && !a.isTrashed);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The library holds a file (in its timeline, not in the trash), as the signed-in API sees it: by its original name,
|
|
124
|
+
* through the library's search. Waits a moment for an upload that has just been taken.
|
|
125
|
+
*
|
|
126
|
+
* Example #1: Then the library should hold "webship-test-red.jpg"
|
|
127
|
+
* Example #2: And the library should hold "webship-test-blue.jpg"
|
|
128
|
+
* Example #3: Then the library should hold "webship-test-green.jpg"
|
|
129
|
+
* Example #4: Then the library should hold "holiday-2024.jpg"
|
|
130
|
+
* Example #5: But the library should hold "webship-test-red.jpg"
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
Then(/^the library should hold "([^"]+)"$/, async function (file) {
|
|
134
|
+
for (let i = 0; i < 20; i += 1) {
|
|
135
|
+
if ((await holding(this, file)).length) return;
|
|
136
|
+
await h.pause(500);
|
|
137
|
+
}
|
|
138
|
+
throw friendly({ message: `Expected the library to hold "${file}", but its search finds no such file outside the trash.`, hint: 'Upload it first in the scenario, as the account the API is signed in as.' });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The library does not hold a file outside its trash, as the signed-in API sees it.
|
|
143
|
+
*
|
|
144
|
+
* Example #1: Then the library should not hold "webship-test-red.jpg"
|
|
145
|
+
* Example #2: And the library should not hold "webship-test-blue.jpg"
|
|
146
|
+
* Example #3: Then the library should not hold "webship-test-green.jpg"
|
|
147
|
+
* Example #4: Then the library should not hold "holiday-2024.jpg"
|
|
148
|
+
* Example #5: But the library should not hold "webship-test-red.jpg"
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
Then(/^the library should not hold "([^"]+)"$/, async function (file) {
|
|
152
|
+
const found = await holding(this, file);
|
|
153
|
+
if (found.length) {
|
|
154
|
+
throw friendly({ message: `Expected the library not to hold "${file}", but it holds it (asset ${found[0].id}).`, hint: 'A file in the trash does not count: move it to the trash, or upload another.' });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The page shows a photo taken on a date, written as the library writes it in the photo's name ("May 1, 2024"): the
|
|
160
|
+
* timeline, an album, a search or the trash. Waits for it.
|
|
161
|
+
*
|
|
162
|
+
* Example #1: Then the timeline should show the photo taken on "May 1, 2024"
|
|
163
|
+
* Example #2: And the timeline should show the photo taken on "August 15, 2023"
|
|
164
|
+
* Example #3: Then the timeline should show the photo taken on "December 24, 2022"
|
|
165
|
+
* Example #4: Then the timeline should show the photo taken on "January 9, 2021"
|
|
166
|
+
* Example #5: But the timeline should show the photo taken on "May 1, 2024"
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
Then(/^the timeline should show the photo taken on "([^"]+)"$/, async function (date) {
|
|
170
|
+
if (!(await h.photoShows(this.page, date))) {
|
|
171
|
+
const shown = await h.photosShown(this.page);
|
|
172
|
+
throw failure(this.page, `Expected the timeline to show the photo taken on "${date}", but it shows ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'no photo'}.`, {
|
|
173
|
+
hint: 'Write the date as the library does ("May 1, 2024"): the date the photo was taken, from its EXIF.',
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The page does not show a photo taken on that date.
|
|
180
|
+
*
|
|
181
|
+
* Example #1: Then the timeline should not show the photo taken on "May 1, 2024"
|
|
182
|
+
* Example #2: And the timeline should not show the photo taken on "August 15, 2023"
|
|
183
|
+
* Example #3: Then the timeline should not show the photo taken on "December 24, 2022"
|
|
184
|
+
* Example #4: Then the timeline should not show the photo taken on "January 9, 2021"
|
|
185
|
+
* Example #5: But the timeline should not show the photo taken on "May 1, 2024"
|
|
186
|
+
*
|
|
187
|
+
*/
|
|
188
|
+
Then(/^the timeline should not show the photo taken on "([^"]+)"$/, async function (date) {
|
|
189
|
+
await this.page.waitForLoadState('networkidle').catch(() => {});
|
|
190
|
+
if (await h.photoShows(this.page, date, 1000)) {
|
|
191
|
+
throw failure(this.page, `Expected the timeline not to show the photo taken on "${date}", but it does.`, {
|
|
192
|
+
hint: 'A photo in the trash leaves the timeline; check that the scenario moved this one.',
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Open a photo of the page in the library's photo viewer, by the date it was taken; the step waits for the viewer.
|
|
199
|
+
*
|
|
200
|
+
* Example #1: When I open the photo taken on "May 1, 2024"
|
|
201
|
+
* Example #2: When we open the photo taken on "August 15, 2023"
|
|
202
|
+
* Example #3: And I open the photo taken on "December 24, 2022"
|
|
203
|
+
* Example #4: When I open the photo taken on "January 9, 2021"
|
|
204
|
+
* Example #5: Given I open the photo taken on "May 1, 2024"
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
When(/^(?:I|we) open the photo taken on "([^"]+)"$/, async function (date) {
|
|
208
|
+
const page = this.page;
|
|
209
|
+
if (!(await h.photoShows(page, date))) {
|
|
210
|
+
const shown = await h.photosShown(page);
|
|
211
|
+
throw failure(page, `Expected a photo taken on "${date}" to open, but the page shows ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'no photo'}.`, {
|
|
212
|
+
hint: 'Open the page that shows it first (the timeline, an album), and write the date as the library does ("May 1, 2024").',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
await h.photo(page, date).first().click();
|
|
216
|
+
try {
|
|
217
|
+
await page.getByRole('button', { name: 'Info', exact: true }).waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
218
|
+
} catch (e) {
|
|
219
|
+
throw failure(page, `Expected the photo viewer for the photo taken on "${date}", but it did not open (the page is ${page.url()}).`, {
|
|
220
|
+
hint: 'A photo in a picker is selected, not opened: close the picker first.',
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
/** The viewer's details panel, opened when it is closed. */
|
|
226
|
+
async function details(page) {
|
|
227
|
+
const panel = page.getByText('Details', { exact: true }).filter({ visible: true });
|
|
228
|
+
if (!(await panel.count())) {
|
|
229
|
+
await page.getByRole('button', { name: 'Info', exact: true }).click();
|
|
230
|
+
await panel.first().waitFor({ state: 'visible', timeout: h.WAIT.page }).catch(() => {});
|
|
231
|
+
}
|
|
232
|
+
return panel;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The photo viewer's details say a text: the date, the file name, the size, the camera… The details panel is opened
|
|
237
|
+
* when it is closed.
|
|
238
|
+
*
|
|
239
|
+
* Example #1: Then the photo's details should say "webship-test-red.jpg"
|
|
240
|
+
* Example #2: And the photo's details should say "640 × 480"
|
|
241
|
+
* Example #3: Then the photo's details should say "Webship test camera"
|
|
242
|
+
* Example #4: Then the photo's details should say "May 1, 2024"
|
|
243
|
+
* Example #5: But the photo's details should say "12.2 KiB"
|
|
244
|
+
*
|
|
245
|
+
*/
|
|
246
|
+
Then(/^the photo's details should say "([^"]+)"$/, async function (text) {
|
|
247
|
+
const page = this.page;
|
|
248
|
+
await details(page);
|
|
249
|
+
if (!(await h.messageShown(page, text, h.WAIT.message))) {
|
|
250
|
+
const panel = await page.locator('section, aside').filter({ hasText: 'Details' }).last().innerText().catch(() => '');
|
|
251
|
+
throw failure(page, `Expected the photo's details to say "${text}", but they say: ${panel.split('\n').map((s) => s.trim()).filter(Boolean).slice(0, 12).join(' · ') || '(nothing)'}.`, {
|
|
252
|
+
hint: 'Open the photo first (When I open the photo taken on "…"), and write the text as the panel shows it.',
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Mark the photo open in the viewer as a favorite, or take the mark off; the step waits until the library has it.
|
|
259
|
+
*
|
|
260
|
+
* Example #1: When I mark the photo as a favorite
|
|
261
|
+
* Example #2: When we mark the photo as a favorite
|
|
262
|
+
* Example #3: And I mark the photo as a favorite
|
|
263
|
+
* Example #4: When I unmark the photo as a favorite
|
|
264
|
+
* Example #5: And we unmark the photo as a favorite
|
|
265
|
+
*
|
|
266
|
+
*/
|
|
267
|
+
When(/^(?:I|we) (mark|unmark) the photo as a favorite$/, async function (how) {
|
|
268
|
+
const page = this.page;
|
|
269
|
+
const [press, then] = how === 'mark' ? ['Favorite', 'Unfavorite'] : ['Unfavorite', 'Favorite'];
|
|
270
|
+
const button = page.getByRole('button', { name: press, exact: true });
|
|
271
|
+
if (!(await button.count())) {
|
|
272
|
+
throw failure(page, `Expected the viewer's "${press}" button, but there is none${how === 'mark' ? ': the photo is a favorite already, or no photo is open' : ': the photo is not a favorite, or no photo is open'}.`, {
|
|
273
|
+
hint: 'Open the photo first: When I open the photo taken on "…".',
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const answer = await h.callOf(page, 'PUT', /^\/api\/assets$/, () => button.click());
|
|
277
|
+
try {
|
|
278
|
+
await page.getByRole('button', { name: then, exact: true }).waitFor({ state: 'visible', timeout: h.WAIT.message });
|
|
279
|
+
} catch (e) {
|
|
280
|
+
throw failure(page, `Expected the viewer to show "${then}" once the photo was ${how}ed, but it does not${answer ? ` (the library answered ${answer.status()})` : ''}.`, { hint: 'Check the library\'s log.' });
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The photo open in the viewer is a favorite, or is not (the viewer offers "Unfavorite", or "Favorite").
|
|
286
|
+
*
|
|
287
|
+
* Example #1: Then the photo should be a favorite
|
|
288
|
+
* Example #2: And the photo should be a favorite
|
|
289
|
+
* Example #3: Then the photo should not be a favorite
|
|
290
|
+
* Example #4: But the photo should not be a favorite
|
|
291
|
+
* Example #5: Then the photo should be a favorite
|
|
292
|
+
*
|
|
293
|
+
*/
|
|
294
|
+
Then(/^the photo should (be|not be) a favorite$/, async function (be) {
|
|
295
|
+
const page = this.page;
|
|
296
|
+
const offered = be === 'be' ? 'Unfavorite' : 'Favorite';
|
|
297
|
+
try {
|
|
298
|
+
await page.getByRole('button', { name: offered, exact: true }).waitFor({ state: 'visible', timeout: h.WAIT.message });
|
|
299
|
+
} catch (e) {
|
|
300
|
+
throw failure(page, `Expected the photo ${be === 'be' ? 'to be' : 'not to be'} a favorite (the viewer offering "${offered}"), but it ${be === 'be' ? 'is not' : 'is'}.`, {
|
|
301
|
+
hint: 'Open the photo first: When I open the photo taken on "…".',
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Move the photo open in the viewer to the trash (the viewer's Delete, which asks nothing); the step waits for the
|
|
308
|
+
* library's "Trashed 1 asset". Its Undo: When I press "Undo" in the library's message.
|
|
309
|
+
*
|
|
310
|
+
* Example #1: When I move the photo to the trash
|
|
311
|
+
* Example #2: When we move the photo to the trash
|
|
312
|
+
* Example #3: And I move the photo to the trash
|
|
313
|
+
* Example #4: Then I move the photo to the trash
|
|
314
|
+
* Example #5: Given we move the photo to the trash
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
When(/^(?:I|we) move the photo to the trash$/, async function () {
|
|
318
|
+
const page = this.page;
|
|
319
|
+
const button = page.getByRole('button', { name: 'Delete', exact: true });
|
|
320
|
+
if (!(await button.count())) {
|
|
321
|
+
throw failure(page, 'Expected the viewer\'s "Delete" button, but no photo is open.', { hint: 'Open the photo first: When I open the photo taken on "…".' });
|
|
322
|
+
}
|
|
323
|
+
const answer = await h.callOf(page, 'DELETE', /^\/api\/assets$/, () => button.click());
|
|
324
|
+
if (!answer || answer.status() >= 300) {
|
|
325
|
+
throw failure(page, `Expected the library to move the photo to the trash, but it ${answer ? `answered ${answer.status()}` : 'did not answer'}.`, { hint: 'Check that the account owns the photo.' });
|
|
326
|
+
}
|
|
327
|
+
if (!(await h.messageShown(page, 'Trashed', h.WAIT.message))) {
|
|
328
|
+
throw failure(page, 'Expected the library to say the photo was trashed, but it said nothing.', { hint: 'Check the library\'s settings: the trash may be off, which deletes for good.' });
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* The library says a text: in its messages (toasts: they have no role, so they are read by their text), a form's
|
|
334
|
+
* error, or anywhere on the page. Waits for it.
|
|
335
|
+
*
|
|
336
|
+
* Example #1: Then the library should say "Trashed 1 asset"
|
|
337
|
+
* Example #2: Then the library should say "Incorrect email or password"
|
|
338
|
+
* Example #3: And the library should say "Added 1 asset to the album"
|
|
339
|
+
* Example #4: Then the library should say "Restored 1 asset"
|
|
340
|
+
* Example #5: But the library should say "Permanently deleted 1 asset"
|
|
341
|
+
*
|
|
342
|
+
*/
|
|
343
|
+
Then(/^the library should say "([^"]+)"$/, async function (text) {
|
|
344
|
+
if (!(await h.messageShown(this.page, text))) {
|
|
345
|
+
const shown = await h.messagesShown(this.page);
|
|
346
|
+
throw failure(this.page, `Expected the library to say "${text}", but it says ${shown.length ? shown.map((s) => `"${s}"`).join(', ') : 'nothing'}.`, {
|
|
347
|
+
hint: 'A message shows for a few seconds after what it is about: read it in the next step.',
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Press a button of the library's message (a toast): its Undo, its View Album.
|
|
354
|
+
*
|
|
355
|
+
* Example #1: When I press "Undo" in the library's message
|
|
356
|
+
* Example #2: When we press "View Album" in the library's message
|
|
357
|
+
* Example #3: And I press "Undo" in the library's message
|
|
358
|
+
* Example #4: When I press "View Album" in the library's message
|
|
359
|
+
* Example #5: Then I press "Undo" in the library's message
|
|
360
|
+
*
|
|
361
|
+
*/
|
|
362
|
+
When(/^(?:I|we) press "([^"]+)" in the library's message$/, async function (name) {
|
|
363
|
+
const page = this.page;
|
|
364
|
+
const button = page.locator('body > div').getByRole('button', { name, exact: true }).filter({ visible: true }).first();
|
|
365
|
+
try {
|
|
366
|
+
await button.waitFor({ state: 'visible', timeout: h.WAIT.message });
|
|
367
|
+
} catch (e) {
|
|
368
|
+
const shown = await h.messagesShown(page);
|
|
369
|
+
throw failure(page, `Expected a message of the library with a "${name}" button, but it shows ${shown.length ? shown.map((s) => `"${s}"`).join(', ') : 'none'}.`, {
|
|
370
|
+
hint: 'Press it right after what the message is about: a message leaves after a few seconds.',
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
await button.click();
|
|
374
|
+
await page.waitForLoadState('networkidle').catch(() => {});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Press a button that asks first, and confirm: the library's question is a dialog with no name of its own, found by
|
|
379
|
+
* its role and its text ("Are you sure…"), and answered with its "Confirm". The step waits until the dialog closes.
|
|
380
|
+
*
|
|
381
|
+
* Example #1: When I confirm "Empty trash"
|
|
382
|
+
* Example #2: When we confirm "Restore all"
|
|
383
|
+
* Example #3: And I confirm "Delete album"
|
|
384
|
+
* Example #4: When I confirm "Empty trash"
|
|
385
|
+
* Example #5: Then we confirm "Restore all"
|
|
386
|
+
*
|
|
387
|
+
*/
|
|
388
|
+
When(/^(?:I|we) confirm "([^"]+)"$/, async function (name) {
|
|
389
|
+
const page = this.page;
|
|
390
|
+
const button = page.getByRole('button', { name, exact: true }).or(page.getByRole('menuitem', { name, exact: true })).filter({ visible: true }).first();
|
|
391
|
+
try {
|
|
392
|
+
await button.waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
393
|
+
} catch (e) {
|
|
394
|
+
throw failure(page, `Expected a "${name}" button to press, but the page (${page.url()}) has none.`, { hint: 'Open the page that offers it first (the trash, an album).' });
|
|
395
|
+
}
|
|
396
|
+
await button.click();
|
|
397
|
+
const asks = await h.dialog(page);
|
|
398
|
+
if (!asks) {
|
|
399
|
+
throw failure(page, `Expected the library to ask before "${name}", but no question showed.`, { hint: 'A button that does not ask is pressed with: When I press "…".' });
|
|
400
|
+
}
|
|
401
|
+
const confirm = asks.getByRole('button', { name: 'Confirm', exact: true });
|
|
402
|
+
if (!(await confirm.count())) {
|
|
403
|
+
const text = (await asks.innerText()).replace(/\s*\n+\s*/g, ' · ');
|
|
404
|
+
throw failure(page, `Expected the library's question to offer "Confirm", but it says: ${text}.`, { hint: 'Answer this dialog with the button it offers.' });
|
|
405
|
+
}
|
|
406
|
+
await confirm.click();
|
|
407
|
+
await asks.waitFor({ state: 'hidden', timeout: h.WAIT.dialog }).catch(() => {});
|
|
408
|
+
await page.waitForLoadState('networkidle').catch(() => {});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* The trash holds a photo taken on a date, or holds nothing: its page opened again, since it does not follow a
|
|
413
|
+
* restore on its own (it keeps showing a restored photo until it is loaded again).
|
|
414
|
+
*
|
|
415
|
+
* Example #1: Then the trash should hold the photo taken on "May 1, 2024"
|
|
416
|
+
* Example #2: And the trash should hold the photo taken on "August 15, 2023"
|
|
417
|
+
* Example #3: Then the trash should hold the photo taken on "December 24, 2022"
|
|
418
|
+
* Example #4: Then the trash should be empty
|
|
419
|
+
* Example #5: But the trash should be empty
|
|
420
|
+
*
|
|
421
|
+
*/
|
|
422
|
+
Then(/^the trash should (?:hold the photo taken on "([^"]+)"|be empty)$/, async function (date) {
|
|
423
|
+
const page = this.page;
|
|
424
|
+
await h.open(this, '/trash');
|
|
425
|
+
if (date) {
|
|
426
|
+
if (!(await h.photoShows(page, date))) {
|
|
427
|
+
const shown = await h.photosShown(page);
|
|
428
|
+
throw failure(page, `Expected the trash to hold the photo taken on "${date}", but it holds ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'nothing'}.`, { hint: 'Move it to the trash first: When I move the photo to the trash.' });
|
|
429
|
+
}
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const empty = await h.messageShown(page, 'Trashed photos and videos will show up here.', h.WAIT.page);
|
|
433
|
+
if (!empty) {
|
|
434
|
+
const shown = await h.photosShown(page);
|
|
435
|
+
throw failure(page, `Expected the trash to be empty, but it holds ${shown.length ? shown.map((d) => `the photo taken on "${d}"`).join(', ') : 'something'}.`, { hint: 'Empty it first: When I confirm "Empty trash".' });
|
|
436
|
+
}
|
|
437
|
+
});
|