-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,9 @@ | ||
import { expect, test as setup } from '@playwright/test' | ||
import { authFile, user } from './helpers' | ||
import { test as setup } from '@playwright/test' | ||
import { signup } from './events' | ||
import { authFile } from './helpers' | ||
|
||
setup('authenticate', async ({ page }) => { | ||
async function checkForChatPage() { | ||
await page.waitForURL('http://localhost:3000/chat') | ||
|
||
await expect( | ||
page.locator('header').filter({ hasText: user.username }), | ||
).toBeVisible() | ||
} | ||
|
||
// Sign up user | ||
await page.goto('http://localhost:3000/signup') | ||
await page.getByLabel('Username').fill(user.username) | ||
await page.getByLabel('Password').fill(user.password) | ||
await page.getByRole('button', { name: 'Create account' }).click() | ||
|
||
await expect(page.getByText(`Sign up success`)).toBeVisible() | ||
await checkForChatPage() | ||
|
||
// Logout user | ||
await page.getByLabel('logout').click() | ||
await page.waitForURL('http://localhost:3000/login') | ||
|
||
// Login | ||
await page.getByLabel('Username').fill(user.username) | ||
await page.getByLabel('Password').fill(user.password) | ||
await page.getByRole('button', { name: 'Continue' }).click() | ||
|
||
await expect(page.getByText(`Login success`)).toBeVisible() | ||
await checkForChatPage() | ||
await signup(page) | ||
|
||
await page.context().storageState({ path: authFile }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { faker } from '@faker-js/faker' | ||
import { Browser, expect, Page } from '@playwright/test' | ||
|
||
export const signup = async (page: Page) => { | ||
const user = { | ||
fullName: faker.person.fullName(), | ||
username: faker.internet.userName(), | ||
password: faker.internet.password(), | ||
} | ||
await page.goto('/auth/signup') | ||
await page.getByLabel('Full name').fill(user.fullName) | ||
await page.getByLabel('Username').fill(user.username) | ||
await page.getByLabel('Password').fill(user.password) | ||
await page.getByRole('button', { name: 'Create account' }).click() | ||
|
||
await expect(page.getByText(`Sign up success`)).toBeVisible() | ||
|
||
await page.waitForURL('/chat') | ||
|
||
await expect( | ||
page.locator('header').filter({ hasText: user.username }), | ||
).toBeVisible() | ||
|
||
return { user } | ||
} | ||
|
||
export const createNewUserSession = async (browser: Browser) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
|
||
const { user } = await signup(page) | ||
|
||
return { page, user } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters