Skip to content

Commit

Permalink
test: clean up e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaslhjulstad committed Oct 1, 2024
1 parent c112571 commit af81ba9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions frontend/cypress/e2e/pages/overview.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ describe('DataTable component displays data correctly', () => {
});

it('renders the correct number of rows', () => {
cy.get('table tbody tr').should('have.length', 6); // Assuming 6 items per page
cy.get('table tbody tr').should('have.length', 6);
});

it('displays data in each column correctly', () => {
// Replace with actual column headers and expected data
cy.get('table thead th').then((headers) => {
const columnCount = headers.length;
cy.get('table tbody tr:first-child td').should('have.length', columnCount);
// Add more specific checks based on your data
});
});

Expand Down Expand Up @@ -49,21 +47,19 @@ describe('DataTable component displays data correctly', () => {
});

it('paginates the table correctly using page numbers', () => {
cy.get('[data-testid="page-2"]').click();

cy.get('table tbody tr td:nth-child(1)').as('cells');

// Go to page 2
cy.get('[data-testid="page-2"]').click();

cy.get('@cells').then(($cells) => {
const secondPageContent = [...$cells].map((cell) => cell.innerText);
expect(secondPageContent).to.have.lengthOf(6);
});

// Can go back to page 1
cy.get('[data-testid="page-1"]').click();
cy.get('@cells').then(($cells) => {
const firstPageContent = [...$cells].map((cell) => cell.innerText);
expect(firstPageContent).to.have.lengthOf(6);
});

// Last page is always visible
cy.get('[data-testid="page-last"]').click();
cy.get('@cells').then(($cells) => {
const lastPageContent = [...$cells].map((cell) => cell.innerText);
Expand All @@ -72,14 +68,12 @@ describe('DataTable component displays data correctly', () => {
});

it('sorts the table by "Address" column correctly', () => {
// Ascending order when header is clicked once
let initialAddresses: string[];

cy.get('table thead th').then(($headers) => {
// Find the index of the "Address" column
const addressIndex = [...$headers].findIndex(header => header.innerText.includes('Adresse')) + 1;

// Get the initial unsorted addresses
cy.get(`table tbody tr td:nth-child(${addressIndex})`).then(($cells) => {
initialAddresses = [...$cells].map((cell) => cell.innerText);

Expand Down Expand Up @@ -138,6 +132,4 @@ describe('DataTable component displays data correctly', () => {
expect(newOrder).to.not.deep.equal(sortedAddresses);
});
});

});

Binary file not shown.

0 comments on commit af81ba9

Please sign in to comment.