Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Frontend code editors #358

Closed
wants to merge 16 commits into from
Prev Previous commit
Next Next commit
added playwright tests
henrychoy committed Oct 31, 2023
commit 3a6b5fe671d46d14586a0acae36e3a5a9da8911e
116 changes: 110 additions & 6 deletions flask-frontend/e2e/vue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,112 @@
import { test, expect } from '@playwright/test';

// See here how to get started:
// https://playwright.dev/docs/intro
test('visits the app root url', async ({ page }) => {
await page.goto('/');
await expect(page.locator('div.greetings > h1')).toHaveText('You did it!');
})
test('login and logout', async ({ page }) => {
await page.goto('http://localhost:5173/');
await expect(page.getByText('Login').nth(2)).toHaveText('Login');
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testuser');
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('test');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Logged In', { exact: true })).toHaveText('Logged In');
await expect(page.getByText('You are currently logged in as testuser')).toHaveText('You are currently logged in as testuser');
await expect(page.getByRole('button', { name: 'Log Out' })).toBeVisible()
await page.getByRole('button', { name: 'Log Out' }).click();
await expect(page.getByText('Login').nth(2)).toHaveText('Login');
});

test('change password', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testuser');
await page.getByLabel('Username').press('Tab');
await page.getByLabel('Password').fill('test');
await page.getByLabel('Password').press('Enter');
await page.getByLabel('Expand "Change Password"').click();
await expect(page.getByText('To change your password, enter your current and new password.')).toBeVisible()
await page.getByLabel('Current Password').click();
await page.getByLabel('Current Password').fill('test');
await page.getByLabel('New Password').click();
await page.getByLabel('New Password').fill('test1');
await page.getByRole('button', { name: 'Change Password', exact: true }).click();
await expect(page.getByText('Successfully changed password for user: testuser')).toBeVisible()
await expect(page.getByText('Login').nth(2)).toHaveText('Login');

// change password back to test
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testuser');
await page.getByLabel('Username').press('Tab');
await page.getByLabel('Password').fill('test1');
await page.getByLabel('Password').press('Enter');
await page.getByLabel('Expand "Change Password"').click();
await page.getByLabel('Current Password').click();
await page.getByLabel('Current Password').fill('test1');
await page.getByLabel('New Password').click();
await page.getByLabel('New Password').fill('test');
await page.getByRole('button', { name: 'Change Password', exact: true }).click();
await expect(page.getByText('Login').nth(2)).toHaveText('Login');
});

test('test endpoint', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testuser');
await page.getByLabel('Username').press('Tab');
await page.getByLabel('Password').fill('test');
await page.getByLabel('Password').press('Enter');
await page.getByRole('tab', { name: 'API' }).click();
await expect(page.getByRole('heading', { name: 'API' })).toBeVisible();
await page.getByLabel('Expand "Test Endpoints"').click();
await page.getByRole('button', { name: 'GET' }).click();
await expect(page.getByText('Response Code:')).toBeVisible();
});

test('required field warnings', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.locator('div').filter({ hasText: /^This field is required$/ }).first()).toBeVisible();
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testuser');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.locator('div').filter({ hasText: /^This field is required$/ }).first()).toBeVisible();
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('test');
await page.getByLabel('Password').press('Enter');
await page.getByLabel('Expand "Change Password"').click();
await page.getByRole('button', { name: 'Change Password', exact: true }).click();
await expect(page.locator('div').filter({ hasText: /^This field is required$/ }).first()).toBeVisible();
await page.getByLabel('Current Password').click();
await page.getByLabel('Current Password').fill('test');
await page.getByRole('button', { name: 'Change Password', exact: true }).click();
await expect(page.locator('div').filter({ hasText: /^This field is required$/ }).first()).toBeVisible();
await page.getByLabel('New Password').click();
await page.getByLabel('New Password').fill('test');
await page.getByLabel('Collapse "Change Password"').click();
await page.getByLabel('Expand "Delete Account"').click();
await page.getByRole('button', { name: 'Delete User' }).click();
await expect(page.locator('div').filter({ hasText: /^This field is required$/ }).first()).toBeVisible();
});

test('create and delete user', async ({ page }) => {
await page.goto('http://localhost:5173/');
await page.getByRole('button', { name: 'Signup.' }).click();
await expect(page.getByText('Register a new user account')).toBeVisible();
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testdeletion');
await page.getByLabel('Username').press('Tab');
await page.getByLabel('Password', { exact: true }).fill('test');
await page.getByLabel('Confirm Password').click();
await page.getByLabel('Confirm Password').fill('test');
await page.getByLabel('Confirm Password').press('Enter');
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('testdeletion');
await page.getByLabel('Username').press('Tab');
await page.getByLabel('Password').fill('test');
await page.getByLabel('Password').press('Enter');
await page.getByLabel('Expand "Delete Account"').click();
await expect(page.getByText('To delete your account, enter your password and press the delete button.')).toBeVisible();
await page.getByLabel('Password', { exact: true }).click();
await page.getByLabel('Password', { exact: true }).fill('test');
await page.getByRole('button', { name: 'Delete User' }).click();
await expect(page.getByText('Login').nth(2)).toHaveText('Login');
});
3 changes: 2 additions & 1 deletion flask-frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -26,7 +26,8 @@ const config: PlaywrightTestConfig = {
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
//workers: process.env.CI ? 1 : undefined,
workers: 1, // parallel user account tests were conflicting eachother
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */