From 99a0f239cc730452f974590ddb404b2a3ae21010 Mon Sep 17 00:00:00 2001 From: Anssi Juvonen Date: Mon, 16 Sep 2024 16:08:45 +0300 Subject: [PATCH] Add tests for log view --- e2e/log.spec.ts | 69 ++++++++++++++++++ src/components/AchievementBadge.vue | 1 + src/components/CategoryStatus.vue | 1 + src/components/NavBar.vue | 20 ++++-- src/components/ToastMessage.vue | 7 +- src/components/VeggieSearch.vue | 7 +- src/components/VeggieSearchChallenge.vue | 4 +- src/components/VeggieSearchGroup.vue | 4 +- src/components/VeggieSearchOption.vue | 6 +- src/components/__tests__/VeggieSearch.spec.ts | 16 ++--- .../AchievementBadge.spec.ts.snap | 4 +- .../AchievementList.spec.ts.snap | 72 +++++++++---------- .../__snapshots__/LogView.spec.ts.snap | 6 +- 13 files changed, 153 insertions(+), 64 deletions(-) create mode 100644 e2e/log.spec.ts diff --git a/e2e/log.spec.ts b/e2e/log.spec.ts new file mode 100644 index 0000000..8710a48 --- /dev/null +++ b/e2e/log.spec.ts @@ -0,0 +1,69 @@ +import {test, expect} from '@playwright/test'; + +// See here how to get started: +// https://playwright.dev/docs/intro +test('logs veggies', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + await expect(page.getByTestId('veggie-search-options')).toBeVisible(); + await page.getByTestId('veggie-search-option-apple').click(); + await expect(page.getByText(/^First veggie added!/)).toBeVisible(); + await expect(page.getByTestId('category-status-center-label')).toHaveText('This Week 1 Veggies'); + await page.getByTestId('veggie-search-option-apricot').click(); + await expect(page.getByTestId('category-status-center-label')).toHaveText('This Week 2 Veggies'); + + const elements = await page.getByTestId('toast-message').all(); + for (const element of elements) { + await element.click(); + } + + await expect(page.getByTestId('toast-message')).toBeHidden(); + await page.getByTestId('navbar-settings-link').click(); + await page.getByTestId('navbar-log-link').click(); + await expect(page.getByTestId('category-status-center-label')).toHaveText('This Week 2 Veggies'); +}); + +test('filters veggies', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-input').fill('cher'); + await expect(page.getByTestId('veggie-search-option-cherry')).toBeVisible(); + await expect(page.getByTestId('veggie-search-option-cherry tomato')).toBeVisible(); +}); + +test('filters veggies in Finnish', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-locale-button-fi').click(); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-input').fill('kirsi'); + await expect(page.getByTestId('veggie-search-option-cherry')).toBeVisible(); + await expect(page.getByTestId('veggie-search-option-cherry tomato')).toBeVisible(); +}); + +test('weekly challenges work', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + await expect(page.getByTestId('veggie-search-challenges')).toBeHidden(); + await page.getByTestId('veggie-search-option-apple').click(); + await expect(page.getByTestId('veggie-search-challenge')).toBeVisible(); + await page.getByTestId('veggie-search-challenge').click(); + await expect(page.getByText(/^You have completed your weekly challenge!/)).toBeVisible(); +}); + +test('achievement notifications work', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + const elements = ( + await page.getByTestId('veggie-search-group-Fruit').locator('.veggie-search__option').all() + ).slice(0, 15); + for (const element of elements) { + await element.click(); + } + await expect(page.getByTestId('dialog')).toBeVisible(); + await expect(page.getByTestId('badge-experimenterFruit-3')).toBeVisible(); + await page.getByTestId('dialog-close-button').click(); + await expect(page.getByTestId('dialog')).toBeHidden(); +}); diff --git a/src/components/AchievementBadge.vue b/src/components/AchievementBadge.vue index 0d81284..bd505b8 100644 --- a/src/components/AchievementBadge.vue +++ b/src/components/AchievementBadge.vue @@ -125,6 +125,7 @@ const achievementProps: AchievementProps = { :aria-label=" $t(`achievements.${achievement}.ariaLabel`, achievementProps[achievement][level]!.textProps) " + :data-test-id="`badge-${achievement}-${level}`" class="badge" role="img" > diff --git a/src/components/CategoryStatus.vue b/src/components/CategoryStatus.vue index 0c7571e..9f27f9c 100644 --- a/src/components/CategoryStatus.vue +++ b/src/components/CategoryStatus.vue @@ -19,6 +19,7 @@ withDefaults( keypath="categoryStatus.centerLabel" tag="h1" class="category-status__center-label" + data-test-id="category-status-center-label" > {{ $t(totals ? 'categoryStatus.topLabelTotal' : 'categoryStatus.topLabel') }} {{ veggies.length }} diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 8c5da86..3ff67ef 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -6,24 +6,30 @@ defineProps<{