From c94cd426512f9ca8088498b2bf9589c7a3a6d2c0 Mon Sep 17 00:00:00 2001 From: Anssi Juvonen Date: Tue, 17 Sep 2024 11:11:31 +0300 Subject: [PATCH] Add tests for settings view --- e2e/log.spec.ts | 2 +- e2e/settings.spec.ts | 40 ++++++++++++++++++ src/components/LocaleChanger.vue | 1 + src/components/QAComponent.vue | 4 +- .../__snapshots__/QAComponent.spec.ts.snap | 42 +++++++++---------- .../__snapshots__/SettingsView.spec.ts.snap | 18 ++++---- 6 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 e2e/settings.spec.ts diff --git a/e2e/log.spec.ts b/e2e/log.spec.ts index 8766ff8..6725a60 100644 --- a/e2e/log.spec.ts +++ b/e2e/log.spec.ts @@ -41,7 +41,7 @@ test('filters veggies in Finnish', async ({page}) => { await expect(page.getByTestId('veggie-search-option-cherry tomato')).toBeVisible(); }); -test.only('weekly challenges work', async ({page}) => { +test('weekly challenges work', async ({page}) => { await page.goto('/'); await page.getByTestId('home-start-button').click(); await page.getByTestId('veggie-search-button').click(); diff --git a/e2e/settings.spec.ts b/e2e/settings.spec.ts new file mode 100644 index 0000000..b8c1a7f --- /dev/null +++ b/e2e/settings.spec.ts @@ -0,0 +1,40 @@ +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 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 expect(page.getByTestId('veggie-search-input')).toHaveAttribute( + 'placeholder', + 'Etsi kasviksia', + ); +}); + +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('locale-button-fi').click(); + await page.getByTestId('reset-button').click(); + await page.getByTestId('confirm-button').click(); + await expect(page).toHaveURL(''); + await expect(page.getByTestId('home-locale-button-fi')).toBeVisible(); +}); + +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('qa-button-appPurpose').click(); + await page.getByTestId('qa-button-contact').click(); + await expect(page.getByTestId('qa-panel-appPurpose')).toBeVisible(); + await expect(page.getByTestId('qa-panel-contact')).toBeVisible(); + await page.getByTestId('qa-button-appPurpose').click(); + await page.getByTestId('qa-button-contact').click(); + await expect(page.getByTestId('qa-panel-appPurpose')).toBeHidden(); + await expect(page.getByTestId('qa-panel-contact')).toBeHidden(); +}); diff --git a/src/components/LocaleChanger.vue b/src/components/LocaleChanger.vue index 5636f8e..f143425 100644 --- a/src/components/LocaleChanger.vue +++ b/src/components/LocaleChanger.vue @@ -13,6 +13,7 @@ const {settings} = storeToRefs(useAppStateStore()); v-for="locale in $i18n.availableLocales" :key="locale" :value="locale" + :data-test-id="`locale-button-${locale}`" v-slot="{checked}" class="locale-changer__option" > diff --git a/src/components/QAComponent.vue b/src/components/QAComponent.vue index 477e983..2460578 100644 --- a/src/components/QAComponent.vue +++ b/src/components/QAComponent.vue @@ -19,7 +19,7 @@ const keysWithLinks = ['contact', 'studyDetails'];
- + {{ $t(`qa.${key}.title`) }} @@ -31,7 +31,7 @@ const keysWithLinks = ['contact', 'studyDetails']; leave-from-class="transform h-full opacity-100" leave-to-class="transform h-0 opacity-0" > - + renders 1`] = ` "
-
- - - - - - @@ -44,53 +44,53 @@ exports[`QAComponent > renders 1`] = ` exports[`QAComponent > renders answers 1`] = ` "
-
-
+
Eat Your Veggies is a free app for tracking plant-based ingredients on weekly basis in your diet. According to a study, consuming 30 or more veggies weekly has multiple health benefits over a less versatile diet. The key, according to study, is not as much in the amounts you consume, but in variation.
- -
+ - -
+
Ultimately, how you use the app is up to your discretion. However, consider that minuscule amounts might not be of any nutritional value. Therefore I personally consider only portions of a heaping tablespoon or larger adequate. It is also worth noting that very processed foods don't count towards a portion. So ketchup should not equal a tomato.
- -
+
...false fruit, I know. Also tomato is not a vegetable in biological sense, so the app takes some liberties in its categories. Still, please report any major inaccuracies you come across! You can also request missing veggies to be added. They should be such that are commercially available globally.
- -
+
The app is free to use, and it has no advertisements. There will be a possibility to donate, but don't feel obliged.
- -
+
The data is stored in your browser's local storage and is not shared with any third parties. You can at any time you wish reset the app using the button below.
- -
+
You can find the project page in GitHub. The page has separate boards for reporting issues and engaging in other discussion. Thank you for your interest towards the project!
diff --git a/src/components/__tests__/__snapshots__/SettingsView.spec.ts.snap b/src/components/__tests__/__snapshots__/SettingsView.spec.ts.snap index 1318b19..56c5338 100644 --- a/src/components/__tests__/__snapshots__/SettingsView.spec.ts.snap +++ b/src/components/__tests__/__snapshots__/SettingsView.spec.ts.snap @@ -3,46 +3,46 @@ exports[`SettingsView > renders 1`] = ` "
-
-
- - - - - -