Skip to content

Commit

Permalink
Write some fun tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farisashai committed Jan 7, 2024
1 parent c87e70e commit 694012c
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 61 deletions.
53 changes: 0 additions & 53 deletions cypress/e2e/pages/auth/login.cy.ts

This file was deleted.

30 changes: 30 additions & 0 deletions cypress/e2e/pages/forgot-password.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference types="cypress" />

describe('Forgot Password Page', () => {
beforeEach(() => {
cy.visit('/forgot-password');
});

it('Should fail with missing email', () => {
cy.contains('button', 'Submit').click();
cy.contains('p', 'Required').should('exist');
});

it('Should fail with unknown email', () => {
const email = '[email protected]';
cy.get('input[name="email"]').type(email);
cy.contains('button', 'Submit').click();

cy.get('.Toastify').contains('There is no account associated with that email').should('exist');
});

it('Should succeed with valid email', () => {
cy.fixture('accounts').then(({ standard }) => {
const { email } = standard;
cy.get('input[name="email"]').type(email);
cy.contains('button', 'Submit').click();

cy.get('.Toastify').contains('Success').should('exist');
});
});
});
79 changes: 79 additions & 0 deletions cypress/e2e/pages/login.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/// <reference types="cypress" />

describe('Login Page', () => {
beforeEach(() => {
cy.visit('/login');
});

it('Should succeed with valid member login', () => {
cy.fixture('accounts').then(({ standard }) => {
const { email, password } = standard;

cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();

cy.location('pathname').should('equal', '/');
cy.getCookie('ACCESS_TOKEN').should('exist');
});
});

it('Should succeed with valid admin login', () => {
cy.fixture('accounts').then(({ admin }) => {
const { email, password } = admin;

cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();

cy.location('pathname').should('equal', '/');
cy.getCookie('ACCESS_TOKEN').should('exist');
cy.getCookie('USER').should('exist');
});
});

it('Should fail with invalid credentials', () => {
const [email, password] = ['[email protected]', 'abc'];

cy.get('input[name="email"]').type(email);
cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();

cy.get('.Toastify').contains('Unable to login').should('exist');
cy.location('pathname').should('equal', '/login');
});

it('Should fail with missing username', () => {
cy.fixture('accounts').then(({ standard }) => {
const { password } = standard;

cy.get('input[name="password"]').type(password);
cy.get('button').contains('Sign In').click();

cy.location('pathname').should('equal', '/login');
cy.get('p').contains('Required').should('exist');
});
});

it('Should fail with missing password', () => {
cy.fixture('accounts').then(({ standard }) => {
const { email } = standard;

cy.get('input[name="email"]').type(email);
cy.get('button').contains('Sign In').click();

cy.location('pathname').should('equal', '/login');
cy.get('p').get('Required').should('exist');
});
});

it('Should link to forgot password page', () => {
cy.get('a').contains('Forgot your password?').click();
cy.location('pathname').should('equal', '/forgot-password');
});

it('Should link to account register page', () => {
cy.get('a').contains('Sign Up').click();
cy.location('pathname').should('equal', '/register');
});
});
7 changes: 7 additions & 0 deletions cypress/e2e/pages/register.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

describe('Register Page', () => {
beforeEach(() => {
cy.visit('/register');
});
});
4 changes: 2 additions & 2 deletions cypress/fixtures/accounts.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"admin": {
"username": "[email protected]",
"email": "[email protected]",
"password": "password"
},
"standard": {
"username": "[email protected]",
"email": "[email protected]",
"password": "password"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"axios": "^1.6.0",
"axios-middleware": "^0.3.1",
"cookies-next": "^2.1.1",
"cypress": "^13.2.0",
"ics": "^3.7.2",
"luxon": "^3.3.0",
"next": "^13.2.5-canary.30",
Expand All @@ -49,13 +48,14 @@
"validator": "^13.9.0"
},
"devDependencies": {
"@types/totp-generator": "^0.0.5",
"@types/lodash": "^4.14.191",
"@types/luxon": "^3.3.0",
"@types/node": "18.8.1",
"@types/react": "18.0.21",
"@types/totp-generator": "^0.0.5",
"@types/validator": "^13.7.14",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"cypress": "13.6.2",
"eslint": "8.24.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2686,10 +2686,10 @@ csstype@^3.0.2, csstype@^3.1.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

cypress@^13.2.0:
version "13.2.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.2.0.tgz#10f73d06a0764764ffbb903a31e96e2118dcfc1d"
integrity sha512-AvDQxBydE771GTq0TR4ZUBvv9m9ffXuB/ueEtpDF/6gOcvFR96amgwSJP16Yhqw6VhmwqspT5nAGzoxxB+D89g==
cypress@13.6.2:
version "13.6.2"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.6.2.tgz#c70df09db0a45063298b3cecba2fa21109768e08"
integrity sha512-TW3bGdPU4BrfvMQYv1z3oMqj71YI4AlgJgnrycicmPZAXtvywVFZW9DAToshO65D97rCWfG/kqMFsYB6Kp91gQ==
dependencies:
"@cypress/request" "^3.0.0"
"@cypress/xvfb" "^1.2.4"
Expand Down

0 comments on commit 694012c

Please sign in to comment.