flotilla/e2e/specs/settings.spec.ts

430 lines
15 KiB
TypeScript
Raw Normal View History

2026-08-20 20:33:20 +00:00
import {MINUTE} from "@welshman/lib"
import type {Locator, Page} from "@playwright/test"
import {dialog, expect, roomPath, settingToggle, test, toast, topDialog, users} from "../harness"
2026-08-20 20:33:20 +00:00
// A handle to a seeded event, which only reads once seed() has drained its queue.
type Seeded = {readonly id: string}
// The relay picker is pushed over the list modal, so it is the only dialog in the dom.
const relayPicker = (page: Page) => topDialog(page)
2026-08-20 20:33:20 +00:00
const relayCard = (scope: Locator, name: string) => scope.locator(".card").filter({hasText: name})
// A toast clears after five seconds, which outlasts the batch a saved setting reaches disk in.
const waitForToastToClear = (page: Page) => expect(toast(page)).toHaveCount(0)
2026-08-20 20:33:20 +00:00
// A Field lays its slider out under the row holding the label and the current value.
const requestsCard = (page: Page) => page.locator(".card").filter({hasText: "Message Requests"})
const requestSliders = (page: Page) => requestsCard(page).locator('input[type="range"]')
2026-09-09 01:07:48 +00:00
test("US-084 block a relay you never want used", async ({seed, as}) => {
2026-08-20 20:33:20 +00:00
await seed(({relay, user}) => {
const space = relay("space")
// A relay is offered as a suggestion once its nip-11 document has been fetched.
2026-08-20 20:33:20 +00:00
relay("other")
space.room("general", {name: "General"})
space.join(user.bob, "general")
space.relayList(user.bob)
2026-08-20 20:33:20 +00:00
})
2026-09-09 01:07:48 +00:00
const page = await as(users.bob, "/settings/privacy")
const blocked = page.getByRole("button", {name: /Blocked$/})
2026-08-20 20:33:20 +00:00
2026-09-09 01:07:48 +00:00
await expect(blocked).toContainText("0 Blocked")
2026-08-20 20:33:20 +00:00
2026-09-09 01:07:48 +00:00
await blocked.click()
2026-08-20 20:33:20 +00:00
await expect(dialog(page, "Blocked Relays").getByText("No relay selections found.")).toBeVisible()
2026-08-20 20:33:20 +00:00
await dialog(page, "Blocked Relays").getByRole("button", {name: "Add Relays"}).click()
2026-08-20 20:33:20 +00:00
await relayCard(relayPicker(page), "other.test").getByRole("button", {name: "Add Relay"}).click()
await page.getByRole("button", {name: "Done"}).click()
await expect(dialog(page, "Blocked Relays").getByText("other.test")).toBeVisible()
2026-08-20 20:33:20 +00:00
await dialog(page, "Blocked Relays").getByRole("button", {name: "Go back"}).click()
2026-08-20 20:33:20 +00:00
2026-09-09 01:07:48 +00:00
await expect(blocked).toContainText("1 Blocked")
2026-08-20 20:33:20 +00:00
// It was the picker's only offer a moment ago, which is what makes its absence about the block.
2026-09-09 01:07:48 +00:00
await blocked.click()
await dialog(page, "Blocked Relays").getByRole("button", {name: "Add Relays"}).click()
2026-08-20 20:33:20 +00:00
2026-09-09 01:07:48 +00:00
await expect(relayPicker(page).getByText("space.test")).toBeVisible()
2026-08-20 20:33:20 +00:00
await expect(relayPicker(page).getByText("other.test")).toHaveCount(0)
})
test("US-086 configure alerts", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const page = await as(users.alice, "/settings/alerts")
const sound = settingToggle(page, "Play sound for new activity")
const push = settingToggle(page, "Enable push notifications")
2026-08-20 20:33:20 +00:00
const alertTypes = page.locator("div.card").filter({has: page.getByText("Alert Types")})
await expect(sound).toBeChecked()
await expect(push).not.toBeChecked()
await expect(alertTypes).not.toHaveClass(/opacity-50/)
// With nothing left to be alerted through, there is nothing to be alerted about.
await sound.uncheck()
await expect(alertTypes).toHaveClass(/opacity-50/)
await page.getByRole("button", {name: "Discard Changes"}).click()
await expect(sound).toBeChecked()
await expect(alertTypes).not.toHaveClass(/opacity-50/)
// Push asks the browser for permission, and this context was never granted it.
await push.check()
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Failed to request notification permissions")
await expect(push).not.toBeChecked()
await expect(sound).toBeChecked()
await waitForToastToClear(page)
await sound.uncheck()
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your settings have been saved!")
await waitForToastToClear(page)
await page.reload()
await expect(settingToggle(page, "Play sound for new activity")).not.toBeChecked()
2026-08-20 20:33:20 +00:00
})
test("US-087 configure content display", async ({seed, as}) => {
let picture!: Seeded
let link!: Seeded
const scenario = await seed(({relay, user, at}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.join(user.bob, "general")
picture = space.message(user.bob, "general", "https://images.test/sunset.png", at(40, MINUTE))
link = space.message(user.bob, "general", "https://example.test/announcement", at(35, MINUTE))
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const {url} = scenario.space("space")
const page = await as(users.alice, "/settings/content")
const hideSensitive = settingToggle(page, "Hide sensitive content?")
const showMedia = settingToggle(page, "Show media?")
2026-08-20 20:33:20 +00:00
await expect(hideSensitive).toBeChecked()
await expect(showMedia).toBeChecked()
await hideSensitive.uncheck()
await showMedia.uncheck()
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your settings have been saved!")
await waitForToastToClear(page)
await page.goto(roomPath(url, "general"))
const pictureMessage = page.locator(`[data-event="${picture.id}"]`)
const linkMessage = page.locator(`[data-event="${link.id}"]`)
await expect(pictureMessage.getByRole("link", {name: "images.test/sunset.png"})).toBeVisible()
await expect(pictureMessage.locator('img[src="https://images.test/sunset.png"]')).toHaveCount(0)
await expect(linkMessage.getByRole("link", {name: "example.test/announcement"})).toBeVisible()
await expect(linkMessage.locator(".spinner")).toHaveCount(0)
await expect(linkMessage.getByText("Unable to load a preview")).toHaveCount(0)
await page.goto("/settings/content")
await expect(settingToggle(page, "Hide sensitive content?")).not.toBeChecked()
2026-08-20 20:33:20 +00:00
})
test("US-088 adjust send delay and media servers", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const page = await as(users.alice, "/settings/content")
// The send delay is the only slider on this page.
const sendDelay = page.locator('input[type="range"]')
const servers = page.getByRole("listitem")
await expect(page.getByText("Delay sending messages and comments for 0 seconds.")).toBeVisible()
2026-08-20 20:33:20 +00:00
await sendDelay.fill("3000")
await expect(page.getByText("Delay sending messages and comments for 3 seconds.")).toBeVisible()
2026-08-20 20:33:20 +00:00
await expect(servers).toHaveCount(0)
await page.getByRole("button", {name: "Add Server"}).click()
await expect(servers).toHaveCount(1)
await servers.first().locator("input").fill("https://media.test/")
await page.getByRole("button", {name: "Add Server"}).click()
await expect(servers).toHaveCount(2)
// Each row leads with its own remove button; the drag handle is the one with a label.
await servers.nth(1).getByRole("button").first().click()
await expect(servers).toHaveCount(1)
await expect(servers.first().locator("input")).toHaveValue("https://media.test/")
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your settings have been saved!")
await waitForToastToClear(page)
await page.reload()
await expect(page.getByText("Delay sending messages and comments for 3 seconds.")).toBeVisible()
2026-08-20 20:33:20 +00:00
await expect(page.locator('input[type="range"]')).toHaveValue("3000")
})
test("US-089 configure privacy preferences", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const page = await as(users.alice, "/settings/privacy")
const auth = settingToggle(page, "Authenticate with unknown relays?")
const usage = settingToggle(page, "Report usage?")
2026-08-20 20:33:20 +00:00
await expect(auth).not.toBeChecked()
await expect(usage).toBeChecked()
await auth.check()
await usage.uncheck()
await page.getByRole("button", {name: "Discard Changes"}).click()
await expect(auth).not.toBeChecked()
await expect(usage).toBeChecked()
await auth.check()
await usage.uncheck()
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your settings have been saved!")
await waitForToastToClear(page)
await page.reload()
await expect(settingToggle(page, "Authenticate with unknown relays?")).toBeChecked()
await expect(settingToggle(page, "Report usage?")).not.toBeChecked()
2026-08-20 20:33:20 +00:00
})
test("US-129 raise the thresholds a stranger has to meet", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.relayList(user.alice)
})
const page = await as(users.alice, "/settings/privacy")
const pow = requestSliders(page).first()
const wot = requestSliders(page).last()
await expect(pow).toHaveValue("16")
await expect(wot).toHaveValue("3")
await expect(requestsCard(page).getByText("16 bits", {exact: true})).toBeVisible()
await expect(requestsCard(page).getByText("3 people", {exact: true})).toBeVisible()
await pow.fill("24")
await wot.fill("1")
await expect(requestsCard(page).getByText("24 bits", {exact: true})).toBeVisible()
await expect(requestsCard(page).getByText("1 person", {exact: true})).toBeVisible()
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your settings have been saved!")
await waitForToastToClear(page)
await page.reload()
await expect(requestSliders(page).first()).toHaveValue("24")
await expect(requestSliders(page).last()).toHaveValue("1")
})
2026-08-20 20:33:20 +00:00
test("US-090 change the app's appearance", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const page = await as(users.alice, "/settings/theme", {context: {colorScheme: "light"}})
const body = page.locator("body")
const colorScheme = () =>
page.evaluate(() => getComputedStyle(document.documentElement).colorScheme)
2026-08-20 20:33:20 +00:00
await expect(body).toHaveAttribute("data-theme", "light")
await expect.poll(colorScheme).toBe("light")
2026-08-20 20:33:20 +00:00
await page.getByRole("button", {name: "Dark", exact: true}).click()
await expect(body).toHaveAttribute("data-theme", "dark")
await expect.poll(colorScheme).toBe("dark")
2026-08-20 20:33:20 +00:00
await page.getByRole("button", {name: "System", exact: true}).click()
await expect(body).toHaveAttribute("data-theme", "light")
await expect.poll(colorScheme).toBe("light")
2026-08-20 20:33:20 +00:00
// System means the device's, so changing the device's changes the app's.
await page.emulateMedia({colorScheme: "dark"})
await expect(body).toHaveAttribute("data-theme", "dark")
await expect.poll(colorScheme).toBe("dark")
2026-08-20 20:33:20 +00:00
await page.getByLabel("Style").selectOption("navy")
await expect(body).toHaveAttribute("data-fl-theme", "navy")
await page.reload()
await expect(body).toHaveAttribute("data-fl-theme", "navy")
await expect(page.getByLabel("Style")).toHaveValue("navy")
// Font size is the only slider on this page, and the only setting here that is published.
const fontSize = page.locator('input[type="range"]')
await expect(page.getByText("110%")).toBeVisible()
await expect(page.getByRole("button", {name: "Save Changes"})).toHaveCount(0)
await fontSize.fill("1.25")
await expect(page.getByText("125%")).toBeVisible()
await expect(page.locator("html")).toHaveAttribute("style", /font-size:\s*1\.25rem/)
// Moving the slider is the save.
2026-08-20 20:33:20 +00:00
await page.reload()
await expect(page.locator("html")).toHaveAttribute("style", /font-size:\s*1\.25rem/)
})
test("US-091 set up how people zap you", async ({seed, as}) => {
await seed(({relay, user}) => {
const space = relay("space")
space.room("general", {name: "General"})
space.join(user.alice, "general")
space.profile(user.alice, {name: "Alice Anders"})
space.relayList(user.alice)
2026-08-20 20:33:20 +00:00
})
const page = await as(users.alice, "/settings/wallet")
await expect(page.getByText("Not set")).toBeVisible()
await page.getByRole("button", {name: "Update"}).click()
const address = page
.locator(".dialog")
.filter({has: page.getByRole("heading", {name: "Update Lightning Address"})})
.last()
await address.getByPlaceholder("user@domain.com").fill("alice@example.test")
await address.getByRole("button", {name: "Save Changes"}).click()
// The dialog closes itself once the profile has gone out, and the page behind it has its own Save.
2026-08-20 20:33:20 +00:00
await expect(address).toHaveCount(0)
await expect(page.getByText("alice@example.test")).toBeVisible()
await expect(page.getByText("Not set")).toHaveCount(0)
await page.getByRole("button", {name: "Update"}).click()
await address.getByPlaceholder("user@domain.com").fill("")
await address.getByRole("button", {name: "Save Changes"}).click()
await expect(address).toHaveCount(0)
await expect(page.getByText("Not set")).toBeVisible()
// The same utility classes land on other rows, so this is pinned to the zap form's input rows.
const zapForm = page.locator("form").filter({hasText: "Zap Amounts"})
const presets = zapForm.locator("div.items-center.gap-2:has(input)")
2026-08-20 20:33:20 +00:00
await expect(presets).toHaveCount(4)
await page.getByRole("button", {name: "Add amount"}).click()
await expect(presets).toHaveCount(5)
// A preset has to be worth something, so saving a zero is refused with an error.
await presets.nth(4).locator("input").fill("0")
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Zap amounts must be greater than zero.")
await waitForToastToClear(page)
// Discarding puts back the last saved values, which are still alice's original four.
2026-08-20 20:33:20 +00:00
await page.getByRole("button", {name: "Discard Changes"}).click()
await expect(presets).toHaveCount(4)
await presets.nth(3).getByRole("button").click()
await presets.nth(2).getByRole("button").click()
await presets.nth(1).getByRole("button").click()
await expect(presets).toHaveCount(1)
await expect(presets.first().getByRole("button")).toBeDisabled()
await presets.first().locator("input").fill("500")
await page.getByRole("button", {name: "Save Changes"}).click()
await expect(page.getByRole("alert")).toContainText("Your zap amounts have been saved!")
await waitForToastToClear(page)
await page.reload()
const saved = page
.locator("form")
.filter({hasText: "Zap Amounts"})
.locator("div.items-center.gap-2:has(input)")
2026-08-20 20:33:20 +00:00
await expect(saved).toHaveCount(1)
await expect(saved.first().locator("input")).toHaveValue("500")
})