Skip to content

Commit

Permalink
chore: add test coverage for main features
Browse files Browse the repository at this point in the history
  • Loading branch information
astone123 committed Dec 13, 2023
1 parent cbe0936 commit dfab32d
Show file tree
Hide file tree
Showing 17 changed files with 7,304 additions and 21 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 6 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import {defineConfig} from 'cypress';

export default defineConfig({
projectId: 'n3os69',
fixturesFolder: 'e2e/fixtures',
e2e: {
baseUrl: 'http://localhost:5173/',
supportFile: false,
env: {
API_BASE_URL: 'https://api.top90.io',
},
baseUrl: 'http://localhost:5173',
supportFile: 'e2e/e2e.ts',
specPattern: 'e2e/*.cy.{ts,tsx}',
},
});
11 changes: 11 additions & 0 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
beforeEach(() => {
// stub API requests
cy.intercept('GET', `${Cypress.env('API_BASE_URL')}/teams*`, {fixture: 'teams'}).as('teams');
cy.intercept('GET', `${Cypress.env('API_BASE_URL')}/leagues*`, {fixture: 'leagues'}).as(
'leagues'
);
cy.intercept('GET', `${Cypress.env('API_BASE_URL')}/fixtures*`, {fixture: 'fixtures'}).as(
'fixtures'
);
cy.intercept('GET', `${Cypress.env('API_BASE_URL')}/goals*`, {fixture: 'goals'}).as('goals');
});
41 changes: 41 additions & 0 deletions e2e/fixtures.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
beforeEach(() => {
cy.visit('/');
cy.wait('@fixtures');
cy.get('.nav-link').contains('Fixtures').click();
});

describe('fixtures', () => {
it('displays fixtures', () => {
cy.get('[data-cy="fixture-group"]')
.should('have.length', 6)
.first()
.within(() => {
cy.contains('Bundesliga').should('be.visible');
cy.get('[alt="League Logo"]').should('be.visible');
cy.get('a')
.should('have.attr', 'href', '/fixtures/1049002')
.within(() => {
cy.get('[alt="Home team logo"]').should('be.visible');
cy.get('[alt="Away team logo"]').should('be.visible');
cy.contains('FC Koln').should('be.visible');
cy.contains('FSV Mainz 05').should('be.visible');
cy.contains('Sun Dec 10 2023').should('be.visible');
cy.contains('9:30 AM').should('be.visible');
});
});
});

it('shows goals for fixture', () => {
cy.get('[data-cy="fixture-group"]').should('have.length', 6).first().click();
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/fixtures/1049002');
});

cy.wait(['@goals', '@goals', '@goals']).then((interceptions) => {
const reqQuery = JSON.parse(interceptions[2].request.query.json as string);
cy.wrap(reqQuery).its('filter').its('fixtureId').should('equal', 1049002);
});

cy.contains('Barcelona 2 - [4] Girona - Stuani 90').should('be.visible');
});
});
268 changes: 268 additions & 0 deletions e2e/fixtures/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
{
"fixtures": [
{
"id": 1049002,
"referee": "",
"date": "2023-12-10T16:30:00Z",
"timestamp": 1702225800,
"teams": {
"home": {
"id": 192,
"name": "FC Koln",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/192.png",
"createdAt": ""
},
"away": {
"id": 164,
"name": "FSV Mainz 05",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/164.png",
"createdAt": ""
}
},
"leagueId": 78,
"season": 2023,
"createdAt": "2023-09-01T02:30:11.074033Z"
},
{
"id": 1035332,
"referee": "",
"date": "2023-12-10T16:30:00Z",
"timestamp": 1702225800,
"teams": {
"home": {
"id": 47,
"name": "Tottenham",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/47.png",
"createdAt": ""
},
"away": {
"id": 34,
"name": "Newcastle",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/34.png",
"createdAt": ""
}
},
"leagueId": 39,
"season": 2023,
"createdAt": "2023-09-01T02:34:00.542584Z"
},
{
"id": 1052402,
"referee": "",
"date": "2023-12-10T17:00:00Z",
"timestamp": 1702227600,
"teams": {
"home": {
"id": 514,
"name": "Salernitana",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/514.png",
"createdAt": ""
},
"away": {
"id": 500,
"name": "Bologna",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/500.png",
"createdAt": ""
}
},
"leagueId": 135,
"season": 2023,
"createdAt": "2023-09-01T02:35:02.615783Z"
},
{
"id": 1038104,
"referee": "",
"date": "2023-12-10T17:30:00Z",
"timestamp": 1702229400,
"teams": {
"home": {
"id": 724,
"name": "Cadiz",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/724.png",
"createdAt": ""
},
"away": {
"id": 727,
"name": "Osasuna",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/727.png",
"createdAt": ""
}
},
"leagueId": 140,
"season": 2023,
"createdAt": "2023-09-01T02:32:04.005269Z"
},
{
"id": 1052401,
"referee": "",
"date": "2023-12-10T19:45:00Z",
"timestamp": 1702237500,
"teams": {
"home": {
"id": 497,
"name": "AS Roma",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/497.png",
"createdAt": ""
},
"away": {
"id": 502,
"name": "Fiorentina",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/502.png",
"createdAt": ""
}
},
"leagueId": 135,
"season": 2023,
"createdAt": "2023-09-01T02:35:02.45986Z"
},
{
"id": 1045010,
"referee": "",
"date": "2023-12-10T19:45:00Z",
"timestamp": 1702237500,
"teams": {
"home": {
"id": 97,
"name": "Lorient",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/97.png",
"createdAt": ""
},
"away": {
"id": 81,
"name": "Marseille",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/81.png",
"createdAt": ""
}
},
"leagueId": 61,
"season": 2023,
"createdAt": "2023-09-01T02:33:03.82978Z"
},
{
"id": 1038102,
"referee": "",
"date": "2023-12-10T20:00:00Z",
"timestamp": 1702238400,
"teams": {
"home": {
"id": 529,
"name": "Barcelona",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/529.png",
"createdAt": ""
},
"away": {
"id": 547,
"name": "Girona",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/547.png",
"createdAt": ""
}
},
"leagueId": 140,
"season": 2023,
"createdAt": "2023-09-01T02:32:03.67276Z"
},
{
"id": 1143449,
"referee": "",
"date": "2023-12-10T22:00:00Z",
"timestamp": 1702245600,
"teams": {
"home": {
"id": 8,
"name": "Colombia",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/8.png",
"createdAt": ""
},
"away": {
"id": 2379,
"name": "Venezuela",
"aliases": null,
"code": "",
"country": "",
"founded": 0,
"national": false,
"logo": "https://media.api-sports.io/football/teams/2379.png",
"createdAt": ""
}
},
"leagueId": 10,
"season": 2023,
"createdAt": "2023-11-20T00:00:08.182076Z"
}
]
}
Loading

0 comments on commit dfab32d

Please sign in to comment.