Skip to content

Commit

Permalink
Merge pull request #2 from gastongaiduk/more-cypress-tests
Browse files Browse the repository at this point in the history
Add almost full coverage tests
  • Loading branch information
gastongaiduk authored Dec 18, 2024
2 parents 8c5e9ab + ea40ef1 commit 069765c
Show file tree
Hide file tree
Showing 14 changed files with 744 additions and 69 deletions.
72 changes: 72 additions & 0 deletions cypress/e2e/game_leaderboards.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
describe('game leaderboards page', () => {
beforeEach(() => {
cy.clearAllLocalStorage()
})

it('no leaderboards', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-without-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'no-leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.wait('@getLeaderboards').its('response.body')
.should('have.property', 'Results')

cy.url().should('include', '/game/769/leaderboards')
cy.contains('Kirby & The Amazing Mirror')
cy.contains('No leaderboards found for this game.')
})

it('leaderboards list with refresh', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.wait('@getLeaderboards').its('response.body')
.should('have.property', 'Results')
.should('have.length', 10)

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.get('.leaderboard-list li').eq(1).contains('New Zealand Two')
cy.get('.leaderboard-list li').eq(1).contains('Thebpg13')
cy.get('.leaderboard-list li').eq(1).contains('2:38.36')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards-refresh.json' }).as('getLeaderboardsRefresh')

cy.get('.refresh-button').click()

cy.wait('@getLeaderboardsRefresh').its('response.body')
.should('have.property', 'Results')
.should('have.length', 10)

cy.get('.leaderboard-list li').eq(1).contains('New Zealand Two')
cy.get('.leaderboard-list li').eq(1).contains('zuliman92')
cy.get('.leaderboard-list li').eq(1).contains('2:35.23')
})

it('go back to recently played games', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.visit('#/game/16557/leaderboards')

cy.get('.back-button').click()

cy.url().should('include', '/games')
})
})
159 changes: 159 additions & 0 deletions cypress/e2e/leaderboard_entries.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
describe('leaderboard entries page', () => {
beforeEach(() => {
cy.clearAllLocalStorage()
})

it('no entries', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.interceptUsersIFollow()
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'no-leaderboard-entries.json' }).as('getLeaderboardEntries')

cy.get('.leaderboard-list li').eq(1).click()

cy.url().should('include', '/leaderboard/19063')
cy.contains('Colin McRae Rally')
cy.contains('New Zealand Two')
cy.contains('No entries found for this leaderboard.')
})

it('entries with refresh and no entry from me or my friends', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.interceptUsersIFollow()
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'leaderboard-entries.json' }).as('getLeaderboardEntries')

cy.get('.leaderboard-list li').eq(1).click()

cy.url().should('include', '/leaderboard/19063')
cy.contains('Colin McRae Rally')
cy.contains('New Zealand Two')

cy.get('.entries-list li').eq(0).contains('Thebpg13')
cy.get('.entries-list li').eq(0).contains('2:38.36')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'leaderboard-entries-refresh.json' }).as('getLeaderboardEntriesRefresh')

cy.get('.refresh-button').click()

cy.wait('@getLeaderboardEntriesRefresh').its('response.body')
.should('have.property', 'Results')
.should('have.length', 10)

cy.get('.entries-list li').eq(0).contains('josef733')
cy.get('.entries-list li').eq(0).contains('2:34.45')

cy.get('.entries-list li').eq(1).contains('Thebpg13')
cy.get('.entries-list li').eq(1).contains('2:38.36')
})

it('entries with an entry only from me', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('matias721744', 'matias721744-secret')
cy.interceptUsersIFollow()
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'leaderboard-entries.json' }).as('getLeaderboardEntries')

cy.get('.leaderboard-list li').eq(1).click()

cy.url().should('include', '/leaderboard/19063')
cy.contains('Colin McRae Rally')
cy.contains('New Zealand Two')

cy.get('.entries-list li').eq(0).contains('matias721744')
cy.get('.entries-list li').eq(0).contains('2:51.55')

cy.get('.entries-list li').eq(1).contains('Thebpg13')
cy.get('.entries-list li').eq(1).contains('2:38.36')
})

it('entries with entry only from a friend', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('player', 'player-secret')
cy.intercept('GET', '**/API/API_GetUsersIFollow.php*', { fixture: 'users-i-follow-with-matias.json' }).as('getUsersIFollow')
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'leaderboard-entries.json' }).as('getLeaderboardEntries')

cy.get('.leaderboard-list li').eq(1).click()

cy.url().should('include', '/leaderboard/19063')
cy.contains('Colin McRae Rally')
cy.contains('New Zealand Two')

cy.get('.entries-list li').eq(0).contains('matias721744')
cy.get('.entries-list li').eq(0).contains('2:51.55')

cy.get('.entries-list li').eq(1).contains('Thebpg13')
cy.get('.entries-list li').eq(1).contains('2:38.36')
})

it('entries with a entry from me and a friend', () => {
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'game-list-with-leaderboard.json' }).as('getRecentlyPlayedGames')

cy.authenticate('masakimu', 'masakimu-secret')
cy.intercept('GET', '**/API/API_GetUsersIFollow.php*', { fixture: 'users-i-follow-with-matias.json' }).as('getUsersIFollow')
cy.visit('/')

cy.intercept('GET', '**/API/API_GetGameLeaderboards.php*', { fixture: 'leaderboards.json' }).as('getLeaderboards')

cy.get('.game-button').click()

cy.url().should('include', '/game/16557/leaderboards')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetLeaderboardEntries.php*', { fixture: 'leaderboard-entries.json' }).as('getLeaderboardEntries')

cy.get('.leaderboard-list li').eq(1).click()

cy.url().should('include', '/leaderboard/19063')
cy.contains('Colin McRae Rally')
cy.contains('New Zealand Two')

cy.get('.entries-list li').eq(0).contains('masakimu')
cy.get('.entries-list li').eq(0).contains('2:46.59')

cy.get('.entries-list li').eq(1).contains('matias721744')
cy.get('.entries-list li').eq(1).contains('2:51.55')

cy.get('.entries-list li').eq(2).contains('Thebpg13')
cy.get('.entries-list li').eq(2).contains('2:38.36')
})
})
40 changes: 8 additions & 32 deletions cypress/e2e/recently_played_games_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ describe('recently played games page', () => {
})

it('no games played', () => {
cy.visit('/')

cy.url().should('include', '/login')
cy.contains('Authenticate')

cy.get('input[id="username"]').type('player')
cy.get('input[id="key"]').type('player-secret')

cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'no-played-games.json' }).as('getRecentlyPlayedGames')

cy.contains('Submit').click()
cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.wait('@getRecentlyPlayedGames').its('response.body')
.should('deep.equal', [])
Expand All @@ -24,50 +17,33 @@ describe('recently played games page', () => {
})

it('recently played games list with refresh', () => {
cy.visit('/')

cy.url().should('include', '/login')
cy.contains('Authenticate')

cy.get('input[id="username"]').type('example')
cy.get('input[id="key"]').type('example-secret')

cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'recently-played-games-1.json' }).as('getRecentlyPlayedGames')

cy.contains('Submit').click()
cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.wait('@getRecentlyPlayedGames').its('response.body')
.should('have.length', 1)

cy.url().should('include', '/games')
cy.contains('Colin McRae Rally')

cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'recently-played-games-2.json' }).as('getRecentlyPlayedGames')
cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'recently-played-games-2.json' }).as('getRecentlyPlayedGamesTwo')

cy.get('.refresh-button').click()

cy.wait('@getRecentlyPlayedGames').its('response.body')
cy.wait('@getRecentlyPlayedGamesTwo').its('response.body')
.should('have.length', 2)

cy.get('.game-list li').eq(0).contains('Colin McRae Rally')
cy.get('.game-list li').eq(1).contains('Kirby & The Amazing Mirror')
})

it('logout', () => {
cy.visit('/')

cy.url().should('include', '/login')
cy.contains('Authenticate')

cy.get('input[id="username"]').type('player')
cy.get('input[id="key"]').type('player-secret')

cy.intercept('GET', '**/API/API_GetUserRecentlyPlayedGames.php*', { fixture: 'no-played-games.json' }).as('getRecentlyPlayedGames')

cy.contains('Submit').click()

cy.wait('@getRecentlyPlayedGames').its('response.body')
.should('deep.equal', [])
cy.authenticate('player', 'player-secret')
cy.visit('/')

cy.contains('Logout').click()

Expand Down
20 changes: 20 additions & 0 deletions cypress/fixtures/game-list-with-leaderboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"GameID": 16557,
"ConsoleID": 12,
"ConsoleName": "PlayStation",
"Title": "Colin McRae Rally",
"ImageIcon": "/Images/036840.png",
"ImageTitle": "/Images/036689.png",
"ImageIngame": "/Images/036690.png",
"ImageBoxArt": "/Images/065054.png",
"LastPlayed": "2024-12-16 22:22:54",
"AchievementsTotal": 104,
"NumPossibleAchievements": 104,
"PossibleScore": 436,
"NumAchieved": 53,
"ScoreAchieved": 173,
"NumAchievedHardcore": 53,
"ScoreAchievedHardcore": 173
}
]
20 changes: 20 additions & 0 deletions cypress/fixtures/game-list-without-leaderboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"GameID": 769,
"ConsoleID": 5,
"ConsoleName": "Game Boy Advance",
"Title": "Kirby & The Amazing Mirror",
"ImageIcon": "/Images/042405.png",
"ImageTitle": "/Images/033746.png",
"ImageIngame": "/Images/002643.png",
"ImageBoxArt": "/Images/014483.png",
"LastPlayed": "2024-11-24 21:31:43",
"AchievementsTotal": 55,
"NumPossibleAchievements": 55,
"PossibleScore": 311,
"NumAchieved": 21,
"ScoreAchieved": 31,
"NumAchievedHardcore": 21,
"ScoreAchievedHardcore": 31
}
]
Loading

0 comments on commit 069765c

Please sign in to comment.