|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { FIXTURES } from './fixtures'; |
| 3 | + |
| 4 | +const VIEWER_RESPONSE = { |
| 5 | + data: { Viewer: { id: 9, name: 'alice', avatar: { medium: null } } }, |
| 6 | +}; |
| 7 | + |
| 8 | +const mockAnilist = async (page: import('@playwright/test').Page) => { |
| 9 | + await page.route('https://graphql.anilist.co/**', async (route) => { |
| 10 | + const body = route.request().postDataJSON() as { query: string; variables?: { name?: string } }; |
| 11 | + if (body.query.includes('Viewer')) { |
| 12 | + await route.fulfill({ json: VIEWER_RESPONSE }); |
| 13 | + return; |
| 14 | + } |
| 15 | + if (body.query.includes('users(search')) { |
| 16 | + await route.fulfill({ json: { data: { Page: { users: [] } } } }); |
| 17 | + return; |
| 18 | + } |
| 19 | + const fixture = FIXTURES[body.variables?.name ?? '']; |
| 20 | + if (!fixture) { |
| 21 | + await route.fulfill({ status: 404, json: { errors: [{ message: 'User not found' }] } }); |
| 22 | + return; |
| 23 | + } |
| 24 | + await route.fulfill({ json: fixture }); |
| 25 | + }); |
| 26 | +}; |
| 27 | + |
| 28 | +test('logged out: connect prompt, unconfigured hint, public profile lookup', async ({ page }) => { |
| 29 | + await mockAnilist(page); |
| 30 | + await page.goto('/profile'); |
| 31 | + await expect(page.getByRole('heading', { name: 'My profile' })).toBeVisible(); |
| 32 | + |
| 33 | + // no OAuth client configured yet -> connect explains setup |
| 34 | + await page.getByRole('button', { name: 'Connect AniList' }).click(); |
| 35 | + await expect(page.locator('.picker-error')).toContainText('client ID'); |
| 36 | + |
| 37 | + // any public profile can still be viewed |
| 38 | + await page.getByPlaceholder('AniList username').fill('alice'); |
| 39 | + await page.getByRole('button', { name: 'View profile' }).click(); |
| 40 | + await expect(page.getByRole('heading', { name: 'alice' })).toBeVisible(); |
| 41 | + await expect(page).toHaveURL(/profile\?u=alice/); |
| 42 | + await expect(page.getByText('3 completed')).toBeVisible(); |
| 43 | + await expect(page.getByRole('heading', { name: 'Genre taste' })).toBeVisible(); |
| 44 | +}); |
| 45 | + |
| 46 | +test('auth callback stores the token and profile shows the viewer', async ({ page }) => { |
| 47 | + await mockAnilist(page); |
| 48 | + await page.goto('/auth/callback#access_token=e2e-token&token_type=Bearer&expires_in=3600'); |
| 49 | + await expect(page).toHaveURL(/\/profile/); |
| 50 | + await expect(page.getByText('Signed in as alice')).toBeVisible(); |
| 51 | + await expect(page.locator('.you')).toHaveText('YOU'); |
| 52 | + await expect(page.getByRole('button', { name: 'Log out' })).toBeVisible(); |
| 53 | + |
| 54 | + // log out returns to the connect prompt |
| 55 | + await page.getByRole('button', { name: 'Log out' }).click(); |
| 56 | + await expect(page.getByRole('button', { name: 'Connect AniList' })).toBeVisible(); |
| 57 | + await expect(page.getByText('Connect AniList', { exact: true }).first()).toBeVisible(); |
| 58 | +}); |
| 59 | + |
| 60 | +test('comparisons land in history: profile modules and picker chips', async ({ page }) => { |
| 61 | + await mockAnilist(page); |
| 62 | + await page.goto('/compare'); |
| 63 | + await page.getByPlaceholder('first username').fill('alice'); |
| 64 | + await page.getByPlaceholder('second username').fill('bob'); |
| 65 | + await page.getByRole('button', { name: 'Compare', exact: true }).click(); |
| 66 | + await expect(page.locator('.user-name').first()).toHaveText('alice'); |
| 67 | + |
| 68 | + await page.goto('/profile'); |
| 69 | + const recents = page.locator('.recents').first(); |
| 70 | + await expect(recents.getByText('alice × bob')).toBeVisible(); |
| 71 | + await expect(recents.getByText(/\/100/)).toBeVisible(); |
| 72 | + |
| 73 | + // fresh compare page offers the recent pair as a one-click chip |
| 74 | + await page.goto('/compare'); |
| 75 | + const chip = page.getByRole('button', { name: 'alice × bob' }); |
| 76 | + await expect(chip).toBeVisible(); |
| 77 | + await chip.click(); |
| 78 | + await expect(page.locator('.user-name').first()).toHaveText('alice'); |
| 79 | +}); |
| 80 | + |
| 81 | +test('groups land in history and reopen from profile', async ({ page }) => { |
| 82 | + await mockAnilist(page); |
| 83 | + await page.goto('/groups?users=alice,bob'); |
| 84 | + await expect(page.getByRole('columnheader', { name: 'alice' })).toBeVisible(); |
| 85 | + |
| 86 | + await page.goto('/profile'); |
| 87 | + const groupsModule = page.locator('.recents').nth(1); |
| 88 | + await expect(groupsModule.getByText('alice, bob')).toBeVisible(); |
| 89 | + await groupsModule.getByText('alice, bob').click(); |
| 90 | + await expect(page).toHaveURL(/groups\?users=alice,bob/); |
| 91 | +}); |
0 commit comments