From 16f025d58f19ecf71f225ac8e356f5fc10666696 Mon Sep 17 00:00:00 2001 From: Anssi Juvonen Date: Fri, 13 Dec 2024 17:26:14 +0200 Subject: [PATCH] Fix hiding toast messages in tests --- e2e/log.spec.ts | 9 ++++----- e2e/stats.spec.ts | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/log.spec.ts b/e2e/log.spec.ts index 5f2eb0d..d07783a 100644 --- a/e2e/log.spec.ts +++ b/e2e/log.spec.ts @@ -17,13 +17,12 @@ test('logs veggies', async ({page}) => { 'This Week 2 Veggies', ); - let elements = await page.getByTestId('toast-message').all(); - for (const element of elements) { - await element.click(); + const toastLocator = page.getByTestId('toast-message'); + + while ((await toastLocator.count()) > 0) { + await toastLocator.nth(0).click(); // Click the first toast message } - elements = await page.getByTestId('toast-message').all(); - expect(elements).toHaveLength(0); await page.getByTestId('navbar-link-settings').click(); await page.getByTestId('navbar-link-log').click(); await expect(page.getByTestId('category-status-chart-center-label')).toHaveText( diff --git a/e2e/stats.spec.ts b/e2e/stats.spec.ts index 02817a3..900bca7 100644 --- a/e2e/stats.spec.ts +++ b/e2e/stats.spec.ts @@ -7,9 +7,10 @@ test("shows current week's veggies", async ({page}) => { await page.getByText(/^apple$/).click(); await page.getByText('Apricot').click(); await page.getByText('Avocado').click(); - const elements = await page.getByTestId('toast-message').all(); - for (const element of elements) { - await element.click(); + const toastLocator = page.getByTestId('toast-message'); + + while ((await toastLocator.count()) > 0) { + await toastLocator.nth(0).click(); // Click the first toast message } await page.getByTestId('navbar-link-stats').click(); await expect(page.getByTestId('tag-apple')).toBeVisible();