~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
115 lines · 5.6 KB Raw History
// One browser signed in to two accounts: alice signs in, adds carol from
// the account menu's sign-in dialog, switches back to alice without
// signing in again, and signing out goes on as carol, then to the
// signed-out page; there, Sign in's dialog's Create one makes dave an
// account at the sign-up PDS, signed in. Then bob, in a browser of his
// own, deletes his HUD data from the account menu: the canvas he made
// listed, his handle typed, he is signed out, and signing in again finds
// a fresh workspace.

import { approve, expect, signIn, test, who, world } from './pages.mjs';

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

/** @type {import('@playwright/test').BrowserContext} */
let context;
/** @type {import('@playwright/test').Page} */
let page;

test.beforeAll(async ({ browser }) => {
	context = await browser.newContext();
	page = await context.newPage();
});
test.afterAll(() => context?.close());

const launcher = () => page.getByRole('main', { name: 'Columns' }).getByRole('region', { name: 'Open' });
/** The name the launcher's account row shows: whose workspace this is. */
const signedInAs = (name) => expect(launcher().getByText(name, { exact: true })).toBeVisible();
/** The tab bar's account menu, opened. */
const accountMenu = () => page.locator('details.account .menu');
const menu = async () => {
	await page.locator('details.account > summary').click();
	return accountMenu();
};
const dialog = () => page.getByRole('dialog', { name: 'Sign in with your Atmosphere account' });

test('carol added from the account menu joins alice in this browser', async () => {
	await signIn(page, 'alice');
	await signedInAs('Alice');
	await (await menu()).getByRole('button', { name: 'Add account' }).click();
	await dialog().getByLabel('Handle').fill(who.carol.did);
	await dialog().getByRole('button', { name: 'Sign in', exact: true }).click();
	await approve(page, 'carol');
	await page.waitForURL(`${world.base}/workspace`);
	await signedInAs('Carol');
	await expect((await menu()).getByTitle(/^Switch to /)).toHaveCount(1);
});

test('switching goes back to alice without signing in, and carol stays held', async () => {
	await accountMenu().getByTitle(/^Switch to /).click();
	await signedInAs('Alice');
	await expect((await menu()).getByTitle(/^Switch to /)).toHaveCount(1);
});

test('signing out goes on as carol, then to the signed-out page', async () => {
	await accountMenu().getByRole('button', { name: 'Sign out' }).click();
	await signedInAs('Carol');
	await expect((await menu()).getByTitle(/^Switch to /)).toHaveCount(0);
	await accountMenu().getByRole('button', { name: 'Sign out' }).click();
	await expect(page.getByRole('heading', { level: 1, name: 'Your Atmosphere, all in one place' })).toBeVisible();
	await expect(dialog()).toHaveCount(0);
});

test('Create one makes dave an account at the sign-up PDS and signs him in', async () => {
	await page.getByRole('banner').getByRole('button', { name: 'Sign in', exact: true }).click();
	await dialog().getByRole('button', { name: 'Create one' }).click();
	const pds = new URL(world.pds).origin;
	await page.waitForURL((u) => u.origin === pds);
	await page.getByRole('textbox', { name: 'Type your username' }).fill('dave');
	await page.getByRole('button', { name: 'Next' }).click();
	await page.getByRole('textbox', { name: 'Email' }).fill('dave@test.com');
	await page.getByRole('textbox', { name: 'Password' }).fill('a long password for dave');
	await page.getByRole('button', { name: 'Sign up' }).click();
	// Then what HUD asks, approved; back at the workspace as him.
	const accept = page.getByRole('button', { name: /^(accept|authorize|allow)$/i });
	for (let i = 0; i < 150 && new URL(page.url()).origin === pds; i++) {
		if (await accept.isVisible()) await accept.click({ timeout: 1000 }).catch(() => {});
		await page.waitForTimeout(200);
	}
	await page.waitForURL(`${world.base}/workspace`);
	await expect(launcher().getByText('@dave.test').first()).toBeVisible();
});

test('bob deletes his HUD data: signed out, and signed in again a fresh workspace', async ({ browser }) => {
	const bobs = await browser.newContext();
	try {
		const bob = await bobs.newPage();
		const tabs = () => bob.getByRole('tablist', { name: 'Canvases' }).getByRole('tab');
		await signIn(bob, 'bob');
		await bob.getByRole('banner').locator('summary[aria-label="Canvases"]').click();
		await bob.getByRole('menuitem', { name: /New canvas/ }).click();
		const name = bob.getByRole('tablist', { name: 'Canvases' }).getByRole('textbox', { name: 'Canvas name' });
		await expect(name).toBeFocused();
		await name.fill('Doomed canvas');
		await name.press('Enter');
		await expect(tabs().filter({ hasText: 'Doomed canvas' })).toHaveAttribute('aria-selected', 'true');

		await bob.locator('details.account > summary').click();
		await bob.locator('details.account .menu').getByRole('button', { name: 'Delete your HUD data' }).click();
		const deleting = bob.getByRole('dialog', { name: 'Delete your HUD data' });
		await expect(deleting.getByRole('listitem').filter({ hasText: 'Doomed canvas' })).toBeVisible();
		const remove = deleting.getByRole('button', { name: 'Delete all my HUD data' });
		await expect(remove).toBeDisabled();
		await deleting.getByLabel(`To confirm, type ${who.bob.handle}`).fill(who.bob.handle);
		await remove.click();
		await expect(bob.getByRole('heading', { level: 1, name: 'Your Atmosphere, all in one place' })).toBeVisible();

		await signIn(bob, 'bob');
		await expect(tabs()).toHaveCount(1);
		await expect(tabs().first()).toHaveText(/My canvas/);
		await bob.getByRole('banner').locator('summary[aria-label="Canvases"]').click();
		await expect(bob.getByRole('menuitem', { name: /Doomed canvas/ })).toHaveCount(0);
	} finally {
		await bobs.close();
	}
});