Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #167 from smartive-education/feature/e2e-tests-cle…
Browse files Browse the repository at this point in the history
…anup

Feature/e2e tests cleanup
  • Loading branch information
tomschall authored Jun 6, 2023
2 parents 6ef4702 + 77fc59e commit bf81296
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
52 changes: 43 additions & 9 deletions __e2e__/authenticated.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,32 @@ 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');
await page.getByRole('button', { name: 'Absenden' }).click();
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}`);
Expand All @@ -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;
Expand All @@ -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}`);

Expand Down
1 change: 0 additions & 1 deletion __e2e__/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions __e2e__/noAuth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cookies": [],
"origins": []
}
7 changes: 2 additions & 5 deletions __e2e__/non-authenticated.test.tsx
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
14 changes: 14 additions & 0 deletions noAuth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookies": [],
"origins": [
{
"origin": "http://localhost:3000",
"localStorage": [
{
"name": "nextauth.message",
"value": "{\"event\":\"session\",\"data\":{\"trigger\":\"getSession\"},\"timestamp\":1684998429}"
}
]
}
]
}

0 comments on commit bf81296

Please sign in to comment.