@jskit-ai/users-web 0.2.105 → 0.2.106
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/CHANGELOG.md +5 -1
- package/locales/en.json +12 -1
- package/package.json +5 -5
- package/patterns/account-settings/PATTERN.md +59 -10
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsNotificationsSection.vue +25 -12
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsPreferencesSection.vue +25 -19
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsProfileSection.vue +74 -54
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsSignInMethodsSection.vue +7 -2
- package/src/client/account-settings/sections.js +39 -0
- package/src/client/components/AccountSettingsClientElement.vue +254 -28
- package/src/client/composables/useAccountSettingsRuntime.js +30 -5
- package/test/accountSettings.browser.test.js +371 -28
- package/test/accountSettingsSections.test.js +57 -0
- package/test/settingsPlacementContract.test.js +4 -2
|
@@ -3,6 +3,7 @@ import process from "node:process";
|
|
|
3
3
|
import { after, before, test } from "node:test";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { chromium, expect } from "@playwright/test";
|
|
6
|
+
import { materialSymbols } from "@jskit-ai/material-web/client/symbols";
|
|
6
7
|
import { createChromiumLaunchOptions, startViteFixture, stopProcess } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
7
8
|
|
|
8
9
|
const RUN = process.env.JSKIT_USERS_WEB_BROWSER_INTEGRATION === "1";
|
|
@@ -108,6 +109,24 @@ async function idleSecond(page) {
|
|
|
108
109
|
return { updates: end.updates - start.updates, busy: end.cpu - start.cpu };
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
// A section's Save: the app bar's primary action, as Material 3 puts a form's Save, named for what it saves.
|
|
113
|
+
function barSave(page, name) {
|
|
114
|
+
return page.getByTestId("jskit-shell-page-actions").getByRole("button", { name, exact: true });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The question leaving a form with unsaved edits asks.
|
|
118
|
+
function discardQuestion(page) {
|
|
119
|
+
return page.getByRole("alertdialog", { name: "Discard unsaved changes?" });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Picks an option of a select field, as a person does: open its menu, then choose.
|
|
123
|
+
async function choose(page, label, option) {
|
|
124
|
+
await page.locator(".v-select").filter({ has: page.getByLabel(label, { exact: true }) }).locator(".v-field").click();
|
|
125
|
+
const menu = page.getByRole("listbox");
|
|
126
|
+
await menu.getByRole("option", { name: option, exact: true }).click();
|
|
127
|
+
await expect(menu).toBeHidden();
|
|
128
|
+
}
|
|
129
|
+
|
|
111
130
|
function lastReport(page) {
|
|
112
131
|
return page.evaluate(() => window.accountFixture.reports.at(-1)?.message);
|
|
113
132
|
}
|
|
@@ -135,14 +154,15 @@ test("the profile section loads, saves, shows a refused field and removes the av
|
|
|
135
154
|
await page.goto("/account/profile?returnTo=/home");
|
|
136
155
|
const name = page.getByLabel("Display name");
|
|
137
156
|
await expect(name).toHaveValue("Ada");
|
|
138
|
-
await expect(page.
|
|
157
|
+
await expect(page.getByTestId("account-email")).toContainText("ada@example.com");
|
|
158
|
+
await expect(page.getByRole("textbox", { name: "Email" })).toHaveCount(0);
|
|
139
159
|
await expect(page.getByRole("link", { name: "Done" })).toHaveAttribute("href", "/home");
|
|
140
160
|
await expect(page.getByTestId("jskit-shell-back")).toHaveCount(0);
|
|
141
161
|
// The app bar's title is the page's one h1.
|
|
142
162
|
await expect(page.getByRole("heading", { level: 1 })).toHaveText("Account settings");
|
|
143
163
|
|
|
144
164
|
await name.fill(" Ada Lovelace ");
|
|
145
|
-
await page
|
|
165
|
+
await barSave(page, "Save profile").click();
|
|
146
166
|
await expect.poll(() => lastReport(page)).toBe("Profile updated.");
|
|
147
167
|
await expect(name).toHaveValue("Ada Lovelace");
|
|
148
168
|
const saved = api.requests.find((request) => request.key === "PATCH /api/settings/profile");
|
|
@@ -150,7 +170,7 @@ test("the profile section loads, saves, shows a refused field and removes the av
|
|
|
150
170
|
assert.equal(saved.body.data.type, "user-profiles");
|
|
151
171
|
|
|
152
172
|
await name.fill("Taken");
|
|
153
|
-
await page
|
|
173
|
+
await barSave(page, "Save profile").click();
|
|
154
174
|
await expect(page.getByText("Name is taken.")).toBeVisible();
|
|
155
175
|
// A new error array on every render keeps Vuetify's form updating past Vue's limit, which shows here as a page error.
|
|
156
176
|
assert.deepEqual(api.errors, []);
|
|
@@ -159,14 +179,17 @@ test("the profile section loads, saves, shows a refused field and removes the av
|
|
|
159
179
|
await expect(page.getByRole("button", { name: "Remove avatar" })).toHaveCount(0);
|
|
160
180
|
await expect.poll(() => lastReport(page)).toBe("Avatar removed.");
|
|
161
181
|
|
|
182
|
+
// Done with the refused name still unsaved asks first; discarding it leaves.
|
|
162
183
|
await page.getByRole("link", { name: "Done" }).click();
|
|
184
|
+
await discardQuestion(page).getByRole("button", { name: "Discard" }).click();
|
|
163
185
|
await expect(page.getByTestId("home")).toBeVisible();
|
|
164
186
|
|
|
165
|
-
//
|
|
187
|
+
// On a wide window the list's own page shows the first section beside the list, as that section's page does, and
|
|
188
|
+
// its bar is the same: no Up, and Done returns to returnTo.
|
|
166
189
|
await page.goto("/account?returnTo=/home");
|
|
167
190
|
await expect(page.getByLabel("Display name")).toHaveValue("Ada");
|
|
168
|
-
await expect(page.getByTestId("jskit-shell-back")).
|
|
169
|
-
await expect(page.getByRole("link", { name: "Done" })).
|
|
191
|
+
await expect(page.getByTestId("jskit-shell-back")).toHaveCount(0);
|
|
192
|
+
await expect(page.getByRole("link", { name: "Done" })).toHaveAttribute("href", "/home");
|
|
170
193
|
await finish(api);
|
|
171
194
|
});
|
|
172
195
|
|
|
@@ -186,14 +209,15 @@ test("settings read again keep an unsaved display name, take the rest, and say w
|
|
|
186
209
|
const { page } = api;
|
|
187
210
|
await page.goto("/account/profile");
|
|
188
211
|
const name = page.getByLabel("Display name");
|
|
189
|
-
|
|
212
|
+
// The email is a value to read, which the sign-in account manages: the read shows the server's.
|
|
213
|
+
const email = page.getByTestId("account-email");
|
|
190
214
|
await expect(name).toHaveValue("Ada");
|
|
191
215
|
|
|
192
216
|
await name.fill("Ada Lovelace");
|
|
193
217
|
current = settings({ profile: { ...current.profile, displayName: "Countess Ada", email: "countess@example.com" } });
|
|
194
218
|
await page.evaluate(() => window.dispatchEvent(new Event("visibilitychange")));
|
|
195
219
|
|
|
196
|
-
await expect(email).
|
|
220
|
+
await expect(email).toContainText("countess@example.com");
|
|
197
221
|
await expect(name).toHaveValue("Ada Lovelace");
|
|
198
222
|
const notice = page.locator(".account-settings-section").getByRole("status");
|
|
199
223
|
await expect(notice).toContainText("Display name changed to “Countess Ada” while you were editing.");
|
|
@@ -201,7 +225,7 @@ test("settings read again keep an unsaved display name, take the rest, and say w
|
|
|
201
225
|
await expect(notice.getByRole("button")).toHaveCount(0);
|
|
202
226
|
await expect(name).toHaveValue("Ada Lovelace");
|
|
203
227
|
|
|
204
|
-
await page
|
|
228
|
+
await barSave(page, "Save profile").click();
|
|
205
229
|
await expect.poll(() => lastReport(page)).toBe("Profile updated.");
|
|
206
230
|
const saved = api.requests.find((request) => request.key === "PATCH /api/settings/profile");
|
|
207
231
|
assert.deepEqual(saved.body.data.attributes, { displayName: "Ada Lovelace" });
|
|
@@ -209,9 +233,10 @@ test("settings read again keep an unsaved display name, take the rest, and say w
|
|
|
209
233
|
await finish(api);
|
|
210
234
|
});
|
|
211
235
|
|
|
212
|
-
// Material 3's list-detail layout: a phone shows the section list or one section, and
|
|
213
|
-
// the list and from the list to home; a wide window shows the
|
|
214
|
-
|
|
236
|
+
// Material 3's list-detail layout: a phone shows the section list or one section, and the bar's leading button (a
|
|
237
|
+
// form section's close, X) returns from the section to the list and Up from the list to home; a wide window shows the
|
|
238
|
+
// list beside the open section, with no way back to the list in the bar.
|
|
239
|
+
test("a phone shows the section list and one section at a time, and the bar returns to the list", options, async () => {
|
|
215
240
|
const api = await openApp({ viewport: { width: 390, height: 844 } });
|
|
216
241
|
const { page } = api;
|
|
217
242
|
const up = page.getByTestId("jskit-shell-back");
|
|
@@ -223,18 +248,18 @@ test("a phone shows the section list and one section at a time, and Up returns t
|
|
|
223
248
|
|
|
224
249
|
await page.getByRole("link", { name: "Preferences" }).click();
|
|
225
250
|
await page.waitForURL("**/account/preferences");
|
|
226
|
-
await expect(page
|
|
251
|
+
await expect(barSave(page, "Save preferences")).toBeVisible();
|
|
227
252
|
await expect(sectionLinks.first()).toBeHidden();
|
|
228
253
|
await expect(page.getByRole("link", { name: "Done" })).toHaveCount(0);
|
|
229
254
|
|
|
230
255
|
await up.click();
|
|
231
256
|
await page.waitForURL((url) => url.pathname === "/account");
|
|
232
257
|
await expect(sectionLinks.first()).toBeVisible();
|
|
233
|
-
await expect(page
|
|
258
|
+
await expect(barSave(page, "Save preferences")).toHaveCount(0);
|
|
234
259
|
|
|
235
260
|
// A section opened from a pasted link has the list as its parent too.
|
|
236
261
|
await page.goto("/account/notifications");
|
|
237
|
-
await expect(page
|
|
262
|
+
await expect(barSave(page, "Save notifications")).toBeVisible();
|
|
238
263
|
await up.click();
|
|
239
264
|
await page.waitForURL((url) => url.pathname === "/account");
|
|
240
265
|
await up.click();
|
|
@@ -245,15 +270,119 @@ test("a phone shows the section list and one section at a time, and Up returns t
|
|
|
245
270
|
await wide.page.goto("/account");
|
|
246
271
|
await expect(wide.page.getByRole("link", { name: "Preferences" })).toBeVisible();
|
|
247
272
|
await expect(wide.page.getByLabel("Display name")).toBeVisible();
|
|
248
|
-
|
|
273
|
+
// The open row is Profile's: its name is its title, and the line under it its description.
|
|
274
|
+
await expect(wide.page.locator(".settings-section-list__item.v-list-item--active")).toHaveAccessibleName("Profile");
|
|
249
275
|
await wide.page.getByRole("link", { name: "Preferences" }).click();
|
|
250
276
|
await wide.page.waitForURL("**/account/preferences");
|
|
251
277
|
await expect(wide.page.getByRole("link", { name: "Profile" })).toBeVisible();
|
|
252
|
-
await expect(wide.page
|
|
278
|
+
await expect(barSave(wide.page, "Save preferences")).toBeVisible();
|
|
253
279
|
await expect(wide.page.getByTestId("jskit-shell-back")).toHaveCount(0);
|
|
254
280
|
await finish(wide);
|
|
255
281
|
});
|
|
256
282
|
|
|
283
|
+
// A section's form is an edit form: the app bar's Up arrow is its close (X), Cancel, as the guide's forms have; Save
|
|
284
|
+
// says what it saves and stays off until something changes; and leaving unsaved edits (the close, the browser's Back,
|
|
285
|
+
// another section, closing the tab) asks first. A section that is no form keeps the Up arrow.
|
|
286
|
+
test("a section's form closes with the bar's X, saves only a change, and asks before unsaved edits are left", options, async () => {
|
|
287
|
+
const api = await openApp({ viewport: { width: 390, height: 844 } });
|
|
288
|
+
const { page } = api;
|
|
289
|
+
const close = page.getByTestId("jskit-shell-back");
|
|
290
|
+
const question = discardQuestion(page);
|
|
291
|
+
await page.goto("/account");
|
|
292
|
+
await page.getByRole("link", { name: "Profile" }).click();
|
|
293
|
+
await page.waitForURL("**/account/profile");
|
|
294
|
+
const name = page.getByLabel("Display name");
|
|
295
|
+
const save = barSave(page, "Save profile");
|
|
296
|
+
await expect(name).toHaveValue("Ada");
|
|
297
|
+
await expect(close).toHaveAttribute("data-action", "close");
|
|
298
|
+
await expect(close).toHaveAccessibleName("Cancel");
|
|
299
|
+
await expect(save).toBeDisabled();
|
|
300
|
+
await name.fill("Ada L");
|
|
301
|
+
await expect(save).toBeEnabled();
|
|
302
|
+
await name.fill("Ada");
|
|
303
|
+
await expect(save).toBeDisabled();
|
|
304
|
+
|
|
305
|
+
// The close with an edit asks; keeping on editing stays, with the edit.
|
|
306
|
+
await name.fill("Ada L");
|
|
307
|
+
await close.click();
|
|
308
|
+
await expect(question).toBeVisible();
|
|
309
|
+
await expect(question).toContainText("Your changes to Profile will be lost.");
|
|
310
|
+
// The supporting text sits 16dp under the headline, as in a Material 3 dialog. Measured by layout offsets within the
|
|
311
|
+
// card, which the dialog's opening scale does not change, as it does the boxes on screen.
|
|
312
|
+
const textGap = await question.evaluate((dialog) => {
|
|
313
|
+
const title = dialog.querySelector(".v-card-title");
|
|
314
|
+
const text = dialog.querySelector(".v-card-text p");
|
|
315
|
+
const titleBottom = title.offsetTop + title.offsetHeight - Number.parseFloat(window.getComputedStyle(title).paddingBottom);
|
|
316
|
+
let textTop = 0;
|
|
317
|
+
for (let node = text; node && node !== title.offsetParent; node = node.offsetParent) {
|
|
318
|
+
textTop += node.offsetTop;
|
|
319
|
+
}
|
|
320
|
+
return textTop - titleBottom;
|
|
321
|
+
});
|
|
322
|
+
assert.equal(textGap, 16, `the question's text is ${textGap}px under its headline`);
|
|
323
|
+
await question.getByRole("button", { name: "Keep editing" }).click();
|
|
324
|
+
await expect(question).toHaveCount(0);
|
|
325
|
+
await expect(page).toHaveURL(/\/account\/profile$/u);
|
|
326
|
+
await expect(name).toHaveValue("Ada L");
|
|
327
|
+
|
|
328
|
+
// The browser's Back asks too; discarding leaves for the list, and the form has the saved name again.
|
|
329
|
+
await page.goBack();
|
|
330
|
+
await expect(question).toBeVisible();
|
|
331
|
+
await question.getByRole("button", { name: "Discard" }).click();
|
|
332
|
+
await page.waitForURL((url) => url.pathname === "/account");
|
|
333
|
+
await expect(page.locator(".settings-account__name")).toHaveText("Ada");
|
|
334
|
+
await page.getByRole("link", { name: "Profile" }).click();
|
|
335
|
+
await expect(name).toHaveValue("Ada");
|
|
336
|
+
|
|
337
|
+
// With nothing changed the close leaves at once.
|
|
338
|
+
await close.click();
|
|
339
|
+
await page.waitForURL((url) => url.pathname === "/account");
|
|
340
|
+
await expect(question).toHaveCount(0);
|
|
341
|
+
|
|
342
|
+
// Sign-in methods is no form: its way back is the Up arrow.
|
|
343
|
+
await page.getByRole("link", { name: "Sign-in methods" }).click();
|
|
344
|
+
await page.waitForURL("**/account/sign-in-methods");
|
|
345
|
+
await expect(close).toHaveAttribute("data-action", "up");
|
|
346
|
+
await finish(api);
|
|
347
|
+
|
|
348
|
+
// Beside the list, the account's header shows the saved name while the form holds an unsaved one.
|
|
349
|
+
const wide = await openApp();
|
|
350
|
+
await wide.page.goto("/account/profile");
|
|
351
|
+
const account = wide.page.getByTestId("account-settings-account");
|
|
352
|
+
await wide.page.getByLabel("Display name").fill("Grace Hopper");
|
|
353
|
+
await expect(account.locator(".settings-account__name")).toHaveText("Ada");
|
|
354
|
+
await expect(account.locator(".v-avatar")).toHaveText("A");
|
|
355
|
+
await wide.page.getByLabel("Display name").fill("Ada");
|
|
356
|
+
|
|
357
|
+
// Choosing another section asks too, and so does closing the tab.
|
|
358
|
+
await wide.page.goto("/account/notifications");
|
|
359
|
+
const saveNotifications = barSave(wide.page, "Save notifications");
|
|
360
|
+
const accountActivity = wide.page.getByLabel("Account activity alerts");
|
|
361
|
+
await expect(saveNotifications).toBeDisabled();
|
|
362
|
+
await accountActivity.click();
|
|
363
|
+
await expect(saveNotifications).toBeEnabled();
|
|
364
|
+
await wide.page.getByRole("link", { name: "Preferences" }).click();
|
|
365
|
+
const wideQuestion = discardQuestion(wide.page);
|
|
366
|
+
await expect(wideQuestion).toBeVisible();
|
|
367
|
+
await wideQuestion.getByRole("button", { name: "Keep editing" }).click();
|
|
368
|
+
await expect(wide.page).toHaveURL(/\/account\/notifications$/u);
|
|
369
|
+
await expect(accountActivity).toBeChecked();
|
|
370
|
+
|
|
371
|
+
// Closing or reloading the tab: the page has the browser ask (it cancels beforeunload) while a form has unsaved
|
|
372
|
+
// edits, and lets it go once none has. The browser's own question can't show here: headless Chromium 149 closes a
|
|
373
|
+
// page without it, even a bare page whose handler asks as Playwright's own test page does (probed 1 Dec).
|
|
374
|
+
const unloadAsks = () => wide.page.evaluate(() => {
|
|
375
|
+
const event = new Event("beforeunload", { cancelable: true });
|
|
376
|
+
window.dispatchEvent(event);
|
|
377
|
+
return event.defaultPrevented;
|
|
378
|
+
});
|
|
379
|
+
assert.equal(await unloadAsks(), true);
|
|
380
|
+
await accountActivity.click();
|
|
381
|
+
await expect(saveNotifications).toBeDisabled();
|
|
382
|
+
assert.equal(await unloadAsks(), false);
|
|
383
|
+
await finish(wide);
|
|
384
|
+
});
|
|
385
|
+
|
|
257
386
|
test("saved preferences follow into the theme, the stored preference and the account locale", options, async () => {
|
|
258
387
|
const api = await openApp({
|
|
259
388
|
routes: {
|
|
@@ -270,7 +399,8 @@ test("saved preferences follow into the theme, the stored preference and the acc
|
|
|
270
399
|
|
|
271
400
|
await page.getByRole("link", { name: "Preferences" }).click();
|
|
272
401
|
await page.waitForURL("**/account/preferences");
|
|
273
|
-
await page
|
|
402
|
+
await choose(page, "Theme", "Light");
|
|
403
|
+
await barSave(page, "Save preferences").click();
|
|
274
404
|
await expect.poll(() => lastReport(page)).toBe("Preferences updated.");
|
|
275
405
|
const saved = api.requests.find((request) => request.key === "PATCH /api/settings/preferences");
|
|
276
406
|
assert.equal(saved.body.data.type, "user-preferences");
|
|
@@ -292,7 +422,8 @@ test("a refused preference shows its message", options, async () => {
|
|
|
292
422
|
});
|
|
293
423
|
const { page } = api;
|
|
294
424
|
await page.goto("/account/preferences");
|
|
295
|
-
await page
|
|
425
|
+
await choose(page, "Theme", "Light");
|
|
426
|
+
await barSave(page, "Save preferences").click();
|
|
296
427
|
await expect(page.getByText("Theme is not allowed.")).toBeVisible();
|
|
297
428
|
// The old error array looped here for seconds before Vue gave up, so the page must also stay idle.
|
|
298
429
|
const idle = await idleSecond(page);
|
|
@@ -313,10 +444,11 @@ test("notifications save, and sign-in methods link through the provider and unli
|
|
|
313
444
|
});
|
|
314
445
|
const { page } = api;
|
|
315
446
|
await page.goto("/account/notifications");
|
|
316
|
-
await page.
|
|
447
|
+
await page.getByLabel("Account activity alerts").click();
|
|
448
|
+
await barSave(page, "Save notifications").click();
|
|
317
449
|
await expect.poll(() => lastReport(page)).toBe("Notification settings updated.");
|
|
318
450
|
const saved = api.requests.find((request) => request.key === "PATCH /api/settings/notifications");
|
|
319
|
-
assert.deepEqual(saved.body.data.attributes, { productUpdates: true, accountActivity:
|
|
451
|
+
assert.deepEqual(saved.body.data.attributes, { productUpdates: true, accountActivity: true, securityAlerts: true });
|
|
320
452
|
|
|
321
453
|
await page.getByRole("link", { name: "Sign-in methods" }).click();
|
|
322
454
|
await page.getByRole("button", { name: "Unlink" }).click();
|
|
@@ -330,6 +462,207 @@ test("notifications save, and sign-in methods link through the provider and unli
|
|
|
330
462
|
|
|
331
463
|
// Material 3 type and layout: the section list's labels and the buttons are label-large (14px/500), a switch sits
|
|
332
464
|
// after its label at the row's end, and each field has the form's full width, so a long email shows whole.
|
|
465
|
+
// Each section in the list is its title after a tonal icon tile, the placement's icon or users-web's for its own
|
|
466
|
+
// sections, on every window: the list beside the open section on wide windows and the list alone on a phone. The open
|
|
467
|
+
// section is told by more than its pill's colour: its label is bold and its tile turns secondary.
|
|
468
|
+
test("the section list heads each section with its icon on a tonal tile, at every width", options, async () => {
|
|
469
|
+
const symbolPath = (alias) => materialSymbols[alias].slice("svg:".length);
|
|
470
|
+
for (const viewport of [{ width: 390, height: 844 }, { width: 1280, height: 900 }]) {
|
|
471
|
+
const at = `${viewport.width}px`;
|
|
472
|
+
const api = await openApp({ viewport });
|
|
473
|
+
const { page } = api;
|
|
474
|
+
await page.goto("/account");
|
|
475
|
+
await expect(page.getByRole("link", { name: "Preferences" }), at).toBeVisible();
|
|
476
|
+
await page.evaluate(() => window.accountFixture.placeSection());
|
|
477
|
+
await expect(page.getByRole("link", { name: "Extra" }), at).toBeVisible();
|
|
478
|
+
const tiles = await page.locator(".settings-section-list__item").evaluateAll((items) => items.map((item) => {
|
|
479
|
+
const tile = item.querySelector(".v-list-item__prepend .v-avatar");
|
|
480
|
+
// A role as the item's theme draws it (these settings choose the dark theme), read from a new element each time:
|
|
481
|
+
// recolouring one element would read its colour transition's start.
|
|
482
|
+
const role = (name) => {
|
|
483
|
+
const probe = item.appendChild(document.createElement("span"));
|
|
484
|
+
probe.style.color = `rgb(var(--v-theme-${name}))`;
|
|
485
|
+
const color = getComputedStyle(probe).color;
|
|
486
|
+
probe.remove();
|
|
487
|
+
return color;
|
|
488
|
+
};
|
|
489
|
+
const active = item.classList.contains("v-list-item--active");
|
|
490
|
+
const container = active ? "rgba(0, 0, 0, 0)" : role("primary-container");
|
|
491
|
+
const onContainer = role(active ? "on-secondary-container" : "on-primary-container");
|
|
492
|
+
return {
|
|
493
|
+
title: item.querySelector(".v-list-item-title").textContent.trim(),
|
|
494
|
+
summary: item.querySelector(".v-list-item-subtitle")?.textContent.trim() || "",
|
|
495
|
+
chevron: item.querySelectorAll(".v-list-item__append .v-icon").length,
|
|
496
|
+
icon: tile?.querySelector(".v-icon path")?.getAttribute("d") || "",
|
|
497
|
+
tonal: Boolean(tile) && getComputedStyle(tile).backgroundColor === container,
|
|
498
|
+
iconColor: Boolean(tile) && getComputedStyle(tile.querySelector(".v-icon")).color === onContainer,
|
|
499
|
+
weight: getComputedStyle(item.querySelector(".v-list-item-title")).fontWeight,
|
|
500
|
+
active
|
|
501
|
+
};
|
|
502
|
+
}));
|
|
503
|
+
assert.deepEqual(tiles, [
|
|
504
|
+
["Profile", "person", "Name, avatar and email"],
|
|
505
|
+
["Extra", "settings", ""],
|
|
506
|
+
["Preferences", "tune", "Theme, language and formats"],
|
|
507
|
+
["Notifications", "notifications", "Updates and alerts we send you"],
|
|
508
|
+
["Sign-in methods", "key", "Password and linked accounts"]
|
|
509
|
+
].map(([title, alias, summary]) => {
|
|
510
|
+
// A wide window opens the first section beside the list; a phone shows the list alone, each row opening a page.
|
|
511
|
+
const active = viewport.width >= 840 && title === "Profile";
|
|
512
|
+
const chevron = viewport.width >= 840 ? 0 : 1;
|
|
513
|
+
return { title, summary, chevron, icon: symbolPath(alias), tonal: true, iconColor: true, weight: active ? "700" : "400", active };
|
|
514
|
+
}), at);
|
|
515
|
+
// Material 3's list item: the title in body-large, the summary under it in body-medium, a two-line row 72dp tall.
|
|
516
|
+
const rows = await page.locator(".settings-section-list__item").evaluateAll((items) => items.map((item) => {
|
|
517
|
+
const subtitle = item.querySelector(".v-list-item-subtitle");
|
|
518
|
+
return {
|
|
519
|
+
title: getComputedStyle(item.querySelector(".v-list-item-title")).fontSize,
|
|
520
|
+
summary: subtitle ? getComputedStyle(subtitle).fontSize : "",
|
|
521
|
+
tall: Math.round(item.getBoundingClientRect().height) >= (subtitle ? 72 : 56)
|
|
522
|
+
};
|
|
523
|
+
}));
|
|
524
|
+
assert.deepEqual(rows, tiles.map((tile) => ({ title: "16px", summary: tile.summary ? "14px" : "", tall: true })), at);
|
|
525
|
+
// The tile and the summary are the item's decoration and description: each link's name is its title alone.
|
|
526
|
+
const signInMethods = page.getByRole("link", { name: "Sign-in methods", exact: true });
|
|
527
|
+
await expect(signInMethods, at).toBeVisible();
|
|
528
|
+
await expect(signInMethods, at).toHaveAccessibleDescription("Password and linked accounts");
|
|
529
|
+
await finish(api);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// The page says whose account it is: the list is headed by the account's avatar, in a container colour, its name and
|
|
534
|
+
// its email, with no line of copy above it. The profile section's avatar takes the same colour, its fields their
|
|
535
|
+
// leading icons, and the email, which the sign-in account manages, is a detail row to read; no developer caption shows.
|
|
536
|
+
test("the section list is headed by the account, and the profile section's avatar and fields carry their colour and icons", options, async () => {
|
|
537
|
+
const symbolPath = (alias) => materialSymbols[alias].slice("svg:".length);
|
|
538
|
+
for (const viewport of [{ width: 390, height: 844 }, { width: 1280, height: 900 }]) {
|
|
539
|
+
const at = `${viewport.width}px`;
|
|
540
|
+
const api = await openApp({ viewport });
|
|
541
|
+
const { page } = api;
|
|
542
|
+
await page.goto("/account");
|
|
543
|
+
const account = page.getByTestId("account-settings-account");
|
|
544
|
+
await expect(account, at).toContainText("Ada");
|
|
545
|
+
await expect(account, at).toContainText("ada@example.com");
|
|
546
|
+
const header = await account.evaluate((element) => {
|
|
547
|
+
const role = (name) => {
|
|
548
|
+
const probe = element.appendChild(document.createElement("span"));
|
|
549
|
+
probe.style.color = `rgb(var(--v-theme-${name}))`;
|
|
550
|
+
const color = getComputedStyle(probe).color;
|
|
551
|
+
probe.remove();
|
|
552
|
+
return color;
|
|
553
|
+
};
|
|
554
|
+
const list = document.querySelector(".settings-section-list").getBoundingClientRect();
|
|
555
|
+
const tile = document.querySelector(".settings-section-list__item .v-list-item__prepend .v-avatar").getBoundingClientRect();
|
|
556
|
+
const rowTitle = document.querySelector(".settings-section-list__item .v-list-item-title").getBoundingClientRect();
|
|
557
|
+
const avatar = element.querySelector(".v-avatar").getBoundingClientRect();
|
|
558
|
+
return {
|
|
559
|
+
avatar: getComputedStyle(element.querySelector(".v-avatar")).backgroundColor === role("primary-container"),
|
|
560
|
+
initials: element.querySelector(".v-avatar").textContent.trim(),
|
|
561
|
+
above: element.getBoundingClientRect().bottom <= list.top + 1,
|
|
562
|
+
nameSize: getComputedStyle(element.querySelector(".settings-account__name")).fontSize,
|
|
563
|
+
// The avatar is a tile's size, and the name and email start where the rows' titles do.
|
|
564
|
+
avatarSize: Math.round(avatar.width),
|
|
565
|
+
lined: Math.round(avatar.left) === Math.round(tile.left),
|
|
566
|
+
textLined: Math.round(element.querySelector(".settings-account__name").getBoundingClientRect().left) === Math.round(rowTitle.left),
|
|
567
|
+
tileLeft: Math.round(tile.left)
|
|
568
|
+
};
|
|
569
|
+
});
|
|
570
|
+
assert.deepEqual(header, {
|
|
571
|
+
avatar: true,
|
|
572
|
+
initials: "A",
|
|
573
|
+
above: true,
|
|
574
|
+
nameSize: "24px",
|
|
575
|
+
avatarSize: 40,
|
|
576
|
+
lined: true,
|
|
577
|
+
textLined: true,
|
|
578
|
+
tileLeft: viewport.width < 600 ? 16 : header.tileLeft
|
|
579
|
+
}, at);
|
|
580
|
+
await expect(page.getByText("Global profile, preferences, notifications, and account controls."), at).toHaveCount(0);
|
|
581
|
+
await finish(api);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
for (const viewport of [{ width: 390, height: 844 }, { width: 768, height: 1024 }, { width: 1280, height: 900 }]) {
|
|
585
|
+
const at = `${viewport.width}px`;
|
|
586
|
+
const api = await openApp({ viewport });
|
|
587
|
+
const { page } = api;
|
|
588
|
+
await page.goto("/account/profile");
|
|
589
|
+
await expect(page.getByLabel("Display name", { exact: true }), at).toHaveValue("Ada");
|
|
590
|
+
const detail = page.locator(".settings-section-detail");
|
|
591
|
+
// One pane (a phone or a tablet): the bar's title says where the person is, "Profile", with Up to the list, and
|
|
592
|
+
// the section adds no heading of its own. Beside the list, the bar says "Account settings" and the open section is
|
|
593
|
+
// headed by its tile and title.
|
|
594
|
+
const twoPane = viewport.width >= 840;
|
|
595
|
+
await expect(page.getByRole("heading", { level: 1 }), at).toHaveText(twoPane ? "Account settings" : "Profile");
|
|
596
|
+
await expect(detail.getByRole("heading", { level: 2, name: "Profile" }), at).toHaveCount(twoPane ? 1 : 0);
|
|
597
|
+
const profile = await detail.evaluate((section, twoPane) => {
|
|
598
|
+
const role = (name) => {
|
|
599
|
+
const probe = section.appendChild(document.createElement("span"));
|
|
600
|
+
probe.style.color = `rgb(var(--v-theme-${name}))`;
|
|
601
|
+
const color = getComputedStyle(probe).color;
|
|
602
|
+
probe.remove();
|
|
603
|
+
return color;
|
|
604
|
+
};
|
|
605
|
+
const heading = section.querySelector("[data-testid='account-settings-section-heading']");
|
|
606
|
+
const field = [...section.querySelectorAll(".v-input")]
|
|
607
|
+
.find((input) => input.querySelector("label")?.textContent.trim() === "Display name");
|
|
608
|
+
const email = section.querySelector("[data-testid='account-email']");
|
|
609
|
+
const avatarButton = [...section.querySelectorAll("button")].find((button) => button.textContent.trim() === "Change avatar");
|
|
610
|
+
const fieldBox = field.querySelector(".v-field").getBoundingClientRect();
|
|
611
|
+
const fieldIcon = field.querySelector(".v-field__prepend-inner .v-icon").getBoundingClientRect();
|
|
612
|
+
const input = field.querySelector("input");
|
|
613
|
+
const inputText = input.getBoundingClientRect().left + Number.parseFloat(getComputedStyle(input).paddingInlineStart);
|
|
614
|
+
const lines = [...email.querySelectorAll(".account-email__text > *")];
|
|
615
|
+
const accountAvatar = document.querySelector("[data-testid='account-settings-account'] .v-avatar")?.getBoundingClientRect();
|
|
616
|
+
const listLeft = document.querySelector(".settings-section-list")?.getBoundingClientRect().left;
|
|
617
|
+
return {
|
|
618
|
+
headingTile: heading ? getComputedStyle(heading.querySelector(".v-avatar")).backgroundColor === role("primary-container") : null,
|
|
619
|
+
avatar:
|
|
620
|
+
getComputedStyle(section.querySelector(".account-settings-section .v-avatar")).backgroundColor === role("primary-container"),
|
|
621
|
+
avatarButton: Boolean(avatarButton) && getComputedStyle(avatarButton).backgroundColor === role("secondary-container"),
|
|
622
|
+
displayName: field?.querySelector(".v-field__prepend-inner .v-icon path")?.getAttribute("d") || "",
|
|
623
|
+
fieldHeight: Math.round(fieldBox.height),
|
|
624
|
+
email: email?.querySelector(".v-icon path")?.getAttribute("d") || "",
|
|
625
|
+
// A detail row: its value is its title, in body-large; "Email" and who manages it are its quieter lines.
|
|
626
|
+
emailLines: lines.map((line) => [line.textContent.trim(), getComputedStyle(line).fontSize]),
|
|
627
|
+
// The row's icon and text on the field's keylines above it.
|
|
628
|
+
emailLined: [
|
|
629
|
+
Math.round(email.querySelector(".v-icon").getBoundingClientRect().left - fieldIcon.left),
|
|
630
|
+
Math.round(lines[0].getBoundingClientRect().left - inputText)
|
|
631
|
+
],
|
|
632
|
+
fieldGap: Math.round(email.getBoundingClientRect().top - field.getBoundingClientRect().bottom),
|
|
633
|
+
// One pane: the form starts at the window's margin, no padding of its own on top of it. Beside the list: the
|
|
634
|
+
// open section's top lines up with the account's, its right margin is the list's left one, and its form keeps a
|
|
635
|
+
// readable width.
|
|
636
|
+
start: twoPane ? null : Math.round(fieldBox.left),
|
|
637
|
+
topsLined: heading && accountAvatar ? Math.round(heading.querySelector(".v-avatar").getBoundingClientRect().top) === Math.round(accountAvatar.top) : null,
|
|
638
|
+
margins: heading ? Math.round(window.innerWidth - section.getBoundingClientRect().right) === Math.round(listLeft) : null,
|
|
639
|
+
formWidth: heading ? Math.round(fieldBox.width) <= 600 : null
|
|
640
|
+
};
|
|
641
|
+
}, twoPane);
|
|
642
|
+
assert.ok(profile.fieldGap >= 0 && profile.fieldGap <= 8, `${at}: only the message line under Display name: ${profile.fieldGap}px`);
|
|
643
|
+
delete profile.fieldGap;
|
|
644
|
+
assert.deepEqual(profile, {
|
|
645
|
+
headingTile: twoPane ? true : null,
|
|
646
|
+
avatar: true,
|
|
647
|
+
avatarButton: true,
|
|
648
|
+
displayName: symbolPath("person"),
|
|
649
|
+
fieldHeight: 56,
|
|
650
|
+
email: symbolPath("mail"),
|
|
651
|
+
emailLines: [["ada@example.com", "16px"], ["Email", "14px"], ["Managed by your sign-in account", "14px"]],
|
|
652
|
+
emailLined: [0, 0],
|
|
653
|
+
start: twoPane ? null : viewport.width < 600 ? 16 : 24,
|
|
654
|
+
topsLined: twoPane ? true : null,
|
|
655
|
+
margins: twoPane ? true : null,
|
|
656
|
+
formWidth: twoPane ? true : null
|
|
657
|
+
}, at);
|
|
658
|
+
await expect(page.getByRole("textbox", { name: "Email" }), at).toHaveCount(0);
|
|
659
|
+
await expect(page.getByText(/Preview size/u), at).toHaveCount(0);
|
|
660
|
+
await expect(barSave(page, "Save profile"), at).toBeVisible();
|
|
661
|
+
await expect(detail.getByRole("button", { name: /Save/u }), at).toHaveCount(0);
|
|
662
|
+
await finish(api);
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
|
|
333
666
|
test("account settings use Material 3 label type, trailing switches and full-width fields", options, async () => {
|
|
334
667
|
const email = "ada.lovelace.analytical.engine@difference-engine.example.com";
|
|
335
668
|
const api = await openApp({
|
|
@@ -337,13 +670,17 @@ test("account settings use Material 3 label type, trailing switches and full-wid
|
|
|
337
670
|
});
|
|
338
671
|
const { page } = api;
|
|
339
672
|
await page.goto("/account");
|
|
340
|
-
|
|
673
|
+
const shownEmail = page.getByTestId("account-email").getByText(email);
|
|
674
|
+
await expect(shownEmail).toBeVisible();
|
|
675
|
+
assert.equal(await shownEmail.evaluate((element) => element.scrollWidth <= element.clientWidth), true, "the email shows whole");
|
|
341
676
|
const type = (locator) => locator.evaluate((element) => {
|
|
342
677
|
const style = window.getComputedStyle(element);
|
|
343
678
|
return [style.fontSize, style.fontWeight];
|
|
344
679
|
});
|
|
345
|
-
|
|
346
|
-
|
|
680
|
+
const label = page.locator(".settings-section-list__item:not(.v-list-item--active) .v-list-item-title").first();
|
|
681
|
+
// A row's title is a list item's body-large (its summary body-medium); the bar's Save is a button's label-large.
|
|
682
|
+
assert.deepEqual(await type(label), ["16px", "400"]);
|
|
683
|
+
assert.deepEqual(await type(barSave(page, "Save profile")), ["14px", "500"]);
|
|
347
684
|
const fields = await page.evaluate(() => {
|
|
348
685
|
const form = document.querySelector(".settings-section-detail form");
|
|
349
686
|
const width = (element) => Math.round(element.getBoundingClientRect().width);
|
|
@@ -352,7 +689,7 @@ test("account settings use Material 3 label type, trailing switches and full-wid
|
|
|
352
689
|
return { width: width(field), form: width(form), whole: input.scrollWidth <= input.clientWidth };
|
|
353
690
|
});
|
|
354
691
|
});
|
|
355
|
-
assert.ok(fields.length >=
|
|
692
|
+
assert.ok(fields.length >= 1, "the profile form has its fields");
|
|
356
693
|
for (const field of fields) {
|
|
357
694
|
assert.ok(field.width >= field.form - 48, `a field has the form's width: ${JSON.stringify(field)}`);
|
|
358
695
|
assert.equal(field.whole, true, `a field shows its value whole: ${JSON.stringify(field)}`);
|
|
@@ -390,9 +727,10 @@ test("each section stays busy until its save or removal answers", options, async
|
|
|
390
727
|
|
|
391
728
|
await page.goto("/account");
|
|
392
729
|
const name = page.getByLabel("Display name");
|
|
393
|
-
const saveProfile = page
|
|
730
|
+
const saveProfile = barSave(page, "Save profile");
|
|
394
731
|
const removeAvatar = page.getByRole("button", { name: "Remove avatar" });
|
|
395
732
|
await expect(name).toHaveValue("Ada");
|
|
733
|
+
await name.fill("Ada L");
|
|
396
734
|
await saveProfile.click();
|
|
397
735
|
await expect(saveProfile).toHaveClass(loading);
|
|
398
736
|
await expect(name).not.toBeEditable();
|
|
@@ -401,16 +739,20 @@ test("each section stays busy until its save or removal answers", options, async
|
|
|
401
739
|
await expect(saveProfile).not.toHaveClass(loading);
|
|
402
740
|
await expect(name).toBeEditable();
|
|
403
741
|
|
|
742
|
+
// An unsaved name waits for the avatar's removal to save.
|
|
743
|
+
await name.fill("Ada L");
|
|
404
744
|
await removeAvatar.click();
|
|
405
745
|
await expect(removeAvatar).toHaveClass(loading);
|
|
406
746
|
await expect(saveProfile).toBeDisabled();
|
|
407
747
|
answers.avatar.resolve(document(settings()));
|
|
408
748
|
await expect(removeAvatar).not.toHaveClass(loading);
|
|
409
749
|
await expect(saveProfile).toBeEnabled();
|
|
750
|
+
await name.fill("Ada");
|
|
410
751
|
|
|
411
752
|
await page.getByRole("link", { name: "Preferences" }).click();
|
|
412
|
-
const savePreferences = page
|
|
753
|
+
const savePreferences = barSave(page, "Save preferences");
|
|
413
754
|
const disabledFields = page.locator(".v-input--disabled");
|
|
755
|
+
await choose(page, "Theme", "Light");
|
|
414
756
|
await savePreferences.click();
|
|
415
757
|
await expect(savePreferences).toHaveClass(loading);
|
|
416
758
|
await expect(disabledFields).not.toHaveCount(0);
|
|
@@ -419,8 +761,9 @@ test("each section stays busy until its save or removal answers", options, async
|
|
|
419
761
|
await expect(disabledFields).toHaveCount(0);
|
|
420
762
|
|
|
421
763
|
await page.getByRole("link", { name: "Notifications" }).click();
|
|
422
|
-
const saveNotifications = page
|
|
764
|
+
const saveNotifications = barSave(page, "Save notifications");
|
|
423
765
|
const productUpdates = page.getByLabel("Product updates");
|
|
766
|
+
await page.getByLabel("Account activity alerts").click();
|
|
424
767
|
await saveNotifications.click();
|
|
425
768
|
await expect(saveNotifications).toHaveClass(loading);
|
|
426
769
|
await expect(productUpdates).toBeDisabled();
|
|
@@ -116,3 +116,60 @@ test("normalizeAccountSettingsSectionEntry keeps a message-key title for the hos
|
|
|
116
116
|
null
|
|
117
117
|
);
|
|
118
118
|
});
|
|
119
|
+
|
|
120
|
+
test("each section has its icon: the placement's own, else users-web's for its own sections, else a settings icon", () => {
|
|
121
|
+
const section = (value, icon) => ({ component: {}, props: { value, title: value, ...(icon === undefined ? {} : { icon }) } });
|
|
122
|
+
const resolved = resolveAccountSettingsSections([
|
|
123
|
+
section("profile"),
|
|
124
|
+
section("preferences"),
|
|
125
|
+
section("notifications"),
|
|
126
|
+
section("sign-in-methods"),
|
|
127
|
+
section("billing"),
|
|
128
|
+
section("invites", "$mail"),
|
|
129
|
+
section("security", " $lock ")
|
|
130
|
+
]);
|
|
131
|
+
assert.deepEqual(Object.fromEntries(resolved.map((entry) => [entry.value, entry.icon])), {
|
|
132
|
+
profile: "$person",
|
|
133
|
+
preferences: "$tune",
|
|
134
|
+
notifications: "$notifications",
|
|
135
|
+
"sign-in-methods": "$key",
|
|
136
|
+
billing: "$settings",
|
|
137
|
+
invites: "$mail",
|
|
138
|
+
security: "$lock"
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("a placement's own icon wins over users-web's for its own section", () => {
|
|
143
|
+
const entry = normalizeAccountSettingsSectionEntry({
|
|
144
|
+
component: {},
|
|
145
|
+
props: { value: "profile", title: "Profile", icon: "$accountCircle" }
|
|
146
|
+
});
|
|
147
|
+
assert.equal(entry.icon, "$accountCircle");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// A section's line under its title in the list says what it holds: the placement's own (plain text, a message key or
|
|
151
|
+
// { key, fallback }), else users-web's for its own sections, else none.
|
|
152
|
+
test("each section has its one-line summary: the placement's own, else users-web's for its own sections, else none", () => {
|
|
153
|
+
const section = (value, summary) => ({
|
|
154
|
+
component: {},
|
|
155
|
+
props: { value, title: value, ...(summary === undefined ? {} : { summary }) }
|
|
156
|
+
});
|
|
157
|
+
const resolved = resolveAccountSettingsSections([
|
|
158
|
+
section("profile"),
|
|
159
|
+
section("preferences"),
|
|
160
|
+
section("notifications"),
|
|
161
|
+
section("sign-in-methods"),
|
|
162
|
+
section("billing"),
|
|
163
|
+
section("invites", " People you invited "),
|
|
164
|
+
section("security", { key: "app.settings.security.summary", fallback: "Two-step sign-in" })
|
|
165
|
+
]);
|
|
166
|
+
assert.deepEqual(Object.fromEntries(resolved.map((entry) => [entry.value, entry.summary])), {
|
|
167
|
+
profile: "jskit.users.accountSettings.summary.profile",
|
|
168
|
+
preferences: "jskit.users.accountSettings.summary.preferences",
|
|
169
|
+
notifications: "jskit.users.accountSettings.summary.notifications",
|
|
170
|
+
"sign-in-methods": "jskit.users.accountSettings.summary.signInMethods",
|
|
171
|
+
billing: "",
|
|
172
|
+
invites: "People you invited",
|
|
173
|
+
security: { key: "app.settings.security.summary", fallback: "Two-step sign-in" }
|
|
174
|
+
});
|
|
175
|
+
});
|