diff --git a/cypress-tests/Dockerfile b/cypress-tests/Dockerfile index 434ccc4..375e93e 100644 --- a/cypress-tests/Dockerfile +++ b/cypress-tests/Dockerfile @@ -1,4 +1,4 @@ FROM cypress/included:13.2.0 COPY cypress.config.js / -COPY ./tests/* /cypress/e2e/ \ No newline at end of file +COPY ./cypress /cypress/ \ No newline at end of file diff --git a/cypress-tests/cypress.config.js b/cypress-tests/cypress.config.js index 827086c..a4b09ee 100644 --- a/cypress-tests/cypress.config.js +++ b/cypress-tests/cypress.config.js @@ -3,8 +3,9 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ e2e: { baseUrl: 'http://localhost', - supportFile: false, + supportFile: 'cypress/support/e2e.js', // Path to e2e.js video: false, + }, env: { CYPRESS_PASSWORD: 'password', diff --git a/cypress-tests/tests/01-login_spec.cy.js b/cypress-tests/cypress/e2e/01-login_spec.cy.js similarity index 100% rename from cypress-tests/tests/01-login_spec.cy.js rename to cypress-tests/cypress/e2e/01-login_spec.cy.js diff --git a/cypress-tests/cypress/e2e/02-create_tournament.cy.js b/cypress-tests/cypress/e2e/02-create_tournament.cy.js new file mode 100644 index 0000000..15dc4de --- /dev/null +++ b/cypress-tests/cypress/e2e/02-create_tournament.cy.js @@ -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.') + }); +}); diff --git a/cypress-tests/cypress/e2e/03-pool_to_bracket_tournament_setup.cy.js b/cypress-tests/cypress/e2e/03-pool_to_bracket_tournament_setup.cy.js new file mode 100644 index 0000000..dd4a4cd --- /dev/null +++ b/cypress-tests/cypress/e2e/03-pool_to_bracket_tournament_setup.cy.js @@ -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(); + }); +}); diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js new file mode 100644 index 0000000..d03b107 --- /dev/null +++ b/cypress-tests/cypress/support/commands.js @@ -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'); + }); + \ No newline at end of file diff --git a/cypress-tests/cypress/support/e2e.js b/cypress-tests/cypress/support/e2e.js new file mode 100644 index 0000000..62c769d --- /dev/null +++ b/cypress-tests/cypress/support/e2e.js @@ -0,0 +1,2 @@ +// Import commands.js using ES2015 syntax: +import './commands'; \ No newline at end of file diff --git a/cypress-tests/run-cypress-tests.sh b/cypress-tests/run-cypress-tests.sh index 27ed4be..6ae999f 100644 --- a/cypress-tests/run-cypress-tests.sh +++ b/cypress-tests/run-cypress-tests.sh @@ -3,6 +3,9 @@ project_dir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/.." cd ${project_dir} cd deploy +docker-compose -f docker-compose-test.yml down +docker volume rm deploy_influxdb deploy_mysql + bash deploy-test.sh cd ../cypress-tests