Skip to content

Commit

Permalink
🐛(frontend) fix flaky e2e test
Browse files Browse the repository at this point in the history
A test on e2e was flaky, this commit fixes it.
  • Loading branch information
AntoLC authored and sampaccoud committed Oct 16, 2024
1 parent d31d7c8 commit eb0fdb1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
36 changes: 22 additions & 14 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test.describe('Documents Grid', () => {
orderDefault: '',
orderDesc: '&ordering=-title',
orderAsc: '&ordering=title',
defaultColumn: false,
},
{
nameColumn: 'Created at',
Expand All @@ -60,6 +61,7 @@ test.describe('Documents Grid', () => {
orderDefault: '',
orderDesc: '&ordering=-created_at',
orderAsc: '&ordering=created_at',
defaultColumn: false,
},
{
nameColumn: 'Updated at',
Expand All @@ -68,6 +70,7 @@ test.describe('Documents Grid', () => {
orderDefault: '&ordering=-updated_at',
orderDesc: '&ordering=updated_at',
orderAsc: '',
defaultColumn: true,
},
].forEach(
({
Expand All @@ -77,6 +80,7 @@ test.describe('Documents Grid', () => {
orderDefault,
orderDesc,
orderAsc,
defaultColumn,
}) => {
test(`checks datagrid ordering ${ordering}`, async ({ page }) => {
const responsePromise = page.waitForResponse(
Expand All @@ -98,20 +102,19 @@ test.describe('Documents Grid', () => {
);

// Checks the initial state
const datagrid = page
.getByLabel('Datagrid of the documents page 1')
.getByRole('table');
const thead = datagrid.locator('thead');
const datagrid = page.getByLabel('Datagrid of the documents page 1');
const datagridTable = datagrid.getByRole('table');
const thead = datagridTable.locator('thead');

const response = await responsePromise;
expect(response.ok()).toBeTruthy();

const docNameRow1 = datagrid
const docNameRow1 = datagridTable
.getByRole('row')
.nth(1)
.getByRole('cell')
.nth(cellNumber);
const docNameRow2 = datagrid
const docNameRow2 = datagridTable
.getByRole('row')
.nth(2)
.getByRole('cell')
Expand Down Expand Up @@ -144,13 +147,21 @@ test.describe('Documents Grid', () => {
await expect(docNameRow2).toHaveText(/.*/);
const textDocNameRow1Asc = await docNameRow1.textContent();
const textDocNameRow2Asc = await docNameRow2.textContent();

const compare = (comp1: string, comp2: string) => {
const comparisonResult = comp1.localeCompare(comp2, 'en', {
caseFirst: 'false',
ignorePunctuation: true,
});

// eslint-disable-next-line playwright/no-conditional-in-test
return defaultColumn ? comparisonResult >= 0 : comparisonResult <= 0;
};

expect(
textDocNameRow1Asc &&
textDocNameRow2Asc &&
textDocNameRow1Asc.localeCompare(textDocNameRow2Asc, 'en', {
caseFirst: 'false',
ignorePunctuation: true,
}) <= 0,
compare(textDocNameRow1Asc, textDocNameRow2Asc),
).toBeTruthy();

// Ordering Desc
Expand All @@ -171,10 +182,7 @@ test.describe('Documents Grid', () => {
expect(
textDocNameRow1Desc &&
textDocNameRow2Desc &&
textDocNameRow1Desc.localeCompare(textDocNameRow2Desc, 'en', {
caseFirst: 'false',
ignorePunctuation: true,
}) >= 0,
compare(textDocNameRow2Desc, textDocNameRow1Desc),
).toBeTruthy();
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ test.describe('Doc Visibility', () => {
const header = page.locator('header').first();
await header.locator('h2').getByText('Docs').click();

const datagrid = page
.getByLabel('Datagrid of the documents page 1')
.getByRole('table');
const datagrid = page.getByLabel('Datagrid of the documents page 1');
const datagridTable = datagrid.getByRole('table');

await expect(datagrid.getByLabel('Loading data')).toBeHidden({
timeout: 10000,
});

await expect(datagrid.getByText(docTitle)).toBeVisible();
await expect(datagridTable.getByText(docTitle)).toBeVisible();

const row = datagrid.getByRole('row').filter({
const row = datagridTable.getByRole('row').filter({
hasText: docTitle,
});

Expand Down

0 comments on commit eb0fdb1

Please sign in to comment.