Skip to content

Commit

Permalink
gh-157: Add more e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhywhat committed May 11, 2020
1 parent af8c5e4 commit 1bdc71c
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 17 deletions.
5 changes: 5 additions & 0 deletions backend/db_test/test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,8 @@ INSERT INTO "Matches"("Id","Team1Player1Id","Team1Player1Rating","Team1Player2Id
INSERT INTO "Matches"("Id","Team1Player1Id","Team1Player1Rating","Team1Player2Id","Team1Player2Rating","Team2Player1Id","Team2Player1Rating","Team2Player2Id","Team2Player2Rating","Date","WinningTeamRatingChange","Team1Won","LosingTeamRatingChange", "GameId") VALUES ('4510','150','823','230','1068','70','1385','210','819','2019-11-06 13:57:41.732','9','false','-9', '3');
INSERT INTO "Matches"("Id","Team1Player1Id","Team1Player1Rating","Team1Player2Id","Team1Player2Rating","Team2Player1Id","Team2Player1Rating","Team2Player2Id","Team2Player2Rating","Date","WinningTeamRatingChange","Team1Won","LosingTeamRatingChange", "GameId") VALUES ('4520','150','814','90','1063','50','950','220','906','2019-11-07 16:15:51.246','16','true','-16', '3');
INSERT INTO "Matches"("Id","Team1Player1Id","Team1Player1Rating","Team1Player2Id","Team1Player2Rating","Team2Player1Id","Team2Player1Rating","Team2Player2Id","Team2Player2Rating","Date","WinningTeamRatingChange","Team1Won","LosingTeamRatingChange", "GameId") VALUES ('4530','90','1079','150','830','240','960','220','890','2019-11-08 12:16:44.265','15','true','-15', '3');

-- Shift Ids' Serials to avoid errors when inserting new rows
ALTER SEQUENCE "Users_Id_seq1" RESTART WITH 300;
ALTER SEQUENCE "Users_Id_seq" RESTART WITH 300;
ALTER SEQUENCE "Matches_Id_seq" RESTART WITH 5000;
36 changes: 36 additions & 0 deletions cypress/integration/pages/AddMatchPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Page } from './Page'
import { Player } from '../types/Player'
import { DashboardPage } from './DashboardPage'

export class AddMatchPage extends Page {
constructor(private gameName: string) {
super(`/${gameName}/create-match`)
}

visit(): AddMatchPage {
super.visit()
return this
}

locate(): void {
super.locate()
this.getContent()
.should('contain.text', 'Team 1')
.should('contain.text', 'Team 2')
}

selectTeam1Player1(player: Player): AddMatchPage {
cy.get('#team1-player-input-0').select(player.name)
return this
}

selectTeam2Player1(player: Player): AddMatchPage {
cy.get('#team2-player-input-0').select(player.name)
return this
}

team1Wins(): DashboardPage {
cy.get('#team1-win-button').click()
return new DashboardPage(this.gameName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { SelectGamePage } from './SelectGamePage'
import { Player } from '../types/Player'
import { DashboardPage } from './DashboardPage'

export class CreatePlayerPage extends Page {
export class AddPlayerPage extends Page {
constructor(private gameName: string) {
super(`/${gameName}/add-player`)
}

visit(): CreatePlayerPage {
visit(): AddPlayerPage {
super.visit()
return this
}
Expand All @@ -23,7 +23,7 @@ export class CreatePlayerPage extends Page {
return new DashboardPage(this.gameName)
}

addPlayer(player: Player, score: number): CreatePlayerPage {
addPlayer(player: Player, score: number): AddPlayerPage {
const content = this.getContent()
content.get('#player-name-input').clear().type(player.name)
content
Expand Down
12 changes: 12 additions & 0 deletions cypress/integration/pages/DashboardPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Page } from './Page'
import { SelectGamePage } from './SelectGamePage'
import { AddMatchPage } from './AddMatchPage'
import { MatchListPage } from './MatchListPage'
import { LeaderboardPage } from './LeaderboardPage'

export class DashboardPage extends Page {
Expand All @@ -21,11 +23,21 @@ export class DashboardPage extends Page {
.should('contain.text', 'Add Match')
}

goToAddMatch(): AddMatchPage {
cy.get('#add-match-button').click()
return new AddMatchPage(this.gameName)
}

goToGameSelection(): SelectGamePage {
this.getHeader().get('#logo').click()
return new SelectGamePage()
}

goToMatchesList(): MatchListPage {
this.getContent().get('#show-all-matches').click()
return new MatchListPage(this.gameName)
}

goToLeaderboard(): LeaderboardPage {
this.getContent().get('#show-leaderboard').click()
return new LeaderboardPage(this.gameName)
Expand Down
7 changes: 7 additions & 0 deletions cypress/integration/pages/MatchListPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Page } from './Page'

export class MatchListPage extends Page {
constructor(private gameName: string) {
super(`/${gameName}/match-list`)
}
}
44 changes: 44 additions & 0 deletions cypress/integration/tests/add-match.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AddMatchPage } from '../pages/AddMatchPage'
import { FOOSBALL_GAME } from '../utils/data'
import { AddPlayerPage } from '../pages/AddPlayerPage'
import { generateRandomPlayer } from '../utils/gen'
import { LeaderboardPage } from '../pages/LeaderboardPage'

describe('Create match page', () => {
const addMatchPage = new AddMatchPage(FOOSBALL_GAME.name)
before(() => {
addMatchPage.visit()
})
it('renders', () => {
addMatchPage.locate()
})
})

describe('Leaderboard', () => {
const player1 = generateRandomPlayer()
const player1score = 1010
const player1newscore= 1026
const player2 = generateRandomPlayer()
const player2score = 1020
const player2newscore= 1004
describe('when player 1 and player 2 exist in foosball and first wins once over second', () => {
let leaderboard: LeaderboardPage
beforeEach(() => {
leaderboard = new AddPlayerPage(FOOSBALL_GAME.name)
.visit()
.addPlayer(player1, player1score)
.addPlayer(player2, player2score)
.goToSelectGamePage()
.selectGame(FOOSBALL_GAME.name)
.goToAddMatch()
.selectTeam1Player1(player1)
.selectTeam2Player1(player2)
.team1Wins()
.goToLeaderboard()
})
it('contains players with resulting scores', () => {
leaderboard.locatePlayerWithScore(player1, player1newscore)
leaderboard.locatePlayerWithScore(player2, player2newscore)
})
})
})
51 changes: 47 additions & 4 deletions cypress/integration/tests/add-player.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CreatePlayerPage } from '../pages/CreatePlayerPage'
import { FOOSBALL_GAME } from '../utils/data'
import { AddPlayerPage } from '../pages/AddPlayerPage'
import { FOOSBALL_GAME, TENNIS_GAME } from '../utils/data'
import { Player } from '../types/Player'
import { generateRandomPlayer } from '../utils/gen'

describe('Create player page', () => {
const addPlayerPage = new CreatePlayerPage(FOOSBALL_GAME.name)
describe('Add player page', () => {
const addPlayerPage = new AddPlayerPage(FOOSBALL_GAME.name)
before(() => {
addPlayerPage.visit()
})
Expand All @@ -26,3 +26,46 @@ describe('Create player page', () => {
})
})
})

describe('A player added to foosball is not added to tennis', () => {
const addPlayerPage = new AddPlayerPage(FOOSBALL_GAME.name)
describe('when a player is added to foosball', () => {
let player: Player
const score = 1001
beforeEach(() => {
player = generateRandomPlayer()
addPlayerPage
.visit()
.addPlayer(player, score)
})
it('is not added to tennis', () => {
addPlayerPage
.goToSelectGamePage()
.selectGame(TENNIS_GAME.name)
.goToLeaderboard()
.missPlayerWithScore(player, score)
})
})
})

describe('Same player can be added to foosball and to tennis', () => {
describe('when a player is added to foosball', () => {
let player: Player
const score = 1001
beforeEach(() => {
player = generateRandomPlayer()
new AddPlayerPage(FOOSBALL_GAME.name)
.visit()
.addPlayer(player, score)
})
it('can be added to tennis', () => {
new AddPlayerPage(TENNIS_GAME.name)
.visit()
.addPlayer(player, score)
.goToSelectGamePage()
.selectGame(TENNIS_GAME.name)
.goToLeaderboard()
.locatePlayerWithScore(player, score)
})
})
})
8 changes: 3 additions & 5 deletions cypress/integration/tests/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { DashboardPage } from '../pages/DashboardPage'

describe('Dashboard', () => {
const dashboardPage = new DashboardPage('foosball')
beforeEach(() => {
before(() => {
dashboardPage.visit()
})
it('contains Last Battles and Top Rating titles', () => {
dashboardPage.getContent()
.should('contain.text', 'Last Battles')
.should('contain.text', 'Top Rating')
it('renders', () => {
dashboardPage.locate()
})
})
11 changes: 11 additions & 0 deletions cypress/integration/tests/game-select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SelectGamePage } from '../pages/SelectGamePage'

describe('Select Game Page', () => {
const selectGamePage = new SelectGamePage()
before(() => {
selectGamePage.visit()
})
it('renders', () => {
selectGamePage.locate()
})
})
53 changes: 53 additions & 0 deletions cypress/integration/tests/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { SelectGamePage } from '../pages/SelectGamePage'
import { FOOSBALL_GAME, TENNIS_GAME } from '../utils/data'

describe('Navigation', () => {
describe('foosball dashboard', () => {
it('is reachable', () => {
new SelectGamePage()
.visit()
.selectGame(FOOSBALL_GAME.name)
.locate()
})
})

describe('foosball add match page', () => {
it('is reachable', () => {
new SelectGamePage()
.visit()
.selectGame(FOOSBALL_GAME.name)
.goToAddMatch()
.locate()
})
})

describe('tennis dashboard after foosball dashboard', () => {
it('is reachable', () => {
new SelectGamePage()
.visit()
.selectGame(FOOSBALL_GAME.name)
.goToGameSelection()
.selectGame(TENNIS_GAME.name)
.locate()
})
})

describe('match list page', () => {
it('is reachable', () => {
new SelectGamePage()
.visit()
.selectGame(FOOSBALL_GAME.name)
.goToMatchesList()
.locate()
})
})
describe('leaderboard page', () => {
it('is reachable', () => {
new SelectGamePage()
.visit()
.selectGame(FOOSBALL_GAME.name)
.goToLeaderboard()
.locate()
})
})
})
6 changes: 6 additions & 0 deletions cypress/integration/types/Team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Player } from './Player'

export interface Team {
player1: Player;
player2: Player;
}
20 changes: 20 additions & 0 deletions cypress/integration/utils/data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { Player } from '../types/Player'
import { Team } from '../types/Team'

export const FOOSBALL_GAME = {
name: 'foosball',
}

export const TENNIS_GAME = {
name: 'tennis',
}

export const XRadek: Player = {
name: 'XRadek',
}

export const XTonda: Player = {
name: 'XTonda',
}

export const Team1: Team = {
player1: XRadek,
player2: XTonda,
}
2 changes: 1 addition & 1 deletion frontend/src/app/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GameComponent extends Component {
<span id='title'>
<SimpleLink id='title-link' to={url}>{capitalize(selection.value.name)}</SimpleLink>
</span>
<SimpleButton onClick={createMatch}>Add Match</SimpleButton>
<SimpleButton id="add-match-button" onClick={createMatch}>Add Match</SimpleButton>
</>
: null }
</Header>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/__snapshots__/Game.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exports[`GameComponent when foosball is selected renders button "Add Match" and
</Styled(Link)>
</span>
<styled.button
id="add-match-button"
onClick={[Function]}
>
Add Match
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/components/AddPlayer/AddPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class AddPlayerComponent extends Component {
<Label>
Initial Rating:
</Label>
<Input id='player-rating-input' type='number' value={this.state.initialRating} onChange={this.initialRatingChanged} />
<Input
id='player-rating-input'
type='number'
value={this.state.initialRating}
onChange={this.initialRatingChanged} />
</GridContainer>
<Button id='add-player-button' onClick={this.submitForm} enabled={canSubmit}>Create</Button>
</Box>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/components/CreateMatch/CreateMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class CreateMatchComponent extends Component {
<GridContainer Column="1fr 1fr">
<Box Margin="0 10px 10px" Padding="10px 10px 20px">
<SelectTeamForm
id="team1"
maxPlayerNumber={this.props.maxPlayerNumber}
teamName="Team 1"
players={this.props.players}
Expand All @@ -102,6 +103,7 @@ export class CreateMatchComponent extends Component {
</Box>
<Box Margin="0 10px 10px" Padding="10px 10px 20px">
<SelectTeamForm
id="team2"
maxPlayerNumber={this.props.maxPlayerNumber}
teamName="Team 2"
players={this.props.players}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/components/CreateMatch/SelectTeamForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ export class SelectTeamForm extends Component {
render = () => {
const playerItems = this.createPlayerItemsWithNone()
const selectInputs = this.state.selectedPlayerIds.map((playerId, index) => (
<SelectInput
<SelectInput id={`${this.props.id}-player-input-${index}`}
key={index} selectedValue={playerId} items={playerItems}
onChange={event => this.playerSelected(index, Number(event.target.value))} />
))
return (
<>
<Subtitle>{this.props.teamName}</Subtitle>
{selectInputs}
<Button disabled={!this.props.canSubmit} onClick={this.props.teamSubmitted}>
<Button id={`${this.props.id}-win-button`}
disabled={!this.props.canSubmit} onClick={this.props.teamSubmitted}>
{this.props.teamName} Win
</Button>
</>
Expand Down
Loading

0 comments on commit 1bdc71c

Please sign in to comment.