Skip to content

Commit

Permalink
gh-147: Add GamePage in e2e, use title to navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhywhat committed Apr 17, 2020
1 parent 12009c2 commit f3627be
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
12 changes: 3 additions & 9 deletions cypress/integration/pages/CreatePlayerPage.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { Page } from './Page'
import { SelectGamePage } from './SelectGamePage'
import { GamePage } from './GamePage'
import { Player } from '../types/Player'

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

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

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

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

export class DashboardPage extends Page {
constructor(private gameName: string) {
super(`/${gameName}`)
export class DashboardPage extends GamePage {
constructor(gameName: string) {
super(gameName)
}

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

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

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

export class GamePage extends Page {
constructor(protected readonly gameName: string, path?: string) {
super(`/${gameName}` + path ? `/${path}` : '')
}

goToGameSelection(): SelectGamePage {
this.getHeader().get('#logo').click()
return new SelectGamePage()
}
goToDashboard(): DashboardPage {
this.getHeader().get('#title').click()
return new DashboardPage(this.gameName)
}
}
8 changes: 4 additions & 4 deletions cypress/integration/pages/LeaderboardPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Page } from './Page'
import { GamePage } from './GamePage'
import { Player } from '../types/Player'

export class LeaderboardPage extends Page {
constructor(private gameName: string) {
super(`/${gameName}/leaderboard`)
export class LeaderboardPage extends GamePage {
constructor(gameName: string) {
super(gameName, '/leaderboard')
}

locatePlayerWithScore(player: Player, score: number): void {
Expand Down
3 changes: 1 addition & 2 deletions cypress/integration/tests/create-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ describe('Create player page', () => {
})
it('is seen in the leaderboard without reload', () => {
const leaderboard = addPlayerPage
.goToSelectGamePage()
.selectGame(FOOSBALL_GAME.name)
.goToDashboard()
.goToLeaderboard()
leaderboard.locatePlayerWithScore(player, score)
})
Expand Down

0 comments on commit f3627be

Please sign in to comment.