Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add front-end tests for react code #715

Closed
MyPyDavid opened this issue Sep 21, 2023 · 9 comments · Fixed by #769
Closed

Add front-end tests for react code #715

MyPyDavid opened this issue Sep 21, 2023 · 9 comments · Fixed by #769

Comments

@MyPyDavid
Copy link
Member

MyPyDavid commented Sep 21, 2023

Rationale / Begründung

From discussion in #649:

Since we use react now, we could also think about adding tests for the front-end. I have no clue about the ecosystem there. This is something for the next year.

Originally posted by @jochenklar in #649 (comment)

I think you can test the frontend code with javascript unit tests, like jest.

And the test the bundled frontend in combination with a django-liveserver you can use selenium, playwright or cypress nowadays.

I wrote a couple of functional tests with selenium for another project. But I think playwright might be taking over.

Refs:

Originally posted by @afuetterer in #649 (comment)

Affected

Devs

Minimal functionality

  • functional tests for front-end
    • multiple browsers, test should just pass
    • Test for mobile, will depend on what is tested
  • included in ci actions

Nice-to-have functionality

  • tests of JS code with coverage
  • 100 % coverage

References / Verweise

@afuetterer
Copy link
Member

afuetterer commented Sep 27, 2023

I can offer to write a couple of playwright tests in Python, because I wanted to test this for a long time.

These tests would require a webpack bundled frontend and a running live-server pytest-fixture. That is no problem at all.

But it "only" tests the functionality of the frontend, it will not be able to measure coverage of the JS files. For that you might need to write the tests with a JS testing framework (jest, cypress or even playwright js).

What is the priority? High coverage?

Refs:

@MyPyDavid
Copy link
Member Author

thank you @afuetterer! Think it would be great if you could make the start with just the functional tests. The coverage part is then for later or nice-to-have.

@afuetterer

This comment was marked as resolved.

@MyPyDavid
Copy link
Member Author

ok, i'll suggest here a start for tests on the new "Management Interface (docs)" that uses the React frontend.

Under /management/ each content type is known as an element. In the #sidebar there is the list of links to each element. Opening each link should show the list of items of each element in the #main part. As a test, maybe you could count the number of items (in the #list-group) shown for each element based on the test fixtures.

Some of the elements also have a special "nested" display (eg. /catalogs/1/nested/). As a start, those /nested/ views could be tested just for functionality.

The edit buttons and the edit form for each element can be tested additionally.
Another typical "click-path" would be to create a new item, fill out some data and save it.

Sidebar, Navigation:

Here are the so-called "elements" fetched:

export function fetchElements(elementType) {

and the nested parts:
if (elementAction == 'nested') {

2cents

@jochenklar
Copy link
Member

Everything @MyPyDavid suggested and, maybe some check that if you click a button (or trigger a redux action) the right API call gets fired to the backend. I don't know how JS testing does that, but to me that would be the biggest benefit of testing the front-end.

@afuetterer
Copy link
Member

Thank you, I will give it a try and let you know if I need more info. I will use an admin user for this, which should definitively have the required permissions, right?

@jochenklar I think the playwright tests will test the output, not so much which API call gets fired. But I will let you know.

@afuetterer
Copy link
Member

afuetterer commented Sep 29, 2023

Interim Report: playwright is awesome.

I will submit a PR soon.

I figured out how to use pytest-playwright to request the /management section with a logged in admin user and click on all items in the navigation. Works like a charm.

We need to build the webpack frontend in CI then and install a browser to access the live_server from pytest-django.

I still struggle with using the database in multiple tests. The live_server fixture uses transactions and wipes the database after a test is run. That means the first test can access data in rhe db, the second test finds an empty db. Need to do some more research.

I will define a custom "e2e" pytest marker, that can (de)select test cases.

Should I put these tests in management/tests or in a specific e2e tests folder?

I suggest running CI like now:

  • lint etc.
  • lots of unit tests
  • a few e2e tests

Sounds like a plan?

@afuetterer
Copy link
Member

Further discussion in associated PR #769.

@afuetterer afuetterer linked a pull request Oct 13, 2023 that will close this issue
30 tasks
afuetterer added a commit to afuetterer/rdmo that referenced this issue Nov 2, 2023
afuetterer added a commit to afuetterer/rdmo that referenced this issue Nov 15, 2023
afuetterer added a commit to afuetterer/rdmo that referenced this issue Nov 19, 2023
@MyPyDavid
Copy link
Member Author

further optimization continued with #803

afuetterer added a commit to afuetterer/rdmo that referenced this issue Nov 23, 2023
* refactor: use admin.register decorator

* build: pin django-mptt dependency

* fix: update verbose_name_plural in questionset

* fix rdmorganiser#791 for openid_connect providers and refactor keycloak snippet

* Add custom {more} markdown tag (rdmorganiser#595)

* Adjust details/summary style

* Add ValueConflictValidator and check for conflicts when storing values

* Autosave after eraseValue and removeValue

* Add tests for ValueConflictValidator

* Fix human2bytes utils function

* chore: refactor human2bytes utils func

* Fix ValueQuotaValidator and add tests

* Update HUMAN2BYTES_MAPPER and add test

* Refactor progress bar and take sets and conditions into account (rdmorganiser#596)

* Check is_optional for progress bar (again)

* Add progress_count and progress_total to Project model, compute on POST
when using the API and add progress to the project overview (rdmorganiser#488)

* Add navigation action to ProjectViewSet and refactor navigation (rdmorganiser#299, rdmorganiser#424)

* Always show count in progress bar

* Fix progress bar for questionsets

* Fix progress computation

* Fix progress permissions

* Add tests for progress and navigation

* Add progress to project hierarchy (rdmorganiser#488)

* chore: refactor values query to managers

* Use "count of total" for the progress in projects table

* Add support for BASE_URL to the management react interface (rdmorganiser#815)

* Rename variable

* Refresh navigation after auto-save in interview

* chore: add pytest-playwright dependency

* chore: add custom pytest marker for e2e tests

* chore: enable debug mode per env, default false

* refactor: add "fixtures" fixture to reuse in e2e tests

* test: add frontend-tests with pytest-playwright

Co-authored-by: David Wallace

Fixes: rdmorganiser#715

* ci: run e2e tests in ci

* ci: add dependency groups to dependabot config

* chore: update ruff repo name in pre-commit config

* build: update pre-commit hooks

* chore: fix ruff errors (PGH002, UP032)

---------

Co-authored-by: David Wallace <david.wallace@tu-darmstadt.de>
Co-authored-by: Jochen Klar <mail@jochenklar.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
afuetterer added a commit to afuetterer/rdmo that referenced this issue Nov 29, 2023
* Refactor autocomplete and add free autocomplete widget for arbitrary inputs (rdmorganiser#600)

* refactor: use admin.register decorator

* build: pin django-mptt dependency

* fix: update verbose_name_plural in questionset

* fix rdmorganiser#791 for openid_connect providers and refactor keycloak snippet

* Add custom {more} markdown tag (rdmorganiser#595)

* Adjust details/summary style

* Add ValueConflictValidator and check for conflicts when storing values

* Autosave after eraseValue and removeValue

* Add tests for ValueConflictValidator

* Fix human2bytes utils function

* chore: refactor human2bytes utils func

* Fix ValueQuotaValidator and add tests

* Update HUMAN2BYTES_MAPPER and add test

* Refactor progress bar and take sets and conditions into account (rdmorganiser#596)

* Check is_optional for progress bar (again)

* Add progress_count and progress_total to Project model, compute on POST
when using the API and add progress to the project overview (rdmorganiser#488)

* Add navigation action to ProjectViewSet and refactor navigation (rdmorganiser#299, rdmorganiser#424)

* Always show count in progress bar

* Fix progress bar for questionsets

* Fix progress computation

* Fix progress permissions

* Add tests for progress and navigation

* Add progress to project hierarchy (rdmorganiser#488)

* chore: refactor values query to managers

* Use "count of total" for the progress in projects table

* Add support for BASE_URL to the management react interface (rdmorganiser#815)

* Rename variable

* Refresh navigation after auto-save in interview

* chore: add pytest-playwright dependency

* chore: add custom pytest marker for e2e tests

* chore: enable debug mode per env, default false

* refactor: add "fixtures" fixture to reuse in e2e tests

* test: add frontend-tests with pytest-playwright

Co-authored-by: David Wallace

Fixes: rdmorganiser#715

* ci: run e2e tests in ci

* ci: add build-wheel job

Fixes: rdmorganiser#802

* Fix translated strings (Projektaufgaben, Projektansichten) and some
automatic reformatting (rdmorganiser#254)

* Add accept to project import plugins to restrict upload files (to e.g. .xml)

* Add accept=".xml" to management upload form component

* chore: add email to RoleAdmin

* chore: update ruff repo name in pre-commit config

* build: update pre-commit hooks

* chore: fix ruff errors (PGH002, UP032)

* ci: add dependency groups to dependabot config

* ci: update dependabot js groups

* build(deps-dev): bump the babel group with 5 updates

Bumps the babel group with 5 updates:

| Package | From | To |
| --- | --- | --- |
| [@babel/cli](https://github.com/babel/babel/tree/HEAD/packages/babel-cli) | `7.17.10` | `7.23.4` |
| [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) | `7.17.10` | `7.23.3` |
| [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) | `7.17.10` | `7.23.3` |
| [@babel/preset-react](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-react) | `7.16.7` | `7.23.3` |
| [babel-loader](https://github.com/babel/babel-loader) | `8.2.5` | `9.1.3` |

Updates `@babel/cli` from 7.17.10 to 7.23.4
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.4/packages/babel-cli)

Updates `@babel/core` from 7.17.10 to 7.23.3
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.3/packages/babel-core)

Updates `@babel/preset-env` from 7.17.10 to 7.23.3
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.3/packages/babel-preset-env)

Updates `@babel/preset-react` from 7.16.7 to 7.23.3
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.3/packages/babel-preset-react)

Updates `babel-loader` from 8.2.5 to 9.1.3
- [Release notes](https://github.com/babel/babel-loader/releases)
- [Changelog](https://github.com/babel/babel-loader/blob/main/CHANGELOG.md)
- [Commits](babel/babel-loader@v8.2.5...v9.1.3)

---
updated-dependencies:
- dependency-name: "@babel/cli"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: babel
- dependency-name: "@babel/core"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: babel
- dependency-name: "@babel/preset-env"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: babel
- dependency-name: "@babel/preset-react"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: babel
- dependency-name: babel-loader
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: babel
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): pin react-bootstrap

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Jochen Klar <mail@jochenklar.de>
Co-authored-by: David Wallace <david.wallace@tu-darmstadt.de>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants