~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0
main
1037 lines · 50.4 KB Raw History
// What people do on the console, in order, as alice: sign in at her own
// PDS, see her groups, sign an app in as one of them, and decline one;
// and what the app then does as the group, read back from the host.

import { expect, test } from '@playwright/test';
import {
  App,
  McpClient,
  approve,
  didKey,
  hydrating,
  inboxWriters,
  joins,
  makeInbox,
  signIn,
  signInDialog,
  signedInAs,
  suggests,
  url,
  who,
  world
} from './pages.mjs';

test.describe.configure({ mode: 'serial' });

let page;
// Bob's browser, apart from alice's.
let bob;

test.beforeAll(async ({ browser }) => {
  page = await browser.newPage();
  bob = await (await browser.newContext()).newPage();
  hydrating(page);
  hydrating(bob);
  await suggests(page.context());
  await suggests(bob.context());
});

test.afterAll(async () => {
  await page.close();
  await bob.context().close();
});

test('coming to the host signed out', async () => {
  await page.goto(url('/'));
  // The host by its address, what signing in is for, and no groups.
  const host = new URL(world.base).hostname;
  await expect(page.getByRole('heading', { level: 1 })).toHaveText(`Groups on ${host}`);
  await expect(
    page.getByText('Sign in with your Atmosphere account to see your groups, or to start one.')
  ).toBeVisible();
  await expect(page.locator('.group-row')).toHaveCount(0);
  await expect(page.getByRole('contentinfo')).toHaveText(`${host} runs Atmosphere Groups`);
  // Its one button opens the dialog: the apps of the Atmosphere, what an
  // account is, the handle, and where to make one.
  await page.getByRole('main').getByRole('button', { name: 'Sign in' }).click();
  const dialog = signInDialog(page);
  await expect(dialog).toBeVisible();
  await expect(dialog.locator('.apps img')).toHaveCount(40);
  await expect(
    dialog.getByRole('link', { name: 'What is an Atmosphere account?' })
  ).toHaveAttribute('href', 'https://atmosphereaccount.com/');
  await expect(dialog.getByRole('combobox', { name: 'Handle' })).toBeFocused();
  // Made at the host's sign-up PDS, coming back here signed in.
  await expect(dialog.getByRole('link', { name: 'Create one' })).toHaveAttribute(
    'href',
    '/console/login?create&back=%2F'
  );
  await expect(dialog.getByRole('combobox', { name: 'Handle' })).toHaveAttribute(
    'placeholder',
    'you.bsky.social'
  );
  // Two letters of a handle suggest the accounts it is part of; one, none.
  const handle = dialog.getByRole('combobox', { name: 'Handle' });
  await handle.pressSequentially('a');
  await expect(handle).toHaveAttribute('aria-expanded', 'false');
  await handle.pressSequentially('l');
  await expect(dialog.getByRole('option')).toHaveText(['Alice @alice.test']);
  await expect(handle).toHaveAttribute('aria-expanded', 'true');
  // Escape closes the list, not the dialog; what the arrows chose is let
  // go, so Enter after more typing sends what is typed.
  await handle.press('ArrowDown');
  await expect(dialog.getByRole('option')).toHaveAttribute('aria-selected', 'true');
  await handle.press('Escape');
  await expect(dialog.getByRole('listbox')).toBeHidden();
  await expect(dialog).toBeVisible();
  await handle.pressSequentially('i');
  await expect(dialog.getByRole('option')).toHaveAttribute('aria-selected', 'false');
  await handle.press('Escape');
  await dialog.getByRole('button', { name: 'Cancel' }).click();
  await expect(dialog).toBeHidden();
});

test("a group's page signed out", async () => {
  // Its handle alone, and the way in, wherever its policy lets
  // anyone signed in read it.
  await page.goto(url('/g/riders.groups.test'));
  await expect(page.getByRole('heading', { level: 1 })).toHaveText('riders.groups.test');
  await expect(page.getByText('Sign in to see this group.')).toBeVisible();
  await expect(page.locator('.identity, .rules, .standing')).toHaveCount(0);
  // Nor does the host tell anyone not signed in more of it.
  const { group } = await fetch(
    `${world.host}/xrpc/org.atgrp.internal.getGroup?group=${world.riders}`
  ).then((r) => r.json());
  expect(group).toEqual({ did: world.riders, handle: 'riders.groups.test' });
});

test("signing in at her own PDS, from a group's page", async () => {
  // Signed in from the page by picking her account as she types it, with
  // the arrows and Enter; back on it, as she may see it.
  await page.getByRole('main').getByRole('button', { name: 'Sign in' }).click();
  const handle = signInDialog(page).getByRole('combobox', { name: 'Handle' });
  await handle.pressSequentially('alic');
  await expect(signInDialog(page).getByRole('option', { name: 'Alice @alice.test' })).toBeVisible();
  await handle.press('ArrowDown');
  await expect(
    signInDialog(page).getByRole('option', { name: 'Alice @alice.test' })
  ).toHaveAttribute('aria-selected', 'true');
  await handle.press('Enter');
  await approve(page, 'alice');
  await page.waitForURL(url('/g/riders.groups.test'));
  await expect(page).toHaveURL(url('/g/riders.groups.test'));
  await expect.poll(() => signedInAs(page)).toBe('@alice.test');
  await expect(page.getByText('Sign in to see this group.')).toHaveCount(0);
  await expect(page.getByText(/You're a member/)).toBeVisible();
  await page.goto(url('/'));
});

test('seeing her groups', async () => {
  await expect(page.getByRole('heading', { name: 'Your groups' })).toBeVisible();
  await expect(page.locator('.group-row', { hasText: 'Riders' }).first()).toBeVisible();
});

test('coming back to her groups by a link, the page drawn in the browser', async () => {
  await page.goto(url('/new'));
  await page.getByRole('link', { name: 'Atmosphere Groups' }).click();
  await page.waitForURL(url('/'));
  await expect(page.getByRole('heading', { name: 'Your groups' })).toBeVisible();
  await expect(page.locator('.group-row', { hasText: 'Riders' }).first()).toBeVisible();
});

test('starting a group', async () => {
  await page.getByRole('link', { name: 'Start a group' }).click();
  // Its address made from its name, under the host's domain.
  await page.getByRole('textbox', { name: 'Name' }).pressSequentially('Hikers');
  await expect(page.getByRole('textbox', { name: 'Its address' })).toHaveValue('hikers');
  await expect(page.getByText('.groups.test', { exact: true })).toBeVisible();
  await page.getByRole('textbox', { name: 'What it is for' }).fill('Walks on Sundays.');
  await page.getByRole('button', { name: 'Start the group' }).click();
  await page.waitForURL(url('/g/hikers.groups.test'));
  await expect(page.getByRole('heading', { name: 'Hikers' })).toBeVisible();
  await expect(page.getByText('Walks on Sundays.')).toBeVisible();
  await expect(page.getByText(/You're a member/)).toBeVisible();
  // An address taken already is said as it is typed, with the next free
  // one to take; and the host's to refuse, sent all the same.
  await page.goto(url('/new'));
  await page.getByRole('textbox', { name: 'Name' }).pressSequentially('Hikers');
  await expect(page.getByText('hikers.groups.test is taken.')).toBeVisible();
  await expect(page.getByRole('button', { name: 'Use hikers-2.groups.test' })).toBeVisible();
  // Its answer waited for: the note that it is taken is p.danger already,
  // and a page left before the answer lands is drawn over by it.
  const answered = page.waitForResponse(
    (r) => r.request().method() === 'POST' && r.url().includes('/new')
  );
  await page.getByRole('button', { name: 'Start the group' }).click();
  await answered;
  await page.waitForLoadState();
  await expect(page.locator('p.danger')).toBeVisible();
  // Its address changed by hand stays as it was put, whatever the name.
  await page.goto(url('/new'));
  await page.getByRole('textbox', { name: 'Its address' }).pressSequentially('Sunday Walks!');
  await page.getByRole('textbox', { name: 'Name' }).pressSequentially('Hikers');
  await expect(page.getByRole('textbox', { name: 'Its address' })).toHaveValue('sunday-walks-');
});

test('asking to join with a note, and being approved', async () => {
  await bob.goto(url('/g/hikers.groups.test'));
  await signIn(bob, 'bob');
  // The group, and how joining it works: someone looks at each request.
  await expect(bob.getByRole('heading', { name: 'Hikers', exact: true })).toBeVisible();
  await expect(bob.getByText('Joining is by request.')).toBeVisible();
  await expect(bob.getByRole('heading', { name: 'Ask to join' })).toBeVisible();
  const note = bob.getByRole('textbox', { name: 'Note' });
  await note.fill('I walk most Sundays.');
  await bob.getByRole('button', { name: 'Send request' }).click();
  await expect(bob.getByRole('heading', { name: 'Your request is waiting' })).toBeVisible();
  // Withdrawn, and asked again.
  await bob.getByRole('button', { name: 'Cancel request' }).click();
  await expect(bob.getByRole('heading', { name: 'Ask to join' })).toBeVisible();
  await note.fill('I walk most Sundays.');
  await bob.getByRole('button', { name: 'Send request' }).click();
  await expect(bob.getByRole('heading', { name: 'Your request is waiting' })).toBeVisible();
  // Alice sees it, with his note, and lets him in.
  await page.goto(url('/g/hikers.groups.test'));
  const asking = page.locator('.requests li', { hasText: 'bob.test' });
  await expect(asking).toContainText('I walk most Sundays.');
  await asking.getByRole('button', { name: 'Approve' }).click();
  await expect(page.locator('.members', { hasText: 'bob.test' })).toBeVisible();
  await expect(page.getByText('Nobody is asking to join')).toBeVisible();
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByText(/You're a member/)).toBeVisible();
});

test('leaving a group', async () => {
  // Asked to be sure of; cancelled, he is still in.
  const sure = bob.getByRole('dialog', { name: 'Leave this group?' });
  await bob.getByRole('button', { name: 'Leave the group' }).click();
  await sure.getByRole('button', { name: 'Cancel' }).click();
  await expect(sure).toBeHidden();
  await bob.getByRole('button', { name: 'Leave the group' }).click();
  await sure.getByRole('button', { name: 'Leave the group' }).click();
  await expect(bob.getByRole('heading', { name: 'Ask to join' })).toBeVisible();
});

/** Alice invites bob to Hikers from its page, picking him as she types, with a note. */
async function send() {
  const dialog = page.getByRole('dialog', { name: 'Invite someone' });
  await page.getByRole('button', { name: 'Invite someone' }).click();
  const handle = dialog.getByRole('combobox', { name: 'Their handle' });
  await handle.pressSequentially('bo');
  await dialog.getByRole('option', { name: 'Bob @bob.test' }).click();
  await expect(handle).toHaveValue('bob.test');
  await expect(dialog.getByRole('listbox')).toBeHidden();
  await dialog.getByRole('textbox', { name: 'Note' }).fill('Come walk with us.');
  await dialog.getByRole('button', { name: 'Send invite' }).click();
  await expect(page.locator('.invites', { hasText: 'bob.test' })).toBeVisible();
}

test('inviting someone from the dialog', async () => {
  // Bob's app has made his inbox, where groups write their invites to
  // him. A PDS that does not speak the space alpha keeps no space.
  const inbox = world.spaces ? await makeInbox(who.bob) : undefined;
  await page.goto(url('/g/hikers.groups.test'));
  const dialog = page.getByRole('dialog', { name: 'Invite someone' });
  const invite = page.getByRole('button', { name: 'Invite someone' });
  await invite.click();
  await expect(
    dialog.getByText(
      "They'll see it the next time they sign in, here or in any app that shows invites."
    )
  ).toBeVisible();
  await dialog.getByRole('combobox', { name: 'Their handle' }).fill('nobody.test');
  await dialog.getByRole('button', { name: 'Send invite' }).click();
  // Refused, it stays open, saying why, with what was typed.
  await expect(dialog.getByText("We can't find nobody.test.")).toBeVisible();
  await expect(dialog.getByRole('combobox', { name: 'Their handle' })).toHaveValue('nobody.test');
  // Cancelled, it sends nothing.
  await dialog.getByRole('button', { name: 'Cancel' }).click();
  await expect(dialog).toBeHidden();
  await expect(page.locator('.invites')).toHaveCount(0);
  // Sent, with a note, picked from the accounts suggested as part of his
  // handle is typed; cancelled; and sent again.
  await send();
  await page.getByRole('button', { name: 'Cancel invite' }).click();
  await expect(page.locator('.invites', { hasText: 'bob.test' })).toHaveCount(0);
  await send();
  // His PDS took Hikers' invite: the group writes in his inbox.
  if (inbox) {
    const resolved = await fetch(
      `${world.host}/xrpc/com.atproto.identity.resolveHandle?handle=hikers.groups.test`
    ).then((r) => r.json());
    await expect.poll(() => inboxWriters(who.bob, inbox)).toContain(resolved.did);
  }
});

test("turning down an invitation from the group's page", async () => {
  // Marked on every page: a dot on his picture, and a count in his menu,
  // leading to it on his own page, with its note.
  await bob.goto(url('/new'));
  await expect(bob.locator('.user-menu .waiting.dot')).toBeVisible();
  await bob.locator('.user-menu summary').click();
  await bob.locator('.menu').getByRole('link', { name: 'Invites 1' }).click();
  await bob.waitForURL(url('/#invites'));
  await expect(
    bob.locator('#invites').getByRole('heading', { name: 'Invites waiting' })
  ).toBeVisible();
  await expect(bob.locator('#invites').getByText('Come walk with us.')).toBeVisible();
  // Declined on the group's page, asked nothing: it then says how
  // joining works for anyone not invited.
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByRole('heading', { name: "You're invited" })).toBeVisible();
  await bob.getByRole('button', { name: 'Decline' }).click();
  await expect(bob.getByRole('heading', { name: 'Ask to join' })).toBeVisible();
  await expect(bob.locator('.user-menu .waiting.dot')).toHaveCount(0);
  // None waiting: his own page says so, and his menu counts none.
  await bob.goto(url('/'));
  await expect(bob.locator('#invites').getByText('No invites waiting')).toBeVisible();
  await bob.locator('.user-menu summary').click();
  await expect(
    bob.locator('.menu').getByRole('link', { name: 'Invites', exact: true })
  ).toBeVisible();
  await page.goto(url('/g/hikers.groups.test'));
  await expect(page.locator('.invites', { hasText: 'bob.test' })).toHaveCount(0);
});

test('taking up an invitation', async () => {
  await send();
  // On his own page, with its note; and on the group's.
  await bob.goto(url('/'));
  await expect(bob.locator('#invites').getByText('Come walk with us.')).toBeVisible();
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByRole('heading', { name: "You're invited" })).toBeVisible();
  await expect(bob.getByText('Someone in Hikers invited you to join.')).toBeVisible();
  await bob.getByRole('button', { name: 'Join', exact: true }).click();
  await expect(bob.getByRole('heading', { name: "You're in" })).toBeVisible();
  await expect(bob.getByText('Welcome to Hikers.')).toBeVisible();
  await expect(bob.getByText(/You're a member/)).toBeVisible();
  await bob.goto(url('/'));
  await expect(bob.locator('#invites').getByText('No invites waiting')).toBeVisible();
  await expect(bob.locator('.group-row', { hasText: 'Hikers' }).first()).toBeVisible();
  await page.goto(url('/g/hikers.groups.test'));
  await expect(page.locator('.members', { hasText: 'bob.test' })).toBeVisible();
});

test('a member with nothing to change sees no settings', async () => {
  // Bob, a member and no more: no way to its settings on its page.
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByText(/You're a member/)).toBeVisible();
  await expect(bob.getByRole('link', { name: 'Settings' })).toHaveCount(0);
  // At their addresses all the same, nothing is his, and the way back.
  for (const part of ['', '/rules', '/apps']) {
    await bob.goto(url(`/g/hikers.groups.test/settings${part}`));
    await expect(bob.getByText('Nothing here is yours to change')).toBeVisible();
  }
  await bob.getByRole('link', { name: 'Back to Hikers' }).click();
  await bob.waitForURL(url('/g/hikers.groups.test'));
});

test('giving roles, and putting someone out', async () => {
  const row = () => page.locator('.member', { hasText: 'bob.test' });
  // His roles in a dialog, those she may give to tick.
  // From the "⋯" at the end of his row.
  await row().getByLabel('More for bob.test').click();
  await row().getByRole('button', { name: 'Change roles' }).click();
  const roles = page.getByRole('dialog', { name: 'Change roles' }).filter({ visible: true });
  await expect(roles.getByRole('checkbox', { name: 'member' })).toBeChecked();
  // Saved in place: the dialog closes, and the page stays where it was.
  const at = await page.evaluate(() => scrollY);
  expect(at).toBeGreaterThan(0);
  await roles.getByRole('button', { name: 'Save' }).click();
  await expect(roles).toBeHidden();
  await expect(row()).toContainText('member');
  expect(await page.evaluate(() => scrollY)).toBe(at);
  // Removed, once she is sure.
  await row().getByLabel('More for bob.test').click();
  await row().getByRole('button', { name: 'Remove from the group' }).click();
  const sure = page.getByRole('dialog', { name: 'Remove this member?' }).filter({ visible: true });
  await expect(sure).toContainText('bob.test');
  await expect(sure.getByText('They can ask to join again.')).toBeVisible();
  await sure.getByRole('button', { name: 'Remove', exact: true }).click();
  await expect(page.locator('.members', { hasText: 'bob.test' })).toHaveCount(0);
});

test('being told why the host refused', async () => {
  // The group's only admin may not leave it: the page says so.
  await page.getByRole('button', { name: 'Leave the group' }).click();
  await page
    .getByRole('dialog', { name: 'Leave this group?' })
    .getByRole('button', { name: 'Leave the group' })
    .click();
  await expect(page.locator('p.danger')).toBeVisible();
  await expect(page.getByText(/You're a member/)).toBeVisible();
});

test('joining a group anyone can join', async () => {
  // Alice opens it to anyone.
  const settings = url('/g/hikers.groups.test/settings');
  await page.goto(settings);
  await page.getByRole('combobox', { name: 'How people join' }).selectOption('open');
  const profile = page.locator('form[action="?/profile"]');
  await profile.getByRole('button', { name: 'Save' }).click();
  await expect(profile.getByRole('status')).toHaveText('Saved');
  // Bob, removed, joins it at once.
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByRole('heading', { name: 'Join Hikers' })).toBeVisible();
  await expect(bob.locator('.join')).toContainText('Anyone can join.');
  await bob.getByRole('button', { name: 'Join', exact: true }).click();
  await expect(bob.getByRole('heading', { name: "You're in" })).toBeVisible();
  await expect(bob.getByText(/You're a member/)).toBeVisible();
});

test('finding a member, and showing more', async () => {
  // Six in all: more than a page of five.
  for (const name of ['carol', 'dan', 'erin', 'frank']) await joins(name, 'hikers.groups.test');
  await page.goto(url('/g/hikers.groups.test'));
  await expect(page.getByRole('heading', { name: 'Members' })).toContainText('6');
  const rows = page.locator('.members > li');
  await expect(rows).toHaveCount(5);
  await page.getByRole('button', { name: 'Show more' }).click();
  await expect(rows).toHaveCount(6);
  await expect(page.getByRole('button', { name: 'Show more' })).toHaveCount(0);
  // Found by part of a handle, as it is typed.
  const find = page.getByRole('searchbox', { name: 'Find a member' });
  await find.fill('erin');
  await expect(rows).toHaveCount(1);
  await expect(rows).toContainText('erin.test');
  await expect(find).toBeFocused();
  await find.fill('nobody');
  await expect(page.getByText("No member's handle has that in it")).toBeVisible();
});

test('connecting an AI app is shown to those who run the group', async () => {
  await page.goto(url('/g/hikers.groups.test'));
  const connect = page.locator('section', {
    has: page.getByRole('heading', { name: 'Connect an AI app' })
  });
  await expect(connect).toContainText(
    'It acts for you in Hikers, with what your roles let you do.'
  );
  await expect(connect.locator('code')).toHaveText(`${world.base}/mcp`);
  await expect(connect).toContainText('When it asks, sign in here and approve it');
  await expect(connect.locator('.asks li')).toHaveCount(3);
  // Not to a plain member.
  await bob.goto(url('/g/hikers.groups.test'));
  await expect(bob.getByText(/You're a member/)).toBeVisible();
  await expect(bob.getByRole('heading', { name: 'Connect an AI app' })).toHaveCount(0);
});

test("changing a group's profile", async () => {
  await page.goto(url('/g/hikers.groups.test'));
  await page.getByRole('link', { name: 'Settings' }).click();
  await page.getByRole('textbox', { name: 'Name', exact: true }).fill('Hikers of the Hills');
  const site = page.getByRole('textbox', { name: /^Its own site/ });
  await site.fill('https://hikers.example/');
  // Changed, it says so beside Save, and Save is the thing to press.
  const profile = page.locator('form[action="?/profile"]');
  const said = profile.getByRole('status');
  const save = profile.getByRole('button', { name: 'Save' });
  await expect(said).toHaveText('Unsaved changes');
  await expect(save).not.toHaveClass(/quiet/);
  await save.click();
  // Saved, it says that, until something is changed again.
  await expect(said).toHaveText('Saved');
  await expect(save).toHaveClass(/quiet/);
  // Drawn again as saved.
  await expect(page.getByRole('textbox', { name: 'Name', exact: true })).toHaveValue(
    'Hikers of the Hills'
  );
  await expect(site).toHaveValue('https://hikers.example/');
  await page.goto(url('/g/hikers.groups.test'));
  await expect(page.getByRole('heading', { name: 'Hikers of the Hills' })).toBeVisible();
  await expect(page.getByText('Walks on Sundays.')).toBeVisible();
});

// A one-pixel PNG.
const PIXEL = Buffer.from(
  'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
  'base64'
);

test('being asked before leaving changes unsaved', async () => {
  const settings = url('/g/hikers.groups.test/settings');
  await page.goto(settings);
  const name = page.getByRole('textbox', { name: 'Name', exact: true });
  const was = await name.inputValue();
  await name.fill('Not saved');
  // Going to another page asks first, and staying keeps what was typed.
  await page.getByRole('link', { name: 'Rules' }).click();
  const ask = page.getByRole('dialog', { name: 'Leave without saving?' });
  await ask.getByRole('button', { name: 'Keep editing' }).click();
  await expect(name).toHaveValue('Not saved');
  // Put back as it was, there is nothing to ask about.
  await name.fill(was);
  await expect(page.locator('form[action="?/profile"]').getByRole('status')).toHaveText('');
  await name.fill('Not saved');
  await page.getByRole('link', { name: 'Rules' }).click();
  await ask.getByRole('button', { name: 'Leave' }).click();
  await expect(page).toHaveURL(/\/settings\/rules$/);
  await page.goto(settings);
  await expect(name).toHaveValue(was);
});

test('giving a group a picture, and taking it away', async () => {
  await page.goto(url('/g/hikers.groups.test/settings'));
  await page.getByRole('button', { name: 'Add the avatar' }).click();
  await page
    .getByLabel('Avatar', { exact: true })
    .setInputFiles({ name: 'face.png', mimeType: 'image/png', buffer: PIXEL });
  const adding = page.getByRole('dialog', { name: 'Add the avatar' });
  await adding.getByRole('button', { name: 'Add the avatar' }).click();
  // Sent in place: done, the dialog closes and the page offers to remove it.
  await expect(adding).toBeHidden();
  await expect(page.getByRole('button', { name: 'Remove the avatar' })).toBeVisible();
  // Drawn on its page, from the host, as the image it is: one pixel wide.
  await page.goto(url('/g/hikers.groups.test'));
  const avatar = page.locator('.identity img.av');
  await expect(avatar).toBeVisible();
  await expect.poll(() => avatar.evaluate((img) => img.naturalWidth)).toBe(1);
  await page.goto(url('/g/hikers.groups.test/settings'));
  await page.getByRole('button', { name: 'Remove the avatar' }).click();
  await expect(page.getByRole('button', { name: 'Add the avatar' })).toBeVisible();
  await page.goto(url('/g/hikers.groups.test'));
  await expect(page.locator('.identity img.av')).toHaveCount(0);
});

test("hiding a group's profile, and showing it again", async () => {
  // Found on the network while its declaration is in its public repo,
  // which anyone may read.
  const listed = async () =>
    bob.evaluate(async () => {
      const { did } = await fetch(
        '/xrpc/com.atproto.identity.resolveHandle?handle=hikers.groups.test'
      ).then((r) => r.json());
      const res = await fetch(
        `/xrpc/com.atproto.repo.getRecord?repo=${did}&collection=org.atgrp.declaration&rkey=self`
      );
      return res.ok;
    });
  expect(await listed()).toBe(true);
  await page.goto(url('/g/hikers.groups.test/settings'));
  // Saved, and the page opened afresh as the host has it: not reloaded,
  // which would send the form's post again.
  const settings = url('/g/hikers.groups.test/settings');
  const save = async (label) => {
    await page.goto(settings);
    await page.getByLabel(label).check();
    const seen = page.locator('form[action="?/visibility"]');
    await seen.getByRole('button', { name: 'Save' }).click();
    await expect(seen.getByRole('status')).toHaveText('Saved');
    await page.goto(settings);
    await expect(page.getByLabel(label)).toBeChecked();
  };
  await save('Members only. Others see just its handle.');
  await expect.poll(listed).toBe(false);
  await save('Anyone, and it can be found');
  await expect.poll(listed).toBe(true);
});

test("asking for a handle on a domain that doesn't point to the group yet", async () => {
  await page.goto(url('/g/hikers.groups.test/settings'));
  const handles = page.locator('.handles');
  await expect(handles.getByText('hikers.groups.test', { exact: true })).toBeVisible();
  await page.getByRole('button', { name: 'Use your own domain' }).click();
  const using = page.getByRole('dialog', { name: 'Use your own domain' });
  // The record to add points to the group, at the domain as it is typed.
  const { did } = await fetch(
    `${world.host}/xrpc/com.atproto.identity.resolveHandle?handle=hikers.groups.test`
  ).then((r) => r.json());
  await expect(using.getByText(`did=${did}`, { exact: true })).toBeVisible();
  await using.getByLabel('Domain').fill('Hikers.test');
  const name = using.getByText('_atproto.hikers.test', { exact: true });
  await expect(name).toBeVisible();
  // Refused in the reader's words, the dialog open with what was typed,
  // and the record's name with it.
  await using.getByRole('button', { name: 'Use', exact: true }).click();
  await expect(
    using.getByText("hikers.test doesn't point to this group yet.", { exact: false })
  ).toBeVisible();
  await expect(using.getByLabel('Domain')).toHaveValue('Hikers.test');
  await expect(name).toBeVisible();
});

test('adding a rule, and taking it away', async () => {
  // Settings has a page for each part, reached by its tabs.
  await page.goto(url('/g/hikers.groups.test/settings'));
  await page
    .getByRole('navigation', { name: 'Settings' })
    .getByRole('link', { name: 'Rules' })
    .click();
  await expect(page).toHaveURL(url('/g/hikers.groups.test/settings/rules'));
  await expect(page.getByText('No rules yet')).toBeVisible();
  await page.getByRole('button', { name: 'Add a rule' }).click();
  await page.getByRole('textbox', { name: 'Rule' }).fill('Leave no trace');
  await page
    .getByRole('dialog', { name: 'Add a rule' })
    .getByRole('button', { name: 'Add', exact: true })
    .click();
  await expect(page.locator('.rule-rows', { hasText: 'Leave no trace' })).toBeVisible();
  // On the group's page, folded under how many there are.
  await page.goto(url('/g/hikers.groups.test'));
  await page.locator('summary', { hasText: 'Rules' }).click();
  await expect(page.locator('.rules .count')).toHaveText('1');
  await expect(page.getByText('Leave no trace')).toBeVisible();
  await page.goto(url('/g/hikers.groups.test/settings/rules'));
  await page.getByRole('button', { name: 'Delete “Leave no trace”' }).click();
  await page
    .getByRole('dialog', { name: 'Delete this rule?' })
    .filter({ visible: true })
    .getByRole('button', { name: 'Delete', exact: true })
    .click();
  await expect(page.locator('.rule-rows')).toHaveCount(0);
});

test('defining a role, then giving it less', async () => {
  await page.goto(url('/g/hikers.groups.test/settings/roles'));
  await page.getByRole('button', { name: 'Create a role' }).click();
  const create = page.getByRole('dialog', { name: 'Create a role' });
  // An ID the host would refuse is said so as it is typed.
  const id = create.getByRole('textbox', { name: 'Its ID' });
  await id.fill('ab');
  await expect
    .poll(() => id.evaluate((input) => input.validationMessage))
    .toBe('Use at least 3 lowercase letters or hyphens, and nothing else.');
  await id.fill('leader');
  await expect.poll(() => id.evaluate((input) => input.validity.valid)).toBe(true);
  await create.getByRole('textbox', { name: /^Its name/ }).fill('Ride leader');
  // Members, a part in running the group: what comes with it shows
  // ticked, and can't be unticked while it is.
  await create.locator('input[name=set][value=members]').check();
  const admit = create.locator('input[name=action][value=admit]');
  await expect(admit).toBeChecked();
  await expect(admit).toBeDisabled();
  await create.getByRole('button', { name: 'Create', exact: true }).click();
  const row = page.locator('.roles > li', {
    has: page.locator('strong', { hasText: 'Ride leader' })
  });
  await expect(row.locator('.tags')).toContainText('admit');
  await expect(row.locator('.tags')).toContainText('role.assign');
  // To take some of that away: no part, and only invite, ticked alone.
  await row.locator('.action-menu summary').click();
  await row.getByRole('button', { name: 'Change', exact: true }).click();
  const change = page.getByRole('dialog', { name: 'Change this role' }).filter({ visible: true });
  const members = change.locator('input[name=set][value=members]');
  await expect(members).toBeChecked();
  await expect(change.locator('input[name=action][value=invite]')).toBeDisabled();
  await members.uncheck();
  await expect(change.locator('input[name=action][value=admit]')).not.toBeChecked();
  await change.getByRole('checkbox', { name: 'invite', exact: true }).check();
  await change.getByRole('button', { name: 'Save', exact: true }).click();
  await expect(change).toBeHidden();
  // Saved as shown: invite, and nothing the members part gave.
  await expect(row.locator('.tags')).toHaveText('invite');
  await row.locator('.action-menu summary').click();
  await row.getByRole('button', { name: 'Delete', exact: true }).click();
  await page
    .getByRole('dialog', { name: 'Delete this role?' })
    .filter({ visible: true })
    .getByRole('button', { name: 'Delete', exact: true })
    .click();
  await expect(page.locator('.roles li', { hasText: 'Ride leader' })).toHaveCount(0);
});

test('creating an app password, and revoking what it signed in', async () => {
  await page.goto(url('/g/hikers.groups.test/settings/apps'));
  await page.getByRole('button', { name: 'Create an app password' }).click();
  await page.getByRole('textbox', { name: 'Where it is used' }).fill('Phone');
  await page
    .getByRole('dialog', { name: 'Create an app password' })
    .getByRole('button', { name: 'Create', exact: true })
    .click();
  const password = (await page.locator('code.password').textContent()).trim();
  const signIn = () =>
    fetch(`${world.host}/xrpc/com.atproto.server.createSession`, {
      method: 'POST',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ identifier: 'hikers.groups.test', password })
    });
  expect((await signIn()).status).toBe(200);
  await page.goto(url('/g/hikers.groups.test/settings/apps'));
  await expect(page.locator('.passwords', { hasText: 'Phone' })).toBeVisible();
  // Whose it is, and who did what lately, by handle; what was done said
  // as what it is, not as the records' addresses.
  await expect(page.locator('.passwords li', { hasText: 'Phone' })).toContainText('alice.test');
  await expect(
    page.locator('.activity li', { hasText: '@alice.test deleted a role' }).first()
  ).toBeVisible();
  await expect(page.locator('.activity')).not.toContainText('at://');
  await expect(page.locator('.activity')).not.toContainText('at:space/');
  await expect(page.locator('.activity')).not.toContainText('did:');
  // Its sessions a page at a time: shown all, to find it.
  while (await page.getByRole('button', { name: 'Show more' }).count())
    await page.getByRole('button', { name: 'Show more' }).click();
  await page.getByRole('button', { name: "Revoke Phone's access" }).click();
  await page
    .getByRole('dialog', { name: "Revoke this app's access?" })
    .filter({ visible: true })
    .getByRole('button', { name: 'Revoke', exact: true })
    .click();
  // The console's own token, from inviting, stays.
  await expect(page.locator('.sessions', { hasText: 'With an app password' })).toHaveCount(0);
  await page.getByRole('button', { name: 'Revoke “Phone”' }).click();
  await page
    .getByRole('dialog', { name: 'Revoke this app password?' })
    .filter({ visible: true })
    .getByRole('button', { name: 'Revoke', exact: true })
    .click();
  await expect(page.locator('.passwords')).toHaveCount(0);
  expect((await signIn()).status).toBe(401);
});

test('adding a recovery key, and removing it', async () => {
  const key = didKey();
  await page.goto(url('/g/hikers.groups.test/settings/recovery'));
  await expect(page.locator('.recovery-keys li')).toHaveCount(1);
  await page.getByRole('button', { name: 'Add a recovery key' }).click();
  await page.getByRole('textbox', { name: 'A key of yours, as a did:key' }).fill(key);
  await page
    .getByRole('dialog', { name: 'Add a recovery key' })
    .getByRole('button', { name: 'Add', exact: true })
    .click();
  const keys = page.locator('.recovery-keys li');
  await expect(keys).toHaveCount(2);
  await expect(keys.first()).toContainText(key);
  await expect(keys.last()).toContainText('This host');
  await keys.first().getByRole('button', { name: 'Remove' }).click();
  await page
    .getByRole('dialog', { name: 'Remove this key?' })
    .filter({ visible: true })
    .getByRole('button', { name: 'Remove', exact: true })
    .click();
  await expect(page.locator('.recovery-keys li')).toHaveCount(1);
});

test('moderating: a label, and the queue', async () => {
  // A label of the group's own, defined in its settings.
  await page.goto(url('/g/hikers.groups.test/settings/labels'));
  await expect(page.getByText('No labels yet')).toBeVisible();
  await page.getByRole('button', { name: 'Create a label' }).click();
  const defining = page.getByRole('dialog', { name: 'Create a label' });
  await defining.getByRole('textbox', { name: 'Name' }).fill('Off-topic');
  await defining.getByRole('textbox', { name: 'Value' }).fill('off-topic');
  await defining.getByRole('textbox', { name: 'What it means' }).fill('Not about hiking.');
  await defining.getByRole('combobox', { name: 'How apps show it' }).selectOption('hide');
  await defining.getByRole('button', { name: 'Create', exact: true }).click();
  await expect(page.locator('.label-rows')).toContainText('Not about hiking.');
  await expect(page.locator('.label-rows')).toContainText('Apps hide it until someone chooses');
  await page.goto(url('/g/hikers.groups.test'));
  await page.getByRole('link', { name: 'Moderation' }).click();
  // A subject's row, by its handle, not those whose history names it.
  const row = (handle) =>
    page
      .locator('li.subject')
      .filter({ has: page.locator(':scope > .row-main .who', { hasText: handle }) });
  const review = page.getByRole('dialog', { name: 'Review' }).filter({ visible: true });
  // Putting him out is already in the queue, on him.
  await expect(row(who.bob.handle).locator(':scope > .history .events')).toContainText('Removed');
  // Found by his handle, he is reviewed where his row is.
  await page.getByRole('combobox', { name: 'Find an account' }).fill(who.bob.handle);
  await page.getByRole('search').getByRole('button', { name: 'Review' }).click();
  // The group's own label is offered by its name.
  await expect(review.getByRole('button', { name: 'Add the label off-topic' })).toHaveText(
    'Off-topic'
  );
  await review.getByRole('textbox', { name: 'Add a label' }).fill('troll');
  await review.getByRole('button', { name: 'Add', exact: true }).click();
  await expect(review.locator('.labels')).toContainText('troll');
  // Taken off, it is a label the group has used, to put back with a press.
  await review.getByRole('button', { name: 'Remove the label troll' }).click();
  await expect(review.locator('.labels')).toHaveCount(0);
  await review.getByRole('button', { name: 'Add the label troll' }).click();
  await expect(review.locator('.labels')).toContainText('troll');
  // Taking him down asks first.
  await review.getByRole('button', { name: 'Take down' }).click();
  await page
    .getByRole('dialog', { name: 'Take this account down?' })
    .getByRole('button', { name: 'Take down' })
    .click();
  await expect(review.locator('.labels')).toContainText('!takedown');
  // Escalated with a note: tagged so, it stays open, and shows on the
  // escalated tab too.
  await review.getByRole('textbox', { name: 'Note' }).fill('Asked him to stop');
  await review.getByRole('button', { name: 'Escalate' }).click();
  await expect(review).toHaveCount(0);
  await expect(row(who.bob.handle).locator(':scope > .row-main .tags')).toContainText('Escalated');
  await page
    .getByRole('navigation', { name: 'The queue' })
    .getByRole('link', { name: 'Escalated' })
    .click();
  const history = () => row(who.bob.handle).locator(':scope > .history .events');
  await expect(history()).toContainText('Escalated by');
  await expect(history()).toContainText('Asked him to stop');
  // Resolved, it leaves the escalated tab for the resolved.
  await row(who.bob.handle).getByRole('button', { name: 'Review' }).click();
  await review.getByRole('button', { name: 'Resolve' }).click();
  await expect(review).toHaveCount(0);
  await expect(row(who.bob.handle)).toHaveCount(0);
  await page.goto(url('/g/hikers.groups.test/moderation?status=resolved'));
  await expect(history()).toContainText('Resolved');
  // Reopened, it is open again; then no longer escalated.
  await row(who.bob.handle).getByRole('button', { name: 'Review' }).click();
  await review.getByRole('button', { name: 'Reopen' }).click();
  await expect(review).toHaveCount(0);
  await expect(row(who.bob.handle)).toHaveCount(0);
  await page.goto(url('/g/hikers.groups.test/moderation?status=open'));
  await expect(history()).toContainText('Reopened');
  await row(who.bob.handle).getByRole('button', { name: 'Review' }).click();
  await review.getByRole('button', { name: 'Remove escalation' }).click();
  await expect(review).toHaveCount(0);
  await expect(history()).toContainText('Escalation removed');
  await expect(row(who.bob.handle).locator(':scope > .row-main .tags')).not.toContainText(
    'Escalated'
  );
  // Someone nobody reported is reported from their review, into the open queue.
  await page.goto(url('/g/hikers.groups.test/moderation'));
  await page.getByRole('combobox', { name: 'Find an account' }).fill(who.dan.handle);
  await page.getByRole('search').getByRole('button', { name: 'Review' }).click();
  await expect(review).toContainText('Not in the queue');
  await review.getByRole('button', { name: 'Report this account' }).click();
  const reporting = page.getByRole('dialog', { name: 'Report an account' });
  await reporting.getByRole('radio', { name: 'Rude' }).check();
  await reporting.getByRole('textbox', { name: 'What happened' }).fill('Shouted at a newcomer.');
  await reporting.getByRole('button', { name: 'Report', exact: true }).click();
  await expect(row(who.dan.handle)).toContainText('Shouted at a newcomer.');
  // The group's own label, no longer defined, is no longer offered.
  await page.goto(url('/g/hikers.groups.test/settings/labels'));
  await page.getByRole('button', { name: 'Delete the label off-topic' }).click();
  await page
    .getByRole('dialog', { name: 'Delete this label?' })
    .getByRole('button', { name: 'Delete', exact: true })
    .click();
  await expect(page.getByText('No labels yet')).toBeVisible();
});

test('signing an app in as her group', async () => {
  const app = await new App('atproto repo:app.bsky.feed.post').listen();
  await page.goto(await app.push());
  await expect(page.getByRole('heading', { name: 'Sign in an app' })).toBeVisible();
  // Said as her PDS says it: Bluesky, and in its details, the posts.
  const riders = page.locator('form', { hasText: '@riders.groups.test' });
  await expect(riders.getByText("Use parts of the group's Bluesky account")).toBeVisible();
  await riders.getByRole('button', { name: 'Details' }).click();
  const details = page.getByRole('dialog', { name: 'Bluesky' }).filter({ visible: true });
  await expect(details.getByRole('row', { name: /app\.bsky\.feed\.post/ })).toBeVisible();
  await details.getByRole('button', { name: 'Close' }).click();
  await page.getByRole('button', { name: 'Technical details' }).click();
  await expect(page.getByRole('dialog', { name: 'Technical details' })).toContainText(
    'repo:app.bsky.feed.post'
  );
  await page
    .getByRole('dialog', { name: 'Technical details' })
    .getByRole('button', { name: 'Close' })
    .click();
  await page.getByRole('button', { name: 'Sign it in as Riders' }).click();
  const back = await app.back;
  app.close();
  expect(new URL(back).searchParams.get('state')).toBe('st4te');
  const tokens = await app.exchange(back);
  expect(tokens.sub).toBe(world.riders);
  expect(tokens.scope).toBe('atproto repo:app.bsky.feed.post');

  // The app writes as the group, and it is there.
  const record = {
    $type: 'app.bsky.feed.post',
    text: 'Ride on Saturday',
    createdAt: new Date().toISOString()
  };
  const made = await app.call('com.atproto.repo.createRecord', tokens.access_token, {
    repo: world.riders,
    collection: 'app.bsky.feed.post',
    record
  });
  expect(made.status, JSON.stringify(made.body)).toBe(200);
  const rkey = made.body.uri.split('/').pop();
  const read = await fetch(
    `${world.host}/xrpc/com.atproto.repo.getRecord?repo=${world.riders}&collection=app.bsky.feed.post&rkey=${rkey}`
  );
  expect((await read.json()).value.text).toBe('Ride on Saturday');
});

test('approving an app that reads her group, and revoking it', async () => {
  const asked = [
    'atproto',
    'space:org.atgrp.meta?action=read',
    'space:org.atgrp.members?action=read',
    'rpc:org.atgrp.listJoinRequests?aud=*'
  ].join(' ');
  const app = await new App(asked).listen();
  await page.goto(await app.push());
  // Said plainly: what it reads, that it writes nothing, and the
  // host's methods it calls.
  const riders = page.locator('form', { hasText: '@riders.groups.test' });
  await expect(
    riders.getByText(
      "Read the group's profile and its members, roles, rules and labels, and write nothing"
    )
  ).toBeVisible();
  await expect(
    riders.getByText(
      "Use the group's own methods here, as your roles let you: see requests to join"
    )
  ).toBeVisible();
  await page.getByRole('button', { name: 'Sign it in as Riders' }).click();
  const back = await app.back;
  app.close();
  const tokens = await app.exchange(back);
  expect(tokens.scope.split(' ')).toContain('rpc:org.atgrp.listJoinRequests?aud=*');
  const requests = () =>
    app.send(
      `${world.host}/xrpc/org.atgrp.listJoinRequests?group=${world.riders}`,
      { method: 'GET' },
      tokens.access_token
    );
  expect((await requests()).status).toBe(200);

  // Listed among the apps acting as the group, by what it may do, and
  // revoked there. The loopback client names itself an app on this device.
  await page.goto(url('/g/riders.groups.test/settings/apps'));
  const reader = page.locator('.sessions li', {
    hasText: "Can read the group's profile and members, and see requests to join"
  });
  await reader.getByRole('button', { name: "Revoke An app on this device's access" }).click();
  await page
    .getByRole('dialog', { name: "Revoke this app's access?" })
    .filter({ visible: true })
    .getByRole('button', { name: 'Revoke', exact: true })
    .click();
  await expect(reader).toHaveCount(0);
  expect((await requests()).status).toBe(401);
});

test('connecting an AI app, and disconnecting it', async () => {
  const client = await new McpClient().listen();
  await page.goto(await client.authorize('Pocket helper'));
  await expect(page.getByText('wants to act as you in one of your groups')).toBeVisible();
  await expect(page.getByText("The app chose this name, and it isn't checked")).toBeVisible();
  await page.getByRole('button', { name: 'Connect it to Riders' }).click();
  const back = await client.back;
  client.close();
  expect(new URL(back).searchParams.get('state')).toBe('st4te');
  const tokens = await client.exchange(back);

  // It acts as her, in Riders, without saying which.
  const got = await client.tool(tokens.access_token, 'group_show', {});
  expect(got.status).toBe(200);
  expect(got.result.structuredContent.group.did).toBe(world.riders);

  await page.goto(url('/g/riders.groups.test'));
  await expect(page.locator('.ai-apps', { hasText: 'Pocket helper' })).toBeVisible();
  await page
    .locator('.ai-apps', { hasText: 'Pocket helper' })
    .getByRole('button', { name: 'Disconnect' })
    .click();
  await page
    .getByRole('dialog', { name: 'Disconnect this app?' })
    .filter({ visible: true })
    .getByRole('button', { name: 'Disconnect', exact: true })
    .click();
  await expect(page.getByText('No AI app connected yet')).toBeVisible();
  expect((await client.tool(tokens.access_token, 'group_show', {})).status).toBe(401);
});

test('declining an app', async () => {
  const app = await new App('atproto').listen();
  await page.goto(await app.push());
  await page.getByRole('button', { name: 'Decline' }).click();
  const back = await app.back;
  app.close();
  expect(new URL(back).searchParams.get('error')).toBe('access_denied');
});

test('coming to a request that has lapsed', async () => {
  await page.goto(
    url('/authorize?request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Areq-gone')
  );
  await expect(page.getByText('This sign-in request has expired')).toBeVisible();
});

test('switching a group off, back on, and deleting it', async () => {
  await page.goto(url('/new'));
  await page.getByRole('textbox', { name: 'Name' }).pressSequentially('Tandem');
  await page.getByRole('button', { name: 'Start the group' }).click();
  await page.waitForURL(url('/g/tandem.groups.test'));
  // Off from its settings, asked to be sure of; its page then says so.
  await page.goto(url('/g/tandem.groups.test/settings'));
  await page.getByRole('button', { name: 'Switch off' }).click();
  await page
    .getByRole('dialog', { name: 'Switch this group off?' })
    .getByRole('button', { name: 'Switch off' })
    .click();
  await page.waitForURL(url('/g/tandem.groups.test'));
  await expect(page.getByText('This group is switched off')).toBeVisible();
  // Bob, who never ran it, sees only that.
  await bob.goto(url('/g/tandem.groups.test'));
  await expect(bob.getByText('This group is switched off')).toBeVisible();
  await expect(bob.getByRole('button', { name: 'Switch back on' })).toHaveCount(0);
  // Back on, from its page.
  await page.getByRole('button', { name: 'Switch back on' }).click();
  await expect(page.getByText(/You're a member/)).toBeVisible();
  // Deleted, it is gone, and so is its page.
  await page.goto(url('/g/tandem.groups.test/settings'));
  await page.getByRole('button', { name: 'Delete the group' }).click();
  await page
    .getByRole('dialog', { name: 'Delete this group?' })
    .getByRole('button', { name: 'Delete', exact: true })
    .click();
  await page.waitForURL(url('/'));
  const gone = await page.goto(url('/g/tandem.groups.test'));
  expect(gone.status()).toBe(404);
});

test('moving an account here to become a group', async () => {
  await page.goto(url('/new'));
  await page.getByRole('link', { name: 'move an account you already have' }).click();
  const moving = page.getByRole('combobox', { name: 'The account to move' });
  await moving.fill(who.harbor.handle);
  await moving.press('Enter');
  // At its own server, as itself; then back, still alice.
  await approve(page, 'harbor');
  await page.waitForURL(url('/move'));
  await expect.poll(() => signedInAs(page)).toBe('@alice.test');
  await expect(page.getByText('Here it will be')).toContainText('@harbor.groups.test');
  await page.getByRole('button', { name: 'Copy it here' }).click();
  const code = page.getByRole('textbox', { name: 'The code' });
  await expect(code).toBeVisible();
  // The code its server emailed, from its inbox.
  const mail = await fetch(`${world.mail}?to=harbor@test.com`).then((r) => r.json());
  await code.fill(mail.code);
  await page.getByRole('button', { name: 'Finish moving it' }).click();
  await page.waitForURL(url('/g/harbor.groups.test'));
  await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
});

test('choosing to see it dark, and as her system has it again', async () => {
  await page.goto(url('/'));
  const html = page.locator('html');
  await expect(html).not.toHaveAttribute('data-theme');
  // From her menu: at once, and from the page's first byte after.
  await page.getByRole('banner').getByText('@alice.test', { exact: true }).click();
  const appearance = page.getByRole('radiogroup', { name: 'Appearance' });
  await appearance.getByText('Dark', { exact: true }).click();
  await expect(html).toHaveAttribute('data-theme', 'dark');
  const drawn = await page.reload();
  expect(await drawn.text()).toContain('data-theme="dark"');
  await expect(html).toHaveAttribute('data-theme', 'dark');
  await page.getByRole('banner').getByText('@alice.test', { exact: true }).click();
  await expect(appearance.getByRole('radio', { name: 'Dark' })).toBeChecked();
  await appearance.getByText('System', { exact: true }).click();
  await expect(html).not.toHaveAttribute('data-theme');
  await page.reload();
  await expect(html).not.toHaveAttribute('data-theme');
});

test('signing out', async () => {
  await page.goto(url('/'));
  // From her menu, under her handle: what is hers, and signing out last.
  await page.getByRole('banner').getByText('@alice.test', { exact: true }).click();
  const menu = page.locator('.user-menu .menu');
  await expect(menu.getByRole('link')).toHaveText([
    'Invites',
    'Your groups',
    'Start a group',
    'Move an account here'
  ]);
  await menu.getByRole('button', { name: 'Sign out' }).click();
  await expect(page.getByRole('banner').getByRole('button', { name: 'Sign in' })).toBeVisible();
  await expect.poll(() => signedInAs(page)).toBe('');
});