mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added some cypress tests
This commit is contained in:
27
cypress-tests/cypress/e2e/01-login_spec.cy.js
Normal file
27
cypress-tests/cypress/e2e/01-login_spec.cy.js
Normal file
@@ -0,0 +1,27 @@
|
||||
describe('Testing Log In', () => {
|
||||
it('Gets Log In Page and Logs In', () => {
|
||||
cy.visit('/')
|
||||
|
||||
cy.contains('Log In').click()
|
||||
|
||||
// Should be on a new URL which
|
||||
// includes '/commands/actions'
|
||||
cy.url().should('include', '/users/sign_in')
|
||||
|
||||
// Get an input, type into it
|
||||
cy.get('[id=user_email]').type(Cypress.env('CYPRESS_USERNAME'))
|
||||
|
||||
// Verify that the value has been updated
|
||||
cy.get('[id=user_email]').should('have.value', Cypress.env('CYPRESS_USERNAME'))
|
||||
|
||||
// Get an input, type into it
|
||||
cy.get('[id=user_password]').type(Cypress.env('CYPRESS_PASSWORD'))
|
||||
|
||||
// Verify that the value has been updated
|
||||
cy.get('[id=user_password]').should('have.value', Cypress.env('CYPRESS_PASSWORD'))
|
||||
|
||||
cy.get('input[type=submit]').click()
|
||||
|
||||
cy.contains('Signed in successfully')
|
||||
})
|
||||
})
|
||||
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';
|
||||
Reference in New Issue
Block a user