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

test: add front-end tests for react code #769

Merged
merged 6 commits into from
Nov 19, 2023

Conversation

afuetterer
Copy link
Member

@afuetterer afuetterer commented Oct 3, 2023

Description

This PR proposes the following changes:

  • add pytest-playwright as test dependency
  • add a custom e2e pytest marker, disabled by default
  • add django debug mode selection per env (e2e tests are run with DEBUG=True)
  • add e2e tests for management navigation
  • remove dedicated "webpack-build" CI job and build frontend bundle in test job
  • refactor fixtures fixture to be reusable by other tests and fixtures
  • test cases for the management UI

How to run e2e tests

Run the e2e tests with the custom marker:

pytest -m e2e

Run the e2e tests with an actual visual browser:

pytest -m e2e --headed

Slow down the test execution:

# --slowmo: miliseconds between actions
pytest -m e2e --headed --slowmo 500

Tests suggested by @MyPyDavid in #715 and related tasks

  • test the "Management Interface"
  • test navigation in #sidebar
  • count number of items per element type (in #list-group), as per number of items in the db (i.e. fixtures)
  • decide if e2e tests should run once or per Python/DB combination: yes, run only once
  • decide if e2e tests should run with a single browser: chromium
  • rebase branch
  • refactor tests to minimize code duplication -> parametrize
  • test nested display for functionality (eg. /catalogs/1/nested/)
  • cache browser installation in CI
  • rebase branch
  • Python 3.12 playwright (waiting for 1.39 on PyPI, already available on GitHub)
  • run tests in parallel in CI with xdist: django.db.utils.OperationalError: database table is locked
  • test new item creation, fill data, save in db
  • test edit buttons and edit form for each element type
  • squash commits
  • add section to testing docs: docs: add section about e2e tests rdmo-docs#35
  • remove nested_elements
  • fix: update verbose_name_plural in questionset #817 is merged
  • rebase branch
  • refactor test_management_navigation() to use a for loop through model_helpers
  • remove properties from ModelHelper
  • squash commits

Related issue: #715

Types of Changes

  • Refactoring (no functional changes, no api changes)
  • Build related changes

Checklist

  • I have read the contributor guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@afuetterer afuetterer marked this pull request as draft October 3, 2023 16:11
@afuetterer afuetterer force-pushed the 715-frontend-tests branch 2 times, most recently from f0add92 to 795ee1d Compare October 3, 2023 16:34
@afuetterer afuetterer force-pushed the 715-frontend-tests branch 2 times, most recently from 8887a4b to 762afbf Compare October 4, 2023 08:02
@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@jochenklar

This comment was marked as resolved.

@MyPyDavid

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@MyPyDavid
Copy link
Member

I've tested it out with pytest -m e2e --headed, that looks pretty awesome and really fast ;)
Think that screenshots would be overkill for the moment, could use it maybe when there are multiple developers that work on features for the front-end.

@afuetterer

This comment was marked as resolved.

@afuetterer
Copy link
Member Author

Apropos fast, you can add slomo.

See: https://playwright.dev/python/docs/test-runners#cli-arguments

@afuetterer

This comment was marked as resolved.

@MyPyDavid

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@MyPyDavid
Copy link
Member

ah yes, thanks for the snippet!
sure, I can look it at, maybe I'll put a sleep in between ;)
until later then!

@afuetterer
Copy link
Member Author

Playwright usually waits, you can also increase its timeout settings. I guess no need for sleeping.

@MyPyDavid
Copy link
Member

the test can also be finished via the front-end only:

    page.get_by_title("Edit catalog").first.click()
    comment_locator = page.get_by_label("Comment")
    expect(comment_locator).to_have_text(comment)
    # Catalog
    catalog = Catalog.objects.first()
    # now it passes
    assert catalog.comment == comment

but now also the db assert works..
think that the expect executes the save to the db and before that it is lazily evualated?

@afuetterer
Copy link
Member Author

Awesome, you already found a solution? Nice.
Maybe you also know what kind of stuff people usually edit there. I just wanted to edit anything and hit save. But there is a thousand options to edit.

@afuetterer
Copy link
Member Author

afuetterer commented Oct 5, 2023

If you want to play around with test generation, please try:
python manage.py runserver in one terminal and
playwright codegen localhost:8000 in another.

@afuetterer

This comment was marked as resolved.

@afuetterer

This comment was marked as resolved.

@jochenklar

This comment was marked as resolved.

@afuetterer
Copy link
Member Author

Done with this for now. Tests are passing.

Copy link
Member

@MyPyDavid MyPyDavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is awesome! thanks so much XD

@afuetterer
Copy link
Member Author

that is awesome! thanks so much XD

You are welcome.

@afuetterer

This comment was marked as resolved.

Copy link
Member

@jochenklar jochenklar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks this looks very good!

@@ -2,7 +2,7 @@

from django.utils.translation import gettext_lazy as _

DEBUG = False
DEBUG = os.getenv("DJANGO_DEBUG", False) == "True"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind setting this always to True, I don't think this makes the tests much slower.

rdmo/questions/models/questionset.py Outdated Show resolved Hide resolved
@afuetterer afuetterer merged commit 874b917 into rdmorganiser:dev-2.1.0 Nov 19, 2023
16 checks passed
@afuetterer afuetterer deleted the 715-frontend-tests branch November 19, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add front-end tests for react code
3 participants