From beb2cfb8f02cbef8fc7380fb642ef907eb35599c Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Wed, 15 Feb 2023 22:34:55 +0000 Subject: [PATCH] add e2e ui test to check account posts and posts-and-replies tabs --- .../routes/(frontend)/[accountId]/index.tsx | 36 +++++++++--------- .../[accountId]/with_replies/index.tsx | 38 +++++++++---------- ui-e2e-tests/account-page.spec.ts | 32 ++++++++++++---- 3 files changed, 60 insertions(+), 46 deletions(-) diff --git a/frontend/src/routes/(frontend)/[accountId]/index.tsx b/frontend/src/routes/(frontend)/[accountId]/index.tsx index 1453fa0..c82c357 100644 --- a/frontend/src/routes/(frontend)/[accountId]/index.tsx +++ b/frontend/src/routes/(frontend)/[accountId]/index.tsx @@ -40,25 +40,23 @@ export default component$(() => { const { accountId, statuses } = statusesLoader.use().value return ( - <> -
- { - let statuses: MastodonStatus[] = [] - try { - const response = await fetch(`/api/v1/accounts/${accountId}/statuses?offset=${numOfCurrentStatuses}`) - if (response.ok) { - const results = await response.text() - statuses = JSON.parse(results) - } - } catch { - /* empty */ +
+ { + let statuses: MastodonStatus[] = [] + try { + const response = await fetch(`/api/v1/accounts/${accountId}/statuses?offset=${numOfCurrentStatuses}`) + if (response.ok) { + const results = await response.text() + statuses = JSON.parse(results) } - return statuses - })} - /> -
- + } catch { + /* empty */ + } + return statuses + })} + /> +
) }) diff --git a/frontend/src/routes/(frontend)/[accountId]/with_replies/index.tsx b/frontend/src/routes/(frontend)/[accountId]/with_replies/index.tsx index 256775a..2784c8c 100644 --- a/frontend/src/routes/(frontend)/[accountId]/with_replies/index.tsx +++ b/frontend/src/routes/(frontend)/[accountId]/with_replies/index.tsx @@ -40,27 +40,25 @@ export default component$(() => { const { accountId, statuses } = statusesLoader.use().value return ( -
-
- { - let statuses: MastodonStatus[] = [] - try { - const response = await fetch( - `/api/v1/accounts/${accountId}/statuses?offset=${numOfCurrentStatuses}&with-replies=true` - ) - if (response.ok) { - const results = await response.text() - statuses = JSON.parse(results) - } - } catch { - /* empty */ +
+ { + let statuses: MastodonStatus[] = [] + try { + const response = await fetch( + `/api/v1/accounts/${accountId}/statuses?offset=${numOfCurrentStatuses}&with-replies=true` + ) + if (response.ok) { + const results = await response.text() + statuses = JSON.parse(results) } - return statuses - })} - /> -
+ } catch { + /* empty */ + } + return statuses + })} + />
) }) diff --git a/ui-e2e-tests/account-page.spec.ts b/ui-e2e-tests/account-page.spec.ts index e0b9339..ffc3f5a 100644 --- a/ui-e2e-tests/account-page.spec.ts +++ b/ui-e2e-tests/account-page.spec.ts @@ -9,13 +9,11 @@ test(`Navigation via to and view of an account (with 1 post)`, async ({ page }) await expect(page.getByTestId('account-info').getByText('Joined')).toBeVisible() await expect(page.getByTestId('account-info').getByTestId('stats')).toHaveText('1Posts0Following0Followers') - expect(await page.getByTestId('account-statuses').getByRole('article').count()).toBe(1) + expect(await page.getByTestId('account-posts').getByRole('article').count()).toBe(1) await expect( - page.getByTestId('account-statuses').getByRole('article').getByRole('img', { name: 'Avatar of Ben, just Ben' }) + page.getByTestId('account-posts').getByRole('article').getByRole('img', { name: 'Avatar of Ben, just Ben' }) ).toBeVisible() - await expect(page.getByTestId('account-statuses').getByRole('article')).toContainText( - 'A very simple update: all good!' - ) + await expect(page.getByTestId('account-posts').getByRole('article')).toContainText('A very simple update: all good!') }) test('Navigation to and view of an account (with 2 posts)', async ({ page }) => { @@ -28,10 +26,30 @@ test('Navigation to and view of an account (with 2 posts)', async ({ page }) => await expect(page.getByTestId('account-info').getByText('Joined')).toBeVisible() await expect(page.getByTestId('account-info').getByTestId('stats')).toHaveText('2Posts0Following0Followers') - expect(await page.getByTestId('account-statuses').getByRole('article').count()).toBe(2) - const [post1Locator, post2Locator] = await page.getByTestId('account-statuses').getByRole('article').all() + expect(await page.getByTestId('account-posts').getByRole('article').count()).toBe(2) + const [post1Locator, post2Locator] = await page.getByTestId('account-posts').getByRole('article').all() await expect(post1Locator.getByRole('img', { name: 'Avatar of Raffa123$' })).toBeVisible() await expect(post1Locator).toContainText("I'm Rafael and I am a web designer") await expect(post2Locator.getByRole('img', { name: 'Avatar of Raffa123$' })).toBeVisible() await expect(post2Locator).toContainText('Hi! My name is Rafael!') }) + +test('View of an account with only a reply and 0 posts', async ({ page }) => { + await page.goto('http://127.0.0.1:8788/@Penny') + + await expect(page.getByTestId('account-posts')).toBeVisible() + await expect(page.getByTestId('account-posts')).toHaveText('Nothing to see right now. Check back later!') + await expect(page.getByTestId('account-posts-and-replies')).not.toBeVisible() + + await page.getByRole('link', { name: 'Posts and replies' }).click() + + await expect(page.getByTestId('account-posts-and-replies')).toBeVisible() + await expect(page.getByTestId('account-posts-and-replies').getByRole('article')).toContainText('Yes you guys did it!') + await expect(page.getByTestId('account-posts')).not.toBeVisible() + + await page.getByRole('link', { name: 'Posts', exact: true }).click() + + await expect(page.getByTestId('account-posts')).toBeVisible() + await expect(page.getByTestId('account-posts')).toHaveText('Nothing to see right now. Check back later!') + await expect(page.getByTestId('account-posts-and-replies')).not.toBeVisible() +})