mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Added some cypress tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
FROM cypress/included:13.2.0
|
FROM cypress/included:13.2.0
|
||||||
|
|
||||||
COPY cypress.config.js /
|
COPY cypress.config.js /
|
||||||
COPY ./tests/* /cypress/e2e/
|
COPY ./cypress /cypress/
|
||||||
@@ -3,8 +3,9 @@ const { defineConfig } = require('cypress')
|
|||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
e2e: {
|
e2e: {
|
||||||
baseUrl: 'http://localhost',
|
baseUrl: 'http://localhost',
|
||||||
supportFile: false,
|
supportFile: 'cypress/support/e2e.js', // Path to e2e.js
|
||||||
video: false,
|
video: false,
|
||||||
|
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
CYPRESS_PASSWORD: 'password',
|
CYPRESS_PASSWORD: 'password',
|
||||||
|
|||||||
42
cypress-tests/cypress/e2e/02-create_tournament.cy.js
Normal file
42
cypress-tests/cypress/e2e/02-create_tournament.cy.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
describe('Create a tournament', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// Use cy.session() with the login helper
|
||||||
|
cy.session('authUser', () => {
|
||||||
|
// cy.login() comes from cypress/support/commands.js
|
||||||
|
cy.login();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Browses Tournaments and Creates a New Pool to bracket Tournament', () => {
|
||||||
|
// Navigate to the Browse Tournaments page
|
||||||
|
cy.visit('/');
|
||||||
|
cy.contains('Browse Tournaments').click();
|
||||||
|
|
||||||
|
// Verify we're on the tournaments page
|
||||||
|
cy.url().should('include', '/tournaments');
|
||||||
|
cy.contains('Upcoming Tournaments');
|
||||||
|
|
||||||
|
// Click "New Tournament"
|
||||||
|
cy.get('a[href="/tournaments/new"]').click();
|
||||||
|
|
||||||
|
// Verify we're on the "New Tournament" page
|
||||||
|
cy.url().should('include', '/tournaments/new');
|
||||||
|
|
||||||
|
// Fill out the tournament creation form
|
||||||
|
cy.get('input[name="tournament[name]"]').type('Cypress Test Tournament - Pool to bracket');
|
||||||
|
cy.get('input[name="tournament[address]"]').type('123 Wrestling Way');
|
||||||
|
cy.get('input[name="tournament[director]"]').type('John Doe');
|
||||||
|
cy.get('input[name="tournament[director_email]"]').type('john.doe@example.com');
|
||||||
|
cy.get('input[name="tournament[date]"]').type('2024-12-31');
|
||||||
|
cy.get('select[name="tournament[tournament_type]"]').select('Pool to bracket');
|
||||||
|
// cy.get('input[name="tournament[is_public]"]').check();
|
||||||
|
|
||||||
|
// Submit the form
|
||||||
|
cy.contains('Submit').click();
|
||||||
|
|
||||||
|
// Verify successful creation (adjust based on app behavior)
|
||||||
|
cy.url().should('include', '/tournaments');
|
||||||
|
cy.contains('Cypress Test Tournament - Pool to bracket');
|
||||||
|
cy.contains('Tournament was successfully created.')
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
describe('Pool to bracket setup', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// Use cy.session() with the login helper
|
||||||
|
cy.session('authUser', () => {
|
||||||
|
cy.login(); // Assume cy.login() is defined in commands.js
|
||||||
|
});
|
||||||
|
cy.visit('/');
|
||||||
|
cy.contains('Browse Tournaments').click();
|
||||||
|
cy.contains('Cypress Test Tournament - Pool to bracket').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Setup Pool to bracket tournament. 3 schools, hs boys weights, and wrestlers.', () => {
|
||||||
|
// Create he boys weights
|
||||||
|
// Listen for the confirmation popup and automatically confirm it
|
||||||
|
cy.on('window:confirm', (text) => {
|
||||||
|
// Assert the text in the popup, if needed
|
||||||
|
expect(text).to.equal('Are you sure? This will delete all current weights.');
|
||||||
|
return true; // Simulates clicking "OK"
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click the link to trigger the confirmation popup
|
||||||
|
cy.contains('Tournament Director Links').click();
|
||||||
|
cy.contains('Create Boys High School Weights (106-285)').click();
|
||||||
|
|
||||||
|
// Add assertions to verify the action
|
||||||
|
cy.url().should('include', '/tournaments/');
|
||||||
|
cy.contains('106.0');
|
||||||
|
|
||||||
|
// 16 schools
|
||||||
|
const schoolNames = Array.from({ length: 3 }, (_, i) => `School ${i + 1}`);
|
||||||
|
const weights = ['106.0', '113.0', '120.0', '126.0', '132.0', '138.0', '144.0', '150.0', '157.0', '165.0', '175.0', '190.0', '215.0', '285.0'];
|
||||||
|
let wrestlerCounter = 1;
|
||||||
|
|
||||||
|
schoolNames.forEach((schoolName) => {
|
||||||
|
// Click "New School"
|
||||||
|
cy.get('a[href^="/schools/new"]').click(); // Matches links starting with /schools/new
|
||||||
|
// Verify we're on the "New School" page
|
||||||
|
cy.url().should('include', '/schools/new');
|
||||||
|
// Fill out the school creation form
|
||||||
|
cy.get('input[name="school[name]"]').type(schoolName);
|
||||||
|
// Submit the form
|
||||||
|
cy.contains('Submit').click();
|
||||||
|
// Verify the school was created (adjust based on your app behavior)
|
||||||
|
cy.url().should('include', '/tournaments');
|
||||||
|
cy.contains('School was successfully created.');
|
||||||
|
});
|
||||||
|
cy.contains(`School 1`).click();
|
||||||
|
|
||||||
|
// Create wrestlers for this school
|
||||||
|
weights.forEach((weight) => {
|
||||||
|
cy.get('a[href^="/wrestlers/new"]').click();
|
||||||
|
// Fill out the wrestler form
|
||||||
|
cy.get('input[name="wrestler[name]"]').type(`Wrestler${wrestlerCounter}`);
|
||||||
|
|
||||||
|
// Select the weight class that matches the string variable
|
||||||
|
cy.get('select[name="wrestler[weight_id]"]').select(weight);
|
||||||
|
|
||||||
|
// Fill out the rest of the form
|
||||||
|
cy.get('input[name="wrestler[season_win]"]').type('0');
|
||||||
|
cy.get('input[name="wrestler[season_loss]"]').type('0');
|
||||||
|
cy.get('input[name="wrestler[criteria]"]').type('N/A');
|
||||||
|
// cy.get('input[name="wrestler[extra]"]').check();
|
||||||
|
|
||||||
|
// Submit the form
|
||||||
|
cy.get('input[type="submit"]').click();
|
||||||
|
|
||||||
|
cy.contains('Wrestler was successfully created.');
|
||||||
|
cy.contains(`Wrestler${wrestlerCounter}`);
|
||||||
|
wrestlerCounter++;
|
||||||
|
});
|
||||||
|
cy.contains('Tournament Home').click();
|
||||||
|
});
|
||||||
|
});
|
||||||
15
cypress-tests/cypress/support/commands.js
Normal file
15
cypress-tests/cypress/support/commands.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
Cypress.Commands.add('login', () => {
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.contains('Log In').click();
|
||||||
|
cy.url().should('include', '/users/sign_in');
|
||||||
|
|
||||||
|
// Fill in login form and submit
|
||||||
|
cy.get('[id=user_email]').type(Cypress.env('CYPRESS_USERNAME'));
|
||||||
|
cy.get('[id=user_password]').type(Cypress.env('CYPRESS_PASSWORD'));
|
||||||
|
cy.get('input[type=submit]').click();
|
||||||
|
|
||||||
|
// Verify successful login
|
||||||
|
cy.contains('Signed in successfully');
|
||||||
|
});
|
||||||
|
|
||||||
2
cypress-tests/cypress/support/e2e.js
Normal file
2
cypress-tests/cypress/support/e2e.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Import commands.js using ES2015 syntax:
|
||||||
|
import './commands';
|
||||||
@@ -3,6 +3,9 @@ project_dir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/.."
|
|||||||
cd ${project_dir}
|
cd ${project_dir}
|
||||||
|
|
||||||
cd deploy
|
cd deploy
|
||||||
|
docker-compose -f docker-compose-test.yml down
|
||||||
|
docker volume rm deploy_influxdb deploy_mysql
|
||||||
|
|
||||||
bash deploy-test.sh
|
bash deploy-test.sh
|
||||||
|
|
||||||
cd ../cypress-tests
|
cd ../cypress-tests
|
||||||
|
|||||||
Reference in New Issue
Block a user