Skip to content

Commit

Permalink
feat: E2E auth tests
Browse files Browse the repository at this point in the history
Signed-off-by: Azanul <azanulhaque@gmail.com>
  • Loading branch information
Azanul committed Jun 9, 2024
1 parent 3e381ed commit 0bc28f7
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
60 changes: 60 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@playwright/test": "^1.44.1",
"autoprefixer": "^10.4.19",
"nth-check": "^2.1.1",
"postcss": "^8.4.38",
Expand Down
77 changes: 77 additions & 0 deletions frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* 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. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
93 changes: 93 additions & 0 deletions frontend/tests/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { test, expect } from '@playwright/test';

test.describe('Registration Page Tests', () => {

test('Registration form contains email, password and confirm password fields', async ({ page }) => {
// Go to the registration page
await page.goto('http://localhost:3000/register');

// Check if the login link exists and is visible
const loginLink = await page.$('a[href="/login"]');
expect(loginLink).not.toBeNull();
expect(await loginLink?.isVisible()).toBeTruthy();

// Check if the form exists
const form = await page.$('form');
expect(form).not.toBeNull();

// Check if the email input field exists
const emailField = await page.$('input[name="email"]');
expect(emailField).not.toBeNull();

// Check if the password input field exists
const passwordField = await page.$('input[name="password"]');
expect(passwordField).not.toBeNull();

// Check if the confirm password input field exists
const confirmPasswordField = await page.$('input[name="confirmPassword"]');
expect(confirmPasswordField).not.toBeNull();
});

test('Fill in the registration form and submit', async ({ page }) => {
// Go to the registration page
await page.goto('http://localhost:3000/register');

// Fill in the email input field
await page.fill('input[name="email"]', 'test@example.com');

// Fill in the password input field
await page.fill('input[name="password"]', 'Password123');

// Fill in the confirm password input field
await page.fill('input[name="confirmPassword"]', 'Password123');

// Submit the form
await page.click('button[type="submit"]');

// Check if the page is redirected to the home page
await page.waitForURL('http://localhost:3000/');
expect(page.url()).toBe('http://localhost:3000/');
});
});

test.describe('Login Page Tests', () => {
test('Login form contains email, password fields', async ({ page }) => {
// Go to the login page
await page.goto('http://localhost:3000/login');

// Check if the register link exists and is visible
const registerLink = await page.$('a[href="/register"]');
expect(registerLink).not.toBeNull();
expect(await registerLink?.isVisible()).toBeTruthy();

// Check if the form exists
const form = await page.$('form');
expect(form).not.toBeNull();

// Check if the email input field exists
const emailField = await page.$('input[name="email"]');
expect(emailField).not.toBeNull();

// Check if the password input field exists
const passwordField = await page.$('input[name="password"]');
expect(passwordField).not.toBeNull();
});

test('Fill in the login form and submit', async ({ page }) => {
// Go to the login page
await page.goto('http://localhost:3000/login');

// Fill in the email input field
await page.fill('input[name="email"]', 'test@example.com');

// Fill in the password input field
await page.fill('input[name="password"]', 'Password123');

// Submit the form
await page.click('button[type="submit"]');

// Check if the page is redirected to the home page
await page.waitForURL('http://localhost:3000/');
expect(page.url()).toBe('http://localhost:3000/');
});
});

0 comments on commit 0bc28f7

Please sign in to comment.