diff --git a/e2e/cypress/e2e/beer-pong-table-create.cy.js b/e2e/cypress/e2e/beer-pong-table-create.cy.js index 29b0925..c253349 100644 --- a/e2e/cypress/e2e/beer-pong-table-create.cy.js +++ b/e2e/cypress/e2e/beer-pong-table-create.cy.js @@ -12,17 +12,15 @@ context('create beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/create`); + cy.visit('/#/tournaments/1/tables/create'); - cy.get('input[name="name"]').type('TEST_TABLE'); + cy.get('input[name="name"]').type('TEST_TABLE'); - cy.get('button#create-beer-pong-table').click(); + cy.get('button#create-beer-pong-table').click(); - cy.wait('@createBeerPongTable'); + cy.wait('@createBeerPongTable'); - cy.contains('Successfully created new beer pong table'); - }); + cy.contains('Successfully created new beer pong table'); }); it('successfully create beer pong table', () => { @@ -30,15 +28,13 @@ context('create beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/create`); + cy.visit('/#/tournaments/1/tables/create'); - cy.get('input[name="name"]').type('`'); + cy.get('input[name="name"]').type('`'); - cy.get('button#create-beer-pong-table').click(); + cy.get('button#create-beer-pong-table').click(); - cy.contains("Name contains characters that aren't allowed."); - }); + cy.contains("Name contains characters that aren't allowed."); }); it('create beer pong table, but dont fill out the form', () => { @@ -46,12 +42,10 @@ context('create beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/create`); + cy.visit('/#/tournaments/1/tables/create'); - cy.get('button#create-beer-pong-table').click(); + cy.get('button#create-beer-pong-table').click(); - cy.contains('Name is required.'); - }); + cy.contains('Name is required.'); }); }); diff --git a/e2e/cypress/e2e/beer-pong-table-overview.cy.js b/e2e/cypress/e2e/beer-pong-table-overview.cy.js index 1aadf74..2277bc3 100644 --- a/e2e/cypress/e2e/beer-pong-table-overview.cy.js +++ b/e2e/cypress/e2e/beer-pong-table-overview.cy.js @@ -25,14 +25,14 @@ context('Get Beer Pong Tables', () => { }); context('Delete Beer Pong Table', () => { - let firstLoad = true; - beforeEach(() => { cy.loginTestUser(); cy.wait(2000); }); it('successfully deletes a beer pong table', () => { + let firstLoad = true; + // Intercept the initial GET request cy.intercept('GET', '/api/v1/beer-pong-tables/tournament/*', req => { req.reply(res => { @@ -67,7 +67,7 @@ context('Delete Beer Pong Table', () => { }); it('cancels beer pong table deletion', () => { - firstLoad = true; + let firstLoad = true; cy.intercept('GET', '/api/v1/beer-pong-tables/tournament/*', req => { req.reply(res => { diff --git a/e2e/cypress/e2e/beer-pong-table-update.cy.js b/e2e/cypress/e2e/beer-pong-table-update.cy.js index 360b7f8..c178ca4 100644 --- a/e2e/cypress/e2e/beer-pong-table-update.cy.js +++ b/e2e/cypress/e2e/beer-pong-table-update.cy.js @@ -17,18 +17,16 @@ context('update beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/1/update`); - cy.wait('@getBeerPongTable'); + cy.visit('/#/tournaments/1/tables/1/update'); + cy.wait('@getBeerPongTable'); - cy.get('input[name="name"]').type('TEST_TABLE'); + cy.get('input[name="name"]').type('TEST_TABLE'); - cy.get('button#update-beer-pong-table').click(); + cy.get('button#update-beer-pong-table').click(); - cy.wait('@updateBeerPongTable'); + cy.wait('@updateBeerPongTable'); - cy.contains('Successfully updated beer pong table'); - }); + cy.contains('Successfully updated beer pong table'); }); it('update beer pong table, but use a banned character as a name', () => { @@ -37,16 +35,14 @@ context('update beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/1/update`); - cy.wait('@getBeerPongTable'); + cy.visit('/#/tournaments/1/tables/1/update'); + cy.wait('@getBeerPongTable'); - cy.get('input[name="name"]').type('`'); + cy.get('input[name="name"]').type('`'); - cy.get('button#update-beer-pong-table').click(); + cy.get('button#update-beer-pong-table').click(); - cy.contains("Name contains characters that aren't allowed."); - }); + cy.contains("Name contains characters that aren't allowed."); }); it('update beer pong table, clear name field, but dont fill out the form', () => { @@ -55,15 +51,13 @@ context('update beer pong table', () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/1/tables/1/update`); - cy.wait('@getBeerPongTable'); + cy.visit('/#/tournaments/1/tables/1/update'); + cy.wait('@getBeerPongTable'); - cy.get('input[name="name"]').clear(); + cy.get('input[name="name"]').clear(); - cy.get('button#update-beer-pong-table').click(); + cy.get('button#update-beer-pong-table').click(); - cy.contains('Name is required.'); - }); + cy.contains('Name is required.'); }); }); diff --git a/e2e/cypress/e2e/edit-knockout-phase-tree.cy.ts b/e2e/cypress/e2e/edit-knockout-phase-tree.cy.ts index 3d40097..e65c520 100644 --- a/e2e/cypress/e2e/edit-knockout-phase-tree.cy.ts +++ b/e2e/cypress/e2e/edit-knockout-phase-tree.cy.ts @@ -31,34 +31,30 @@ context('edit ko-phase for tournament', () => { cy.contains('Successfully updated KO standing.'); }; - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/tournaments/4/ko-phase`); + cy.visit('/#/tournaments/4/ko-phase'); - markDrinksAsPickedUp(3); // team #00 - markDrinksAsPickedUp(4); // team #15 - selectKoMatchWinner(3); + markDrinksAsPickedUp(3); // team #00 + markDrinksAsPickedUp(4); // team #15 + selectKoMatchWinner(3); - markDrinksAsPickedUp(6); // team #01 - markDrinksAsPickedUp(7); // team #14 - selectKoMatchWinner(4); - }); + markDrinksAsPickedUp(6); // team #01 + markDrinksAsPickedUp(7); // team #14 + selectKoMatchWinner(4); }); it("shouldn't be able to set the teams for a disabled ko-phase round", () => { cy.loginTestUser(); cy.wait(4000); - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/tournaments/4/ko-phase`); + cy.visit('/#/tournaments/4/ko-phase'); - cy.get('mat-form-field.mat-form-field-disabled') - .first() - .children() - .first() - // force click, because otherwise a timeout happens as input is disabled - .click({ force: true }); + cy.get('mat-form-field.mat-form-field-disabled') + .first() + .children() + .first() + // force click, because otherwise a timeout happens as input is disabled + .click({ force: true }); - cy.get('mat-option').should('have.length', 0); - }); + cy.get('mat-option').should('have.length', 0); }); }); diff --git a/e2e/cypress/e2e/infoscreen-ko-standings.cy.ts b/e2e/cypress/e2e/infoscreen-ko-standings.cy.ts index 4e50904..34de7e3 100644 --- a/e2e/cypress/e2e/infoscreen-ko-standings.cy.ts +++ b/e2e/cypress/e2e/infoscreen-ko-standings.cy.ts @@ -8,18 +8,16 @@ context('display ko-phase infoscreen for tournament', () => { fixture: 'infoscreen-ko-standings-teams-only-at-start.json', }).as('getInfoscreenKoStandings'); - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/infoscreen/1/ko-phase`); - cy.wait('@getInfoscreenKoStandings'); + cy.visit('/#/infoscreen/1/ko-phase'); + cy.wait('@getInfoscreenKoStandings'); - cy.get('.ko-phase-tree') - .children() - .should('have.length', 2 ** 4 + 2 ** 3 + 2 ** 2 + 2 ** 1 + 2 ** 0); + cy.get('.ko-phase-tree') + .children() + .should('have.length', 2 ** 4 + 2 ** 3 + 2 ** 2 + 2 ** 1 + 2 ** 0); - for (let i = 1; i <= 16; i++) { - cy.get('.ko-phase-tree').contains(`Test Team #${i}`).should('have.length', 1); - } - }); + for (let i = 1; i <= 16; i++) { + cy.get('.ko-phase-tree').contains(`Test Team #${i}`).should('have.length', 1); + } }); it('should be able to display the finished ko-phase tree', () => { @@ -27,87 +25,85 @@ context('display ko-phase infoscreen for tournament', () => { fixture: 'infoscreen-ko-standings-finished-with-winner.json', }).as('getInfoscreenKoStandings'); - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/infoscreen/1/ko-phase`); - cy.wait('@getInfoscreenKoStandings'); + cy.visit('/#/infoscreen/1/ko-phase'); + cy.wait('@getInfoscreenKoStandings'); - cy.get('.ko-phase-tree') - .children() - .should('have.length', 2 ** 4 + 2 ** 3 + 2 ** 2 + 2 ** 1 + 2 ** 0); + cy.get('.ko-phase-tree') + .children() + .should('have.length', 2 ** 4 + 2 ** 3 + 2 ** 2 + 2 ** 1 + 2 ** 0); - const numberOfOccurencesOfTeam = { - 1: 5, - 2: 1, - 3: 2, - 4: 1, - 5: 3, - 6: 1, - 7: 2, - 8: 1, - 9: 4, - 10: 1, - 11: 2, - 12: 1, - 13: 3, - 14: 1, - 15: 2, - 16: 1, - } as Record; + const numberOfOccurrencesOfTeam = { + 1: 5, + 2: 1, + 3: 2, + 4: 1, + 5: 3, + 6: 1, + 7: 2, + 8: 1, + 9: 4, + 10: 1, + 11: 2, + 12: 1, + 13: 3, + 14: 1, + 15: 2, + 16: 1, + } as Record; - const numberOfTimesTeamIsWinner = { - 1: 4, - 2: 0, - 3: 1, - 4: 0, - 5: 2, - 6: 0, - 7: 1, - 8: 0, - 9: 3, - 10: 0, - 11: 1, - 12: 0, - 13: 2, - 14: 0, - 15: 1, - 16: 0, - } as Record; - const numberOfTimesTeamIsLoser = { - 1: 0, - 2: 1, - 3: 1, - 4: 1, - 5: 1, - 6: 1, - 7: 1, - 8: 1, - 9: 1, - 10: 1, - 11: 1, - 12: 1, - 13: 1, - 14: 1, - 15: 1, - 16: 1, - } as Record; + const numberOfTimesTeamIsWinner = { + 1: 4, + 2: 0, + 3: 1, + 4: 0, + 5: 2, + 6: 0, + 7: 1, + 8: 0, + 9: 3, + 10: 0, + 11: 1, + 12: 0, + 13: 2, + 14: 0, + 15: 1, + 16: 0, + } as Record; + const numberOfTimesTeamIsLoser = { + 1: 0, + 2: 1, + 3: 1, + 4: 1, + 5: 1, + 6: 1, + 7: 1, + 8: 1, + 9: 1, + 10: 1, + 11: 1, + 12: 1, + 13: 1, + 14: 1, + 15: 1, + 16: 1, + } as Record; - for (let i = 1; i <= 16; i++) { + for (let i = 1; i <= 16; i++) { + cy.get( + `.ko-phase-tree mat-card:contains("Test Team #${i.toString().padStart(2, '0')}")`, + ).should('have.length', numberOfOccurrencesOfTeam[i]); + if (numberOfTimesTeamIsLoser[i] !== 0) { cy.get( - `.ko-phase-tree mat-card:contains("Test Team #${i.toString().padStart(2, '0')}")`, - ).should('have.length', numberOfOccurencesOfTeam[i]); - if (numberOfTimesTeamIsLoser[i] !== 0) { - cy.get( - `.ko-phase-tree mat-card.team-loser:contains("Test Team #${i.toString().padStart(2, '0')}")`, - ).should('have.length', numberOfTimesTeamIsLoser[i]); - } - if (numberOfTimesTeamIsWinner[i] !== 0) { - cy.get( - `.ko-phase-tree mat-card.team-winner:contains("Test Team #${i.toString().padStart(2, '0')}")`, - ).should('have.length', numberOfTimesTeamIsWinner[i]); - } + `.ko-phase-tree mat-card.team-loser:contains("Test Team #${i.toString().padStart(2, '0')}")`, + ).should('have.length', numberOfTimesTeamIsLoser[i]); } + if (numberOfTimesTeamIsWinner[i] !== 0) { + cy.get( + `.ko-phase-tree mat-card.team-winner:contains("Test Team #${i.toString().padStart(2, '0')}")`, + ).should('have.length', numberOfTimesTeamIsWinner[i]); + } + } - cy.get('.ko-phase-tree mat-card.team-final-winner:contains("Test Team #01")'); - }); + cy.get('.ko-phase-tree mat-card.team-final-winner:contains("Test Team #01")'); }); }); diff --git a/e2e/cypress/e2e/qualification-matches.cy.ts b/e2e/cypress/e2e/qualification-matches.cy.ts index b05a63c..034fb75 100644 --- a/e2e/cypress/e2e/qualification-matches.cy.ts +++ b/e2e/cypress/e2e/qualification-matches.cy.ts @@ -9,67 +9,61 @@ context('update qualification match results', () => { }); it('should be able to mark teams as ready', () => { - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/tournaments/1/qualification-phase`); + cy.visit('/#/tournaments/1/qualification-phase'); - cy.get('app-header-card').contains('Qualification Round').should('exist'); - cy.get('app-tournament-score-table') - .find('tbody') - .find('button[aria-label="mark team as ready"]') - .should('have.length', 64) - .first() - .click(); + cy.get('app-header-card').contains('Qualification Round').should('exist'); + cy.get('app-tournament-score-table') + .find('tbody') + .find('button[aria-label="mark team as ready"]') + .should('have.length', 64) + .first() + .click(); - cy.get('button[data-cy="confirm-dialog-btn"]').click(); - cy.wait(4000); + cy.get('button[data-cy="confirm-dialog-btn"]').click(); + cy.wait(4000); - cy.get('app-tournament-score-table') - .find('tbody') - .find('button[aria-label="mark team as ready"]') - .should('have.length', 63); - }); + cy.get('app-tournament-score-table') + .find('tbody') + .find('button[aria-label="mark team as ready"]') + .should('have.length', 63); }); it('should be able to generate qualification matches and mark teams as ready', () => { - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/tournaments/2/qualification-phase`); + cy.visit('/#/tournaments/2/qualification-phase'); - // for tournament2, all teams should already be "ready" - cy.get('app-header-card').contains('Qualification Round').should('exist'); - cy.get('app-tournament-score-table') - .find('tbody') - .find('button[aria-label="mark team as ready"]') - .should('have.length', 0); + // for tournament2, all teams should already be "ready" + cy.get('app-header-card').contains('Qualification Round').should('exist'); + cy.get('app-tournament-score-table') + .find('tbody') + .find('button[aria-label="mark team as ready"]') + .should('have.length', 0); - cy.get('[data-cy="generate-qualification-matches-btn"]').click(); - cy.get('button[data-cy="confirm-dialog-btn"]').click(); + cy.get('[data-cy="generate-qualification-matches-btn"]').click(); + cy.get('button[data-cy="confirm-dialog-btn"]').click(); - cy.get('app-qualification-match-line') - .first() - .as('match') - .should('not.contain', 'Enter match result'); - }); + cy.get('app-qualification-match-line') + .first() + .as('match') + .should('not.contain', 'Enter match result'); }); it('should be able to mark drinks as picked up and enter match result', () => { - cy.fixture('settings').then(settings => { - cy.visit(`http://${settings.baseUrl}/#/tournaments/3/qualification-phase`); - cy.get('app-qualification-match-line') - .first() - .as('match') - .should('not.contain', 'Enter match result'); + cy.visit('/#/tournaments/3/qualification-phase'); + cy.get('app-qualification-match-line') + .first() + .as('match') + .should('not.contain', 'Enter match result'); - cy.get('@match').find('[data-cy="enter-match-results-btn"]').should('have.attr', 'disabled'); + cy.get('@match').find('[data-cy="enter-match-results-btn"]').should('have.attr', 'disabled'); - cy.get('@match').find('[data-cy="team1-action-button"]').eq(0).click(); - cy.get('button[data-cy="confirm-dialog-btn"]').click(); + cy.get('@match').find('[data-cy="team1-action-button"]').eq(0).click(); + cy.get('button[data-cy="confirm-dialog-btn"]').click(); - cy.get('@match').find('[data-cy="team2-action-button"]').eq(0).click(); - cy.get('button[data-cy="confirm-dialog-btn"]').click(); + cy.get('@match').find('[data-cy="team2-action-button"]').eq(0).click(); + cy.get('button[data-cy="confirm-dialog-btn"]').click(); - cy.get('@match') - .find('[data-cy="enter-match-results-btn"]') - .should('not.have.attr', 'disabled'); - }); + cy.get('@match') + .find('[data-cy="enter-match-results-btn"]') + .should('not.have.attr', 'disabled'); }); }); diff --git a/e2e/cypress/e2e/tournament-teams.cy.js b/e2e/cypress/e2e/tournament-teams.cy.js index 0409b0d..aba63b5 100644 --- a/e2e/cypress/e2e/tournament-teams.cy.js +++ b/e2e/cypress/e2e/tournament-teams.cy.js @@ -17,39 +17,39 @@ context('Tournament teams', () => { }); it('a team can successfully register itself', () => { - cy.fixture('settings').then(settings => { - cy.fixture('tournaments').then(tournaments => { - cy.intercept('GET', '/api/v1/tournaments', { fixture: 'tournaments.json' }).as( - 'getTournaments', - ); + cy.fixture('tournaments').then(tournaments => { + cy.intercept('GET', '/api/v1/tournaments', { fixture: 'tournaments.json' }).as( + 'getTournaments', + ); - cy.reload(); - cy.wait('@getTournaments'); + cy.reload(); + cy.wait('@getTournaments'); - cy.get('[data-cy="tournaments-list"]') - .children() - .first() - .find('[data-cy="open-copy-team-self-reg-link-dialog"]') - .click(); + cy.get('[data-cy="tournaments-list"]') + .children() + .first() + .find('[data-cy="open-copy-team-self-reg-link-dialog"]') + .click(); - const { id: tournamentId, publicAccessToken: publicAccessToken } = tournaments[0]; - const signupUrl = `http://${settings.baseUrl}/#/tournaments/${tournamentId}/signup?token=${publicAccessToken}`; + const { id: tournamentId, publicAccessToken: publicAccessToken } = tournaments[0]; + const signupUrlPath = `/#/tournaments/${tournamentId}/signup?token=${publicAccessToken}`; - cy.get('[data-cy="copy-link-dialog-input"]').should('have.value', signupUrl); + cy.get('[data-cy="copy-link-dialog-input"]') + .invoke('val') + .should(s => expect(s.startsWith('http://') && s.endsWith(signupUrlPath)).to.be.true); - cy.logoutUser(); - cy.visit(signupUrl); + cy.logoutUser(); + cy.visit(signupUrlPath); - cy.intercept('POST', `/api/v1/tournaments/${tournamentId}/teams?token=*`, req => { - expect(req.query.token).to.equal(publicAccessToken); - expect(req.body.name).to.equal('foobar'); - }).as('signupTeamForTournament'); + cy.intercept('POST', `/api/v1/tournaments/${tournamentId}/teams?token=*`, req => { + expect(req.query.token).to.equal(publicAccessToken); + expect(req.body.name).to.equal('foobar'); + }).as('signupTeamForTournament'); - cy.get('[data-cy="team-signup-name-input"]').should('exist').type('foobar'); - cy.get('button[type="submit"]').should('exist').click(); + cy.get('[data-cy="team-signup-name-input"]').should('exist').type('foobar'); + cy.get('button[type="submit"]').should('exist').click(); - cy.wait('@signupTeamForTournament'); - }); + cy.wait('@signupTeamForTournament'); }); }); }); diff --git a/e2e/cypress/e2e/tournaments.cy.js b/e2e/cypress/e2e/tournaments.cy.js index 2e9e9fa..18ea7b7 100644 --- a/e2e/cypress/e2e/tournaments.cy.js +++ b/e2e/cypress/e2e/tournaments.cy.js @@ -5,9 +5,9 @@ context('Get Tournaments', () => { cy.intercept('GET', '/api/v1/tournaments', { fixture: 'tournaments.json' }).as( 'getTournaments', ); - //login automatically lands oin /tournaments + + // login automatically lands on /tournaments cy.loginTestUser(); - // cy.visit('/#/tournaments'); cy.wait('@getTournaments'); cy.wait(3000); }); @@ -18,11 +18,11 @@ context('Get Tournaments', () => { }); it('successfully copied team self-registration link', () => { - cy.fixture('settings').then(settings => { - cy.get('[data-cy="open-copy-team-self-reg-link-dialog"]').first().click(); - cy.get('[data-cy="copy-button"]').first().click(); - cy.assertClipboardContents(`http://${settings.baseUrl}/#/tournaments/1/signup`); - }); + cy.get('[data-cy="open-copy-team-self-reg-link-dialog"]').first().click(); + cy.get('[data-cy="copy-button"]').first().click(); + cy.withClipboardContents( + s => expect(s.startsWith('http://') && s.endsWith('/#/tournaments/1/signup')).to.be.true, + ); }); }); @@ -45,7 +45,7 @@ context('Delete Tournament', () => { // Intercept the DELETE request cy.intercept('DELETE', '/api/v1/tournaments/*', { statusCode: 200 }).as('deleteTournament'); - // Login automaticlly lands on /tournaments + // Login automatically lands on /tournaments cy.loginTestUser(); cy.wait('@getTournaments'); cy.get('[data-cy="tournaments-list"]').should('exist'); diff --git a/e2e/cypress/e2e/upload-image.cy.ts b/e2e/cypress/e2e/upload-image.cy.ts index 1e8388c..7abe0d2 100644 --- a/e2e/cypress/e2e/upload-image.cy.ts +++ b/e2e/cypress/e2e/upload-image.cy.ts @@ -25,7 +25,7 @@ context('update qualification match results', () => { throw new Error('No tournament token found!'); } cy.logoutUser(); - cy.visit(`http://localhost:4200/#/tournaments/1952/upload-image?token=${token}`); + cy.visit(`/#/tournaments/1952/upload-image?token=${token}`); cy.get('[data-cy="image-upload-file-input"]').then(subject => { return cy .fixture('../fixtures/img.png', 'base64') diff --git a/e2e/cypress/fixtures/settings.json b/e2e/cypress/fixtures/settings.json index b95c889..155bd9f 100644 --- a/e2e/cypress/fixtures/settings.json +++ b/e2e/cypress/fixtures/settings.json @@ -1,7 +1,6 @@ { "username": "admin", "password": "password", - "baseUrl": "localhost:4200", "testUser": "testUser", "testUserPassword": "test_user_password" } diff --git a/e2e/cypress/support/commands.js b/e2e/cypress/support/commands.js index 7fb2dfe..beb1dfe 100644 --- a/e2e/cypress/support/commands.js +++ b/e2e/cypress/support/commands.js @@ -2,7 +2,7 @@ Cypress.Commands.add('createUser', () => { cy.fixture('settings').then(settings => { - cy.visit(settings.baseUrl); + cy.visit('/'); cy.get('[data-cy="register-button"]').click(); cy.get('[data-cy="submit-button"]').should('be.visible'); cy.get('input[name="username"]').type(settings.username); @@ -15,7 +15,7 @@ Cypress.Commands.add('createUser', () => { Cypress.Commands.add('loginUser', () => { cy.fixture('settings').then(settings => { - cy.visit(settings.baseUrl); + cy.visit('/'); cy.get('input[name="login-username"]').type(settings.username, { force: true }); cy.get('input[name="login-password"]').type(settings.password, { force: true }); cy.get('[data-cy="login-button"]').click({ force: true }); @@ -24,7 +24,7 @@ Cypress.Commands.add('loginUser', () => { Cypress.Commands.add('loginTestUser', () => { cy.fixture('settings').then(settings => { - cy.visit(settings.baseUrl); + cy.visit('/'); cy.get('input[name="login-username"]').type(settings.testUser, { force: true }); cy.get('input[name="login-password"]').type(settings.testUserPassword, { force: true }); cy.get('[data-cy="login-button"]').click({ force: true }); @@ -32,61 +32,55 @@ Cypress.Commands.add('loginTestUser', () => { }); Cypress.Commands.add('logoutUser', () => { - cy.fixture('settings').then(settings => { - cy.visit(settings.baseUrl); - cy.get('[data-cy="logout-button"]').click(); - }); + cy.visit('/'); + cy.get('[data-cy="logout-button"]').click(); }); Cypress.Commands.add('fillTournamentCreateForm', () => { - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/create`); + cy.visit('/#/tournaments/create'); - const now = new Date(); - now.setDate(now.getDate() + 7); + const now = new Date(); + now.setDate(now.getDate() + 7); - cy.get('input[name="name"]').type('TEST_TOURNAMENT'); - cy.get('input[name="registrationEndDate"]') - .should('be.visible') - .clear({ force: true }) - .type(`${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`); - cy.get('input[name="maxParticipants"]').clear({ force: true }).type(16); - cy.get('textarea[name="description"]').type('TEST_TOURNAMENT'); + cy.get('input[name="name"]').type('TEST_TOURNAMENT'); + cy.get('input[name="registrationEndDate"]') + .should('be.visible') + .clear({ force: true }) + .type(`${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`); + cy.get('input[name="maxParticipants"]').clear({ force: true }).type(16); + cy.get('textarea[name="description"]').type('TEST_TOURNAMENT'); - cy.get('button#create-tournament').click(); + cy.get('button#create-tournament').click(); - cy.wait(200); + cy.wait(200); - cy.contains('Successfully created new tournament'); - }); + cy.contains('Successfully created new tournament'); }); Cypress.Commands.add('fillTournamentCreateFormWithInvalidData', () => { - cy.fixture('settings').then(settings => { - cy.visit(`${settings.baseUrl}/#/tournaments/create`); + cy.visit('/#/tournaments/create'); - const now = new Date(); - now.setDate(now.getDate() - 1); + const now = new Date(); + now.setDate(now.getDate() - 1); - cy.get('input[name="maxParticipants"]').clear({ force: true }).type(-1); - cy.get('input[name="registrationEndDate"]') - .clear({ force: true }) - .type(`${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`); + cy.get('input[name="maxParticipants"]').clear({ force: true }).type(-1); + cy.get('input[name="registrationEndDate"]') + .clear({ force: true }) + .type(`${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`); - cy.get('button#create-tournament').click(); + cy.get('button#create-tournament').click(); - cy.wait(200); + cy.wait(200); - cy.contains('Name is required.'); - cy.contains('Registration end needs to be in the future.'); - cy.contains('At least 16 participants are required.'); - }); + cy.contains('Name is required.'); + cy.contains('Registration end needs to be in the future.'); + cy.contains('At least 16 participants are required.'); }); -Cypress.Commands.add('assertClipboardContents', value => { +Cypress.Commands.add('withClipboardContents', testFn => { cy.window().then(window => { window.navigator.clipboard.readText().then(text => { - expect(text).to.eq(value); + testFn(text); }); }); }); diff --git a/e2e/cypress/support/index.d.ts b/e2e/cypress/support/index.d.ts index d20ed29..9011da0 100644 --- a/e2e/cypress/support/index.d.ts +++ b/e2e/cypress/support/index.d.ts @@ -31,5 +31,10 @@ declare namespace Cypress { * Fill the tournament create form with invalid data */ fillTournamentCreateFormWithInvalidData(): void; + + /** + * Calls the specified `testFn` with the current clipboard contents. + */ + withClipboardContents(testFn: (content: string) => void): void; } }