Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Move Nuxt testing docs to the Docs site (#1144)

Olga Bulat10ea15a59dd8
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 5828defdc..117f3aa68 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -619,7 +619,7 @@ jobs:
It looks like some of the Playwright tests failed. You can download the trace output and image diffs for the failed tests under the "Artifacts" section in the above page.
- You can read the [docs on how to use this artifact](https://github.com/${{ github.repository }}/blob/main/frontend/test/playwright/README.md#debugging).
+ You can read the [docs on how to use this artifact](https://docs.openverse.org/guides/frontend/playwright_tests.html#debugging).
$EOF
HEREDOC
)
diff --git a/documentation/guides/frontend/index.md b/documentation/guides/frontend/index.md
index b1a7e0e10..b173993c8 100644
--- a/documentation/guides/frontend/index.md
+++ b/documentation/guides/frontend/index.md
@@ -5,5 +5,9 @@
quickstart
test
+testing_guidelines
+playwright_tests
+storybook_tests
analytics
+miscellaneous
```
diff --git a/documentation/guides/frontend/miscellaneous.md b/documentation/guides/frontend/miscellaneous.md
new file mode 100644
index 000000000..dd491c76a
--- /dev/null
+++ b/documentation/guides/frontend/miscellaneous.md
@@ -0,0 +1,110 @@
+# Miscellaneous notes on the frontend
+
+## Formatting and Linting
+
+The code in this repository is formatted using `prettier`. If you have prettier
+setup in your code editor it should work out of the box; otherwise you can use
+the `just frontend/run lint` script to format and fix lint errors in your code.
+Checks are run to lint your code and validate the formatting on git precommit.
+
+You will need to fix any linting issues before committing. We recommend
+formatting your JavaScript files on save in your text editor. You can learn how
+to do this in Visual Studio Code
+[here](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode#format-on-save).
+
+### File name conventions
+
+All files and folders should be written in `kebab-case`, with the exception of
+Vue single file components. If it ends in `.vue`, please use `PascalCase`. This
+distinction makes our component files stand out clearly and is
+[recommended by the Vue community](https://vuejs.org/v2/style-guide/#Single-file-component-filename-casing-strongly-recommended).
+
+## Redirects <a name = "redirects"></a>
+
+| From | To | Status code | Setup level |
+| ------------ | ----------- | ----------- | ---------------------- |
+| /photos/\_id | /image/\_id | 301 | Nuxt server middleware |
+
+## Frontend Components
+
+The frontend app is composed of a number of components that are documented in
+our [Storybook](https://docs.openverse.org/storybook/).
+
+### How to create a component
+
+To create a component you can run:
+
+```shell
+# Make sure you have run `pnpm install` at least once before.
+pnpm run create:component [component name in PascalCase]
+for example: pnpm run create:component VButtonGreen
+```
+
+This command will create a component file, a story file for the component, a
+unit test file, and a regression test file. It also adds the component name to
+tsconfig.ts `include` property. Each file will have a basic template to start
+working with. We use the
+[itsjonq/remake](https://www.npmjs.com/package/@itsjonq/remake?activeTab=readme)
+package to create files out of templates.
+
+You can also create all those files manually by running the following commands:
+
+<b>create a component file </b>
+
+```
+pnpm run create:component-sfc --output=[path] --name=[component name]
+```
+
+<b>create a story file </b>
+
+```
+pnpm run create:story --output=[path] --name=[component name]
+```
+
+<b>create a component unit test file</b>
+
+```
+pnpm run create:component-unit-test --output=[path] --name=[component name] --fileName=[component name in kebab-case]
+```
+
+<b>create a component regression test file</b>
+
+```
+pnpm run create:component-storybook-test --output=[path] --name=[component name kebab-case] --fileName=[component name in kebab-case]
+```
+
+### CSS Framework
+
+To design our components, we use the [TailwindCSS](https://tailwindcss.com/)
+utility-first CSS framework. We have compiled a list of TailwindCSS classes that
+are used in the frontend app. You can view the list
+[here](https://docs.openverse.org/tailwind/).
+
+### Development Tips
+
+If you use VS Code, you can install the
+[Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
+extension to get autocomplete for TailwindCSS classes.
+
+## Finding your local IP address <a name = "finding-your-local-ip-address"></a>
+
+You can find the local IP address Nuxt uses by looking at the output of
+`nuxt dev`. Look in your console for a box of configuration details that looks
+like this:
+
+```bash
+# ╭───────────────────────────────────────────╮
+# │ │
+# │ Nuxt @ v2.15.8 │
+# │ │
+# │ ▸ Environment: development │
+# │ ▸ Rendering: server-side │
+# │ ▸ Target: server │
+# │ │
+# │ Listening: http://192.168.50.119:8443/ │ # <-- Use this IP Address
+# │ │
+# ╰───────────────────────────────────────────╯
+```
+
+You will need to regenerate the certificate if this IP address changes for any
+reason, like by enabling a VPN or changing networks.
diff --git a/frontend/test/playwright/README.md b/documentation/guides/frontend/playwright_tests.md
similarity index 87%
rename from frontend/test/playwright/README.md
rename to documentation/guides/frontend/playwright_tests.md
index b84c1ea8c..409a55d21 100644
--- a/frontend/test/playwright/README.md
+++ b/documentation/guides/frontend/playwright_tests.md
@@ -14,14 +14,15 @@ There are also **visual regression** tests that make sure that the pages display
correct components, and components are rendered correctly. The components can be
tested in isolation to make sure that the states are correctly rendered. For
more on which states should be tested, see
-[`TESTING_GUIDELINES.md`](./TESTING_GUIDELINES.md). These tests should use
+[`Testing guidelines.md`](./testing_guidelines.md). These tests should use
Storybook to render the component in isolation, and be placed in
-`test/storybook/visual-regression`.
+`frontend/test/storybook/visual-regression`.
The component tests that test that the component state is correctly rendered
based on the page interaction should be placed in
-`test/visual-regression/components`. For example, the header elements are tested
-this way because their appearance depends on the page scroll position.
+`frontend/test/visual-regression/components`. For example, the header elements
+are tested this way because their appearance depends on the page scroll
+position.
## Dockerization
@@ -53,14 +54,14 @@ codebase.
To run the end-to-end tests, after having installed docker, run the following:
```bash
-pnpm test:playwright
+just frontend/run test:playwright
```
You may pass arguments to playwright directly, for example `-u` to update
snapshots or a filter.
```bash
-pnpm test:playwright visual-regression -u
+just frontend/run test:playwright visual-regression -u
```
The above will run only test files with `visual-regression` in the path and will
@@ -70,10 +71,11 @@ update any snapshot tests due to the `-u` flag.
When writing visual regression tests, it is good practice to write tests for
each relevant breakpoint. There is a series of helpers in
-[`./utils/breakpoints.ts`](./utils/breakpoints.ts) for this. The most common
-usage for this module is to run a test or set of tests for every breakpoint our
-app knows about or a subset of them. Occasionally you will need to separate
-tests by breakpoint or by range for which there are also helpers.
+[`frontend/test/utils/breakpoints.ts`](https://github.com/WordPress/openverse/blob/main/frontend/test/playwright/utils/breakpoints.ts)
+for this. The most common usage for this module is to run a test or set of tests
+for every breakpoint our app knows about or a subset of them. Occasionally you
+will need to separate tests by breakpoint or by range for which there are also
+helpers.
Each of the following methods expects a describe block callback function
accepting some useful helpers.
@@ -92,7 +94,7 @@ accepting some useful helpers.
`describeEachBreakpoint`. It is unlikely that you will need to use this helper
directly.
-Additionally there are describe blocks for individual breakpoints, each
+Additionally, there are describe blocks for individual breakpoints, each
following the pattern `` `describe${Capitalize<Breakpoint>}` ``, for example
`breakpoints.describeXs`.
@@ -118,7 +120,7 @@ The configuration object currently supports the following options:
to `false` for viewport widths above `md` (inclusive) is a no-op.
Please see the
-[`homepage.spec.ts` visual-regression tests](visual-regression/pages/homepage.spec.ts)
+[`homepage.spec.ts` visual-regression tests](https://github.com/WordPress/openverse/blob/main/frontend/test/playwright/visual-regression/pages/homepage.spec.ts)
as an example of how to use these helpers.
### What to test for visual regression
@@ -138,7 +140,8 @@ significantly speeds up the tests and makes the data being tested against
consistent across test runs and eliminates variations that the API may include
after data refreshes happen.
-The configuration for the Talkback proxy is in the [`proxy.js`](../proxy.js)
+The configuration for the Talkback proxy is in the
+[`proxy.js`](https://github.com/WordPress/openverse/blob/main/frontend/test/proxy.js)
module and is run using `pnpm talkback`. It is rare and unlikely that you will
need to run it directly as running it is handled by the Playwright `webServer`
configuration.
@@ -147,7 +150,7 @@ If you've added new tests or updated existing ones, you may get errors about API
responses not being found. To remedy this, you'll need to update the tapes:
```bash
-pnpm test:playwright:update-tapes
+just frontend/run test:playwright:update-tapes
```
If for some reason you find yourself needing to completely recreate the tapes,
@@ -186,7 +189,7 @@ renders the page compared to the docker container.
To run the debug tests:
```bash
-pnpm test:playwright:debug
+just frontend/run test:playwright:debug
```
Note that this still runs the talkback proxy and the Nuxt server for you. If
@@ -212,8 +215,8 @@ When writing end-to-end tests, it can be helpful to use Playwright
[codegen](https://playwright.dev/docs/cli#generate-code) to generate the tests
by performing actions in the browser:
-```
-pnpm run test:playwright:gen
+```bash
+just frontend/run test:playwright:gen
```
This will open the app in a new browser window, and record any actions you take
@@ -225,6 +228,6 @@ using `pnpm start` or `pnpm dev` separately before running the codegen script.
To generate tests for a non-default breakpoint, set the viewport size using the
`--viewport-size` flag. For example, to test the `xs` breakpoint, run:
-```
-pnpm run test:playwright:gen --viewport-size=340,600"
+```bash
+just frontend/run test:playwright:gen --viewport-size=340,600"
```
diff --git a/frontend/test/storybook/README.md b/documentation/guides/frontend/storybook_tests.md
similarity index 69%
rename from frontend/test/storybook/README.md
rename to documentation/guides/frontend/storybook_tests.md
index d96b63d1f..235066ceb 100644
--- a/frontend/test/storybook/README.md
+++ b/documentation/guides/frontend/storybook_tests.md
@@ -4,30 +4,30 @@ We run Playwright tests for our Nuxt application. We also run them for
Storybook, where components are tested in isolation and (ideally) in a
comprehensive way that is not always possible inside an actual application.
-Generally it is preferrable to write regular Jest tests with
+Generally it is preferable to write regular Jest tests with
`@testing-library/vue`, however, some interactions require a real web browser
context (like loading audio files, testing drag and drop interactions, etc). For
these, Playwright is the perfect tool. We can also use Playwright to write
visual regression tests for components in isolation so that we don't have to
-dupliate things like focus state testing into our application level tests.
+duplicate things like focus state testing into our application level tests.
Our Nuxt playwright tests are described by the
-[README in the `playwright` test directory](../playwright/README.md). Please see
-the section on "Dockerization" as it also applies to the Storybook tests.
+[Playwright testing guide](./playwright_tests.md). Please see the section on
+"Dockerization" as it also applies to the Storybook tests.
## Running the tests
To run the tests:
```bash
-pnpm test:storybook
+just frontend/run test:storybook
```
This will run the tests inside a docker container. Should you wish to run the
tests locally, you can use the following:
```bash
-pnpm test:storybook:local
+just frontend/run test:storybook:local
```
But please note that unless you are running the same operating system (down to
@@ -36,19 +36,20 @@ that will cause snapshot tests to fail on false-positives.
## Writing tests
-It is preferrable to write tests using the iframed version of the component to
+It is preferable to write tests using the iframed version of the component to
avoid Storybook UI updates from effective snapshots. To access this, take the
`path` query parameter for any story and apply it to the `/iframe.html` route.
See
-[`v-checkbox.spec.ts` for an example](./visual-regression/v-checkbox.spec.ts).
+[`v-checkbox.spec.ts` for an example](https://github.com/WordPress/openverse/blob/main/frontend/test/storybook/visual-regression/v-checkbox.spec.ts)
### Codegen
You can use Playwright's `codegen` tool to generate tests. For this you will
-need to run Storybook locally on your own using `pnpm storybook`. Then run:
+need to run Storybook locally on your own using `just frontend/run storybook`.
+Then run:
```bash
-pnpm test:storybook:gen
+just frontend/run test:storybook:gen
```
Please note that the codegen script automatically runs against the non-iframed
diff --git a/documentation/guides/frontend/test.md b/documentation/guides/frontend/test.md
index 282451f0c..fa54117c6 100644
--- a/documentation/guides/frontend/test.md
+++ b/documentation/guides/frontend/test.md
@@ -1,6 +1,12 @@
-# Testing guide
+# Running frontend tests
Once you've made some changes to the codebase, it is important to run tests.
+Openverse uses unit tests, Playwright tests for end-to-end, and visual
+regression testing of the app and Storybook components. This guide will help you
+run the tests. To learn more about how to test PRs, read the
+[testing guidelines](./testing_guidelines.md). To learn more about the
+Playwright tests, read [this guide](./playwright_tests.md). To learn more about
+the Storybook visual regression tests, read [this guide](./storybook_tests.md).
## Steps
@@ -21,3 +27,26 @@ Once you've made some changes to the codebase, it is important to run tests.
```
````
+
+3. Run the Playwright tests. This will run both the end-to-end tests and the app
+ visual regression tests.
+
+ ```console
+ $ just frontend/run test:playwright
+ ```
+
+4. Run the Storybook visual regression tests.
+
+ ```console
+ $ just frontend/run test:storybook
+ ```
+
+## Updating snapshots
+
+If you've made changes to the frontend that require updating snapshots, you can
+run the playwright tests with the `-u` flag. For example, this will update the
+snapshots for the app visual regression tests:
+
+```console
+$ just frontend/run test:playwright visual-regression -u
+```
diff --git a/frontend/meta_docs/TESTING_GUIDELINES.md b/documentation/guides/frontend/testing_guidelines.md
similarity index 83%
rename from frontend/meta_docs/TESTING_GUIDELINES.md
rename to documentation/guides/frontend/testing_guidelines.md
index ed068bc33..440a257d2 100644
--- a/frontend/meta_docs/TESTING_GUIDELINES.md
+++ b/documentation/guides/frontend/testing_guidelines.md
@@ -1,11 +1,11 @@
# Testing Guidelines
-This document describes general guidelines you should follow when testing pull
-requests in this repository. It is not exhaustive but should be the starting
-point that you adapt for each PR. You may also use your best judgement and skip
-things that are unrelated to a specific PR. However, please be careful when
-doing this as accessibility bugs _especially_ are easy to slip through the
-cracks when we aren't doing our due diligence and testing changes thoroughly.
+This document describes general guidelines you should follow when testing the
+/frontend pull requests. It is not exhaustive but should be the starting point
+that you adapt for each PR. You may also use your best judgement and skip things
+that are unrelated to a specific PR. However, please be careful when doing this
+as accessibility bugs _especially_ are easy to slip through the cracks when we
+aren't doing our due diligence and testing changes thoroughly.
## Running the application
@@ -25,12 +25,12 @@ http://localhost:8443.
You can also access it from other devices in your same network (like a mobile
phone) for additional testing. See the
-[finding your local IP address](README.md#finding-your-local-ip-address) section
-of the README for how to identify the local IP adress Nuxt is served on. Once
-you have identified your local IP address, you can access the website running on
-your computer by visiting `https://<local IP>:8443` replacing `<local IP>`
-(including the brackets) with the value you found using the instructions above
-in your mobile device's browser.
+[finding your local IP address](./miscellaneous.md#finding-your-local-ip-address)
+section of the README for how to identify the local IP address Nuxt is served
+on. Once you have identified your local IP address, you can access the website
+running on your computer by visiting `https://<local IP>:8443` replacing
+`<local IP>` (including the brackets) with the value you found using the
+instructions above in your mobile device's browser.
Testing from multiple different devices as often as possible is a great way to
contribute to Openverse's frontend development.
@@ -47,10 +47,9 @@ ways to solve this:
2. You can introduce the environment variables necessary for authenticating with
an API
-For the first,
-[run the Openverse API locally](https://github.com/WordPress/openverse-api).
-Then create a `.env` file by copying the `.env.template` file and update it with
-the following:
+For the first, [run the Openverse API locally](../api/quickstart.md). Then
+create a `.env` file by copying the `.env.template` file and update it with the
+following:
```shell
API_URL="http://localhost:8000/"
@@ -76,16 +75,16 @@ API_CLIENT_ID=""
API_CLIENT_SECRET=""
```
-Then run the API as usual using `pnpm dev`. Nuxt automatically loads `.env`
-files into the environment. With these variables in the environment, all
-requests made by your server will be made using an access token retrieved by the
-`~/plugins/api-token.server.ts` plugin.
+Then run the API as usual using `just api/up` & `just api/init`. Nuxt
+automatically loads `.env` files into the environment. With these variables in
+the environment, all requests made by your server will be made using an access
+token retrieved by the `~/plugins/api-token.server.ts` plugin.
Once the `.env` file is set up, you may run the development build the typical
way:
```shell
-pnpm build && pnpm start
+just frontend/run dev
```
## Browsers
@@ -110,7 +109,7 @@ websites and the accessibility properties of them. Many of them also include
examples.
Gutenberg also has an excellent
-[Accessibility Testing Guide](https://github.com/WordPress/gutenberg/blob/086b77ed409a70a6c6a6e74dee704851eff812f2/docs/contributors/accessibility-testing.md)
+[Accessibility Testing Guide](https://github.com/WordPress/gutenberg/blob/5413ddbced8cbe0f0f10eb7739dbc34a7e56adee/docs/contributors/accessibility-testing.md)
with specific instructions for setting up screen readers for testing with.
### General recommendations
@@ -209,5 +208,7 @@ re-written using testing library.
### Playwright tests
-Please see the [Playwright test README.md](./test/playwright/README.md) for
-instructions on running and maintaining the Playwright test suite.
+Please see the [Playwright test guidelines](./playwright_tests.md) for
+instructions on running and maintaining the Playwright test suite, and the
+[Storybook test guidelines](./storybook_tests.md) for instructions on the
+Storybook Playwright test suite.