diff --git a/__e2e__/authenticated.test.tsx b/__e2e__/authenticated.test.tsx index db52a2ac..1845c290 100644 --- a/__e2e__/authenticated.test.tsx +++ b/__e2e__/authenticated.test.tsx @@ -13,7 +13,7 @@ test.describe('01.authenticated tests', () => { await page.waitForLoadState('domcontentloaded'); }); - test('01.timeline - post message', async ({ page }) => { + test('01.timeline - should post a message', async ({ page }) => { await page.waitForSelector('[data-testid="testTextarea"]'); await page.getByTestId('testTextarea').fill(`${testMessage} #${hashTag}`); await page.waitForSelector('body'); @@ -21,15 +21,24 @@ test.describe('01.authenticated tests', () => { expect(page.getByRole('article').filter({ hasText: `${testMessage}` })); }); - test('03.timeline - post without text', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('networkidle'); - await page.waitForSelector('[data-testid="testTextarea"]'); - await page.getByRole('button', { name: 'Absenden' }).click(); - await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); + test('02.timeline - should like an article', async ({ page }) => { + await expect(async () => { + let hasArticleToBeLiked: boolean = false; + hasArticleToBeLiked = await page.isVisible(`text=${testMessage}`); + + if (hasArticleToBeLiked === true) { + await page + .getByRole('article') + .filter({ hasText: `${testMessage}` }) + .first() + .getByRole('button', { name: 'Like' }) + .click(); + } + }).toPass(); + expect(page.getByRole('button', { name: 'Liked' })); }); - test('03.timeline - click on hashtag', async ({ page }) => { + test('03.timeline - should click on hashtag', async ({ page }) => { await expect(async () => { let hasArticleToBeDelete: boolean = false; hasArticleToBeDelete = await page.isVisible(`text=${testMessage}`); @@ -54,7 +63,30 @@ test.describe('01.authenticated tests', () => { }).toPass(); }); - test('04.timeline - delete message', async ({ page }) => { + test('04.timeline - should post no message', async ({ page }) => { + await page.goto('/'); + await page.waitForLoadState('networkidle'); + await page.waitForSelector('[data-testid="testTextarea"]'); + await page.getByRole('button', { name: 'Absenden' }).click(); + await expect(page.locator('p').filter({ hasText: 'Das Textfeld darf nicht leer sein.' })).toBeInViewport(); + }); + + test('05.timeline - should list liked article', async ({ page }) => { + await page.getByRole('link', { name: 'Profile' }).click(); + await expect(page).toHaveURL(/profile/); + + await expect(async () => { + let hasLikedArticle: boolean = false; + hasLikedArticle = await page.isVisible(`text=${testMessage}`); + + if (hasLikedArticle === true) { + expect(page.getByRole('article').filter({ hasText: `${testMessage}` })); + expect(page.getByRole('button', { name: 'Liked' })); + } + }).toPass(); + }); + + test('06.timeline - should delete test message', async ({ page }) => { await page.waitForSelector('body, footer'); await expect(async () => { let hasArticleToBeDelete: boolean = false; @@ -68,6 +100,8 @@ test.describe('01.authenticated tests', () => { const article_id = await articleToBeDeleted.getAttribute('id'); expect(article_id, `👉 should have an article id ${article_id}`); + expect(articleToBeDeleted.locator('svg').last()); + await articleToBeDeleted.locator('svg').last().click(); console.log(`👉 deleting article with id ${article_id}`); diff --git a/__e2e__/globalSetup.ts b/__e2e__/globalSetup.ts index 646d7146..adc34867 100644 --- a/__e2e__/globalSetup.ts +++ b/__e2e__/globalSetup.ts @@ -18,7 +18,6 @@ const globalSetup = async (config: FullConfig) => { await page.getByRole('button', { name: 'Login' }).click(); await expect(page).toHaveURL(new RegExp(`${url}`)); await page.waitForSelector('body'); - await page.getByPlaceholder('username@domain').click(); await page.getByPlaceholder('username@domain').fill(user); await page.locator('#submit-button').click(); await page.getByLabel('Password').fill(pw); diff --git a/__e2e__/noAuth.json b/__e2e__/noAuth.json new file mode 100644 index 00000000..914e9266 --- /dev/null +++ b/__e2e__/noAuth.json @@ -0,0 +1,4 @@ +{ + "cookies": [], + "origins": [] +} diff --git a/__e2e__/non-authenticated.test.tsx b/__e2e__/non-authenticated.test.tsx index e82095cf..23458463 100644 --- a/__e2e__/non-authenticated.test.tsx +++ b/__e2e__/non-authenticated.test.tsx @@ -1,9 +1,10 @@ import { test, expect } from '@playwright/test'; test.describe.configure({ mode: 'serial' }); +test.use({ storageState: './noAuth.json' }); test.beforeEach(async ({ page, context }) => { - await context.clearCookies(); + // await context.clearCookies(); await page.goto('/'); await page.waitForLoadState('domcontentloaded'); await page.waitForSelector('body'); @@ -14,8 +15,6 @@ test.beforeEach(async ({ page, context }) => { test.describe('01.non-authenticated', () => { test('01.timeline - should have at least one article', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('networkidle'); await page.waitForSelector('body'); const articles = page.getByRole('article'); @@ -24,8 +23,6 @@ test.describe('01.non-authenticated', () => { }); test('02.timeline - should redirect to landingpage', async ({ page }) => { - await page.goto('/'); - await page.waitForLoadState('domcontentloaded'); await page.waitForSelector('body'); const article = page.getByRole('article').filter({ hasText: 'username' }).first(); const articles = page.getByRole('article'); diff --git a/noAuth.json b/noAuth.json new file mode 100644 index 00000000..0322be32 --- /dev/null +++ b/noAuth.json @@ -0,0 +1,14 @@ +{ + "cookies": [], + "origins": [ + { + "origin": "http://localhost:3000", + "localStorage": [ + { + "name": "nextauth.message", + "value": "{\"event\":\"session\",\"data\":{\"trigger\":\"getSession\"},\"timestamp\":1684998429}" + } + ] + } + ] +}