mirror of
https://codeberg.org/beerbrawl/beerbrawl.git
synced 2024-09-23 01:30:52 +02:00
parent
0819e8dcc8
commit
7b1166de9d
93
e2e/cypress/e2e/beer-pong-table-overview.cy.js
Normal file
93
e2e/cypress/e2e/beer-pong-table-overview.cy.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
context('Get Beer Pong Tables', () => {
|
||||
beforeEach(() => {
|
||||
cy.loginTestUser();
|
||||
cy.wait(2000);
|
||||
});
|
||||
|
||||
it('successfully get beer pong tables', () => {
|
||||
cy.intercept('GET', '/api/v1/beer-pong-tables/tournament/*', {
|
||||
fixture: 'beerPongTables.json',
|
||||
}).as('getBeerPongTables');
|
||||
cy.visit('/#/tournaments/1/tables');
|
||||
cy.wait('@getBeerPongTables');
|
||||
cy.get('[data-cy="beer-pong-tables-list"]').should('exist');
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').should('have.length.at.least', 1);
|
||||
cy.fixture('beerPongTables.json').then(tables => {
|
||||
tables.forEach((table, index) => {
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]')
|
||||
.eq(index)
|
||||
.should('contain.text', table.name);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('Delete Beer Pong Table', () => {
|
||||
let firstLoad = true;
|
||||
|
||||
beforeEach(() => {
|
||||
cy.loginTestUser();
|
||||
cy.wait(2000);
|
||||
});
|
||||
|
||||
it('successfully deletes a beer pong table', () => {
|
||||
// Intercept the initial GET request
|
||||
cy.intercept('GET', '/api/v1/beer-pong-tables/tournament/*', req => {
|
||||
req.reply(res => {
|
||||
if (firstLoad) {
|
||||
res.send({ fixture: 'beerPongTables.json' });
|
||||
firstLoad = false;
|
||||
} else {
|
||||
res.send({ fixture: 'beerPongTables-after-delete.json' });
|
||||
}
|
||||
});
|
||||
}).as('getBeerPongTables');
|
||||
|
||||
// Intercept the DELETE request
|
||||
cy.intercept('DELETE', '/api/v1/beer-pong-tables/*', { statusCode: 200 }).as(
|
||||
'deleteBeerPongTable',
|
||||
);
|
||||
|
||||
cy.visit('/#/tournaments/1/tables');
|
||||
cy.wait('@getBeerPongTables');
|
||||
cy.get('[data-cy="beer-pong-tables-list"]').should('exist');
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').should('have.length', 3);
|
||||
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').first().as('firstBeerPongTable');
|
||||
cy.get('@firstBeerPongTable').find('[data-cy="delete-beer-pong-table-btn"]').click();
|
||||
|
||||
cy.get('[data-cy="confirm-delete-btn"]').click();
|
||||
|
||||
cy.wait('@deleteBeerPongTable');
|
||||
cy.wait('@getBeerPongTables');
|
||||
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').should('have.length', 2);
|
||||
});
|
||||
|
||||
it('cancels beer pong table deletion', () => {
|
||||
firstLoad = true;
|
||||
|
||||
cy.intercept('GET', '/api/v1/beer-pong-tables/tournament/*', req => {
|
||||
req.reply(res => {
|
||||
if (firstLoad) {
|
||||
res.send({ fixture: 'beerPongTables.json' });
|
||||
firstLoad = false;
|
||||
} else {
|
||||
res.send({ fixture: 'beerPongTables-after-delete.json' });
|
||||
}
|
||||
});
|
||||
}).as('getBeerPongTables');
|
||||
|
||||
cy.visit('/#/tournaments/1/tables');
|
||||
cy.wait('@getBeerPongTables');
|
||||
cy.get('[data-cy="beer-pong-tables-list"]').should('exist');
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').should('have.length', 3);
|
||||
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').first().as('firstBeerPongTable');
|
||||
cy.get('@firstBeerPongTable').find('[data-cy="delete-beer-pong-table-btn"]').click();
|
||||
cy.get('[data-cy="cancel-delete-btn"]').click();
|
||||
|
||||
cy.get('@firstBeerPongTable').should('exist');
|
||||
cy.get('[data-cy="beer-pong-tables-list-item"]').should('have.length', 3);
|
||||
});
|
||||
});
|
12
e2e/cypress/fixtures/beerPongTables-after-delete.json
Normal file
12
e2e/cypress/fixtures/beerPongTables-after-delete.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Table 2",
|
||||
"tournamentId": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Table 3",
|
||||
"tournamentId": 1
|
||||
}
|
||||
]
|
17
e2e/cypress/fixtures/beerPongTables.json
Normal file
17
e2e/cypress/fixtures/beerPongTables.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Table 1",
|
||||
"tournamentId": 1
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Table 2",
|
||||
"tournamentId": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Table 3",
|
||||
"tournamentId": 1
|
||||
}
|
||||
]
|
|
@ -8,7 +8,7 @@
|
|||
</div>
|
||||
</mat-card>
|
||||
|
||||
<div class="table-container">
|
||||
<div class="table-container" data-cy="beer-pong-tables-list">
|
||||
<table mat-table [dataSource]="tables()" class="mat-elevation-z8">
|
||||
<ng-container matColumnDef="id">
|
||||
<th mat-header-cell *matHeaderCellDef>ID</th>
|
||||
|
@ -26,14 +26,22 @@
|
|||
<button mat-icon-button (click)="editBeerPongTable(element.id)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button mat-icon-button (click)="openConfirmDialog(element.id)">
|
||||
<button
|
||||
mat-icon-button
|
||||
(click)="openConfirmDialog(element.id)"
|
||||
data-cy="delete-beer-pong-table-btn"
|
||||
>
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
<tr
|
||||
mat-row
|
||||
*matRowDef="let row; columns: displayedColumns"
|
||||
data-cy="beer-pong-tables-list-item"
|
||||
></tr>
|
||||
</table>
|
||||
|
||||
<button mat-raised-button color="primary" (click)="createBeerPongTable()">
|
||||
|
|
Loading…
Reference in a new issue