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

E2E Tests - ODG #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/e2e.ts',
},
})
1 change: 1 addition & 0 deletions frontend/cypress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="cypress" />
6 changes: 6 additions & 0 deletions frontend/cypress/e2e/example.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('My First Test', () => {
it('Visits the app', () => {
cy.visit('/')
cy.contains('h1', 'Dashboard del Reclutador')
})
})
65 changes: 65 additions & 0 deletions frontend/cypress/e2e/position.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getHandleSelector, getDroppableSelector } from '../support/util';

interface Candidate {
id: number;
name: string;
}

interface CandidatesByColumn {
[key: string]: Candidate[];
}

describe('Position Details Page', () => {
const positionTitle = 'Senior Full-Stack Engineer';
const columns: string[] = ['Initial Screening', 'Technical Interview', 'Manager Interview'];
const candidates: CandidatesByColumn = {
'Initial Screening': [{ id: 3, name: 'Carlos García' }],
'Technical Interview': [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Smith' }],
'Manager Interview': []
};

beforeEach(() => {
cy.visit('/positions/1');
});

it('Carga de la Página de Position', () => {
cy.get('h2').should('contain', positionTitle);

columns.forEach((column, index) => {
cy.get('.row > div').eq(index).find('.card-header').should('contain', column);

const candidatesInColumn = candidates[column];
cy.get('.row > div').eq(index).find('.card-body > .card').should('have.length', candidatesInColumn.length);

candidatesInColumn.forEach(candidate => {
cy.get('.row > div').eq(index).find('.card').should('contain', candidate.name);
});
});
});

it('Cambio de Fase de un Candidato', () => {
const sourceColumn = 'Initial Screening';
const targetColumn = 'Technical Interview';
const candidateToMove = candidates[sourceColumn][0];

const sourceSelector = getDroppableSelector(columns.indexOf(sourceColumn));
const targetSelector = getDroppableSelector(columns.indexOf(targetColumn));
const draggableSelector = getHandleSelector(candidateToMove.id);

cy.get(sourceSelector).find(draggableSelector).as('dragHandle');

cy.get('@dragHandle')
.move({ to: targetSelector });

cy.get(targetSelector)
.find(draggableSelector)
.should('exist');

cy.get(sourceSelector)
.find(draggableSelector)
.should('not.exist');

cy.intercept('PUT', '/candidates/*').as('updateCandidate');
cy.wait('@updateCandidate').its('response.statusCode').should('eq', 200);
});
});
12 changes: 12 additions & 0 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as keyCodes from './key-codes';

Cypress.Commands.add('move', { prevSubject: 'element' }, (subject, options: { to: string }) => {
cy.wrap(subject)
.focus()
.trigger('keydown', { keyCode: keyCodes.space })
.trigger('keydown', { keyCode: keyCodes.arrowRight, force: true })
.wait(0.2 * 1000)
.trigger('keydown', { keyCode: keyCodes.space, force: true });

cy.get(options.to).should('exist');
});
1 change: 1 addition & 0 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands'
5 changes: 5 additions & 0 deletions frontend/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace Cypress {
interface Chainable<Subject> {
move(options: { to: string }): Chainable<Subject>
}
}
13 changes: 13 additions & 0 deletions frontend/cypress/support/key-codes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow
export const tab: number = 9;
export const enter: number = 13;
export const escape: number = 27;
export const space: number = 32;
export const pageUp: number = 33;
export const pageDown: number = 34;
export const end: number = 35;
export const home: number = 36;
export const arrowLeft: number = 37;
export const arrowUp: number = 38;
export const arrowRight: number = 39;
export const arrowDown: number = 40;
2 changes: 2 additions & 0 deletions frontend/cypress/support/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const getHandleSelector = (id: number) => `[data-rbd-draggable-id='${id}']`;
export const getDroppableSelector = (id: number) => `[data-rbd-droppable-id='${id}']`;
Loading