From 7f8f66dcc5b43b1a4a2bf13720e344d58e0b92d9 Mon Sep 17 00:00:00 2001 From: Anssi Juvonen Date: Tue, 17 Sep 2024 16:08:24 +0300 Subject: [PATCH] Add tests for stats view --- e2e/log.spec.ts | 4 +- e2e/settings.spec.ts | 8 +- e2e/stats.spec.ts | 73 +++++++++++++++++++ src/components/AllTimeStatus.vue | 36 +++++++-- src/components/NavBar.vue | 6 +- src/components/TagsComponent.vue | 7 +- .../__snapshots__/LogView.spec.ts.snap | 4 +- src/i18n/en.json | 2 +- src/views/StatsView.vue | 7 +- 9 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 e2e/stats.spec.ts diff --git a/e2e/log.spec.ts b/e2e/log.spec.ts index 6725a60..4370191 100644 --- a/e2e/log.spec.ts +++ b/e2e/log.spec.ts @@ -19,8 +19,8 @@ test('logs veggies', async ({page}) => { } await expect(page.getByTestId('toast-message')).toBeHidden(); - await page.getByTestId('navbar-settings-link').click(); - await page.getByTestId('navbar-log-link').click(); + await page.getByTestId('navbar-link-settings').click(); + await page.getByTestId('navbar-link-log').click(); await expect(page.getByTestId('category-status-center-label')).toHaveText('This Week 2 Veggies'); }); diff --git a/e2e/settings.spec.ts b/e2e/settings.spec.ts index b8c1a7f..b70b0a4 100644 --- a/e2e/settings.spec.ts +++ b/e2e/settings.spec.ts @@ -3,11 +3,11 @@ import {test, expect} from '@playwright/test'; test('locale settings work', async ({page}) => { await page.goto('/'); await page.getByTestId('home-start-button').click(); - await page.getByTestId('navbar-settings-link').click(); + await page.getByTestId('navbar-link-settings').click(); await expect(page).toHaveURL('settings'); await page.getByTestId('locale-button-fi').click(); await expect(page.getByText('Tyhjennä')).toBeVisible(); - await page.getByTestId('navbar-log-link').click(); + await page.getByTestId('navbar-link-log').click(); await expect(page.getByTestId('veggie-search-input')).toHaveAttribute( 'placeholder', 'Etsi kasviksia', @@ -17,7 +17,7 @@ test('locale settings work', async ({page}) => { test('reset works', async ({page}) => { await page.goto('/'); await page.getByTestId('home-start-button').click(); - await page.getByTestId('navbar-settings-link').click(); + await page.getByTestId('navbar-link-settings').click(); await page.getByTestId('locale-button-fi').click(); await page.getByTestId('reset-button').click(); await page.getByTestId('confirm-button').click(); @@ -28,7 +28,7 @@ test('reset works', async ({page}) => { test('q&a works', async ({page}) => { await page.goto('/'); await page.getByTestId('home-start-button').click(); - await page.getByTestId('navbar-settings-link').click(); + await page.getByTestId('navbar-link-settings').click(); await page.getByTestId('qa-button-appPurpose').click(); await page.getByTestId('qa-button-contact').click(); await expect(page.getByTestId('qa-panel-appPurpose')).toBeVisible(); diff --git a/e2e/stats.spec.ts b/e2e/stats.spec.ts new file mode 100644 index 0000000..299ed13 --- /dev/null +++ b/e2e/stats.spec.ts @@ -0,0 +1,73 @@ +import {test, expect} from '@playwright/test'; + +test("shows current week's veggies", async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + 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(); + } + await page.getByTestId('navbar-link-stats').click(); + await expect(page.getByTestId('tag-apple')).toBeVisible(); + await expect(page.getByTestId('tag-apricot')).toBeVisible(); + await expect(page.getByTestId('tag-avocado')).toBeVisible(); + await page.getByTestId('tag-apple').click(); + await page.getByTestId('tag-apricot').click(); + await expect(page.getByTestId('tag-apple')).toBeHidden(); + await expect(page.getByTestId('tag-apricot')).toBeHidden(); + await page.getByTestId('navbar-link-log').click(); + await expect(page.getByTestId('category-status-center-label')).toHaveText('This Week 1 Veggies'); +}); + +test('shows last five weeks', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + await page.getByText('Apricot').click(); + await page.goto('stats'); + await page.getByTestId('stats-dropdown-button').click(); + await page.getByTestId('stats-dropdown-option-1').click(); + await expect(page.getByTestId('weekly-amounts-chart')).toBeVisible(); + await expect(page.getByTestId('weekly-categories-chart')).toBeVisible(); + await expect(page.locator('#weekly-amounts-chart-table')).toBeAttached(); + await expect(page.locator('#weekly-categories-chart-table')).toBeAttached(); +}); + +test('shows all time stats', async ({page}) => { + await page.goto('/'); + await page.getByTestId('home-start-button').click(); + await page.getByTestId('veggie-search-button').click(); + await page.getByText('Apricot').click(); + await page.getByText('Avocado').click(); + await page.goto('stats'); + await page.getByTestId('stats-dropdown-button').click(); + await page.getByTestId('stats-dropdown-option-2').click(); + await expect(page.getByTestId('all-time-weeks')).toHaveText('In Total 1 Weeks'); + await expect(page.getByTestId('all-time-over-30')).toHaveText('Over 30 Veggies in 0 Weeks'); + await expect(page.getByTestId('all-time-unique')).toHaveText('In Total 2 Unique Veggies'); + await expect(page.getByTestId('all-time-at-most')).toHaveText('At Most 2 Veggies in a Week'); +}); + +test('shows achievements', 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 page.getByTestId('dialog-close-button').click(); + await page.goto('stats'); + await page.getByTestId('stats-dropdown-button').click(); + await page.getByTestId('stats-dropdown-option-3').click(); + await expect(page.getByTestId('badge-experimenterFruit-3')).toHaveAttribute( + 'aria-disabled', + 'false', + ); +}); diff --git a/src/components/AllTimeStatus.vue b/src/components/AllTimeStatus.vue index f319cb0..f530b35 100644 --- a/src/components/AllTimeStatus.vue +++ b/src/components/AllTimeStatus.vue @@ -16,26 +16,46 @@ const atMostVeggies = computed(() =>