Skip to content

Commit

Permalink
[playwright] chore: Separate login test (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsdave authored May 27, 2024
1 parent b377ef0 commit 5504171
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
<div className="login-page-form">
<form onSubmit={handleSubmit}>
<h3>Existing user login</h3>
{errorText !== "" && <span className='registration-form-error'>{errorText}</span>}
{errorText !== "" && <span data-testid="login-error-text" className='registration-form-error'>{errorText}</span>}
<input
type="text"
placeholder="Username"
Expand Down
1 change: 1 addition & 0 deletions playwright/pages/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LoginPage {
passwordInput = () => this.page.getByTestId('password');
loginButton = () => this.page.getByRole('button', { name: 'Login' });
signupLink = () => this.page.getByRole('link', { name: 'Sign up' });
loginErrorText = () => this.page.getByTestId('login-error-text');

async goto() {
await this.page.goto('/');
Expand Down
35 changes: 35 additions & 0 deletions playwright/tests/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect, Page } from '@playwright/test';
import { allure } from 'allure-playwright';
import LoginPage from '../pages/LoginPage';
import NotesPage from '../pages/NotesPage';

let page: Page;
let loginPage: LoginPage;
let notesPage: NotesPage;

const timeout = 60 * 1000;

test.beforeAll(async ({ browser }) => {
await allure.feature('User Login');
page = await browser.newPage();
loginPage = new LoginPage(page);
notesPage = new NotesPage(page);
});

test.beforeEach(async () => {
await loginPage.goto();
});

test.describe('Notes App Login', { tag: ['@PRODUCTION'] }, async () => {
test('should see user successfully logged in', async () => {
await loginPage.login('dave', 'test');
await expect(page).toHaveTitle(/Notes/, { timeout });
await expect(notesPage.spinnerContainer()).toBeHidden({ timeout });
});
test('should see error message when login fails', async () => {
await loginPage.login('dave', 'wrongpassword');
await expect(loginPage.loginErrorText()).toHaveText(
'Invalid username or password'
);
});
});
12 changes: 6 additions & 6 deletions playwright/tests/note.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ test.beforeAll(async ({ browser }) => {
loginPage = new LoginPage(page);
notesPage = new NotesPage(page);
await loginPage.goto();
await loginPage.login('dave', 'test');
});

test.describe('Notes App e2e flow', { tag: ['@PRODUCTION'] }, async () => {
test('Should see notes page login', async () => {
await loginPage.login('dave', 'test');
await expect(page).toHaveTitle(/Notes/, { timeout });
await expect(notesPage.spinnerContainer()).toBeHidden({ timeout });
});
Expand All @@ -38,11 +38,6 @@ test.describe('Notes App e2e flow', { tag: ['@PRODUCTION'] }, async () => {
await expect(notesPage.noteContent().first()).toHaveText(NOTE_CONTENT);
});

test('Should be able to Delete a Note', async () => {
await notesPage.deleteNote();
await expect(notesPage.noteTitle().first()).not.toHaveText(NOTE_TITLE);
});

test('Should be able to Edit a Note', async () => {
await notesPage.editNote({
title: EDITED_NOTE_TITLE,
Expand All @@ -54,6 +49,11 @@ test.describe('Notes App e2e flow', { tag: ['@PRODUCTION'] }, async () => {
);
});

test('Should be able to Delete a Note', async () => {
await notesPage.deleteNote();
await expect(notesPage.noteTitle().first()).not.toHaveText(NOTE_TITLE);
});

test('Should not be able to add Note without title', async () => {
await notesPage.addNote({
title: '',
Expand Down

1 comment on commit 5504171

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

97.43%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   App.tsx87.50%75%96%30–31, 40–41
   NoteApp.tsx94.44%100%96.99%70–74
src/api
   apiService.ts100%85.71%92.55%88–94
src/components
   Header.tsx100%100%100%
   Login.tsx81.82%100%98.59%32, 32–33
   Note.tsx100%100%100%
   NoteForm.tsx100%100%100%
   NoteFormModal.tsx100%100%100%
   NoteGrid.tsx100%100%100%
   RegistrationForm.tsx86.67%100%97.04%57, 57–61
   RegistrationLink.tsx100%100%100%
   Spinner.tsx100%100%100%

Please sign in to comment.