Skip to content

Commit

Permalink
E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadanand Pai committed Oct 4, 2023
1 parent 8c0244c commit 467a232
Show file tree
Hide file tree
Showing 17 changed files with 1,801 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
run: |
npm install
npm test
npm run e2e:test
rm -rf dist
npm run build
git add dist -f
Expand Down
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:5173',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
19 changes: 19 additions & 0 deletions cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
'value'
).set;

describe('template spec', () => {
beforeEach(() => {
cy.visit('/');
});

it('should verify sorting', () => {
cy.get('[data-testid="navbar"]').should('be.visible');

cy.get('[data-testid="navbar"]').should(
'contain.html',
'Sorting visualizers'
);
});
});
70 changes: 70 additions & 0 deletions cypress/e2e/sorting.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
'value'
).set;

function verifySorting() {
cy.get('#user-input').should('contain.value', '6, 8, 3, 5, 1, 9, 2, 7, 4');
cy.get('#user-input').type('{selectAll} 6, 8, 3, 5, 9, 2, 7');

cy.get('[data-testid="cell-values"]').should('contain.text', '6835927');
cy.get('#speed').then(($range) => {
const range = $range[0];
nativeInputValueSetter.call(range, 20);
range.dispatchEvent(
new Event('change', { value: 20, bubbles: true } as EventInit)
);
});

const player = cy.get('[data-testid="player"]');
player.click();

player.should('be.disabled');
cy.get('[data-testid="cell-values"]').should('contain.text', '2356789');
}

describe('template spec', () => {
beforeEach(() => {
cy.visit('/');
});

it('should verify bubble sort', () => {
cy.get('a').contains('bubble').click();
verifySorting();
});

it('should verify selection sort', () => {
cy.get('a').contains('selection').click();
verifySorting();
});

it('should verify insertion sort', () => {
cy.get('a').contains('insertion').click();
verifySorting();
});

it('should verify heap sort', () => {
cy.get('a').contains('heap').click();
verifySorting();
});

it('should verify merge sort', () => {
cy.get('a').contains('merge').click();
verifySorting();
});

it('should verify quick sort', () => {
cy.get('a').contains('quick').click();
verifySorting();
});

it('should verify shell sort', () => {
cy.get('a').contains('shell').click();
verifySorting();
});

it('should verify cocktail sort', () => {
cy.get('a').contains('cocktail').click();
verifySorting();
});
});
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
14 changes: 14 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"baseUrl": "http://localhost:5173",
"target": "ES2015",
"lib": ["ES2015", "dom"],
"types": ["cypress", "node"],
"moduleResolution": "NodeNext",
"module": "NodeNext",
"paths": {
"@/*": ["../src/*"]
}
},
"include": ["**/*.ts"]
}
Loading

0 comments on commit 467a232

Please sign in to comment.