# Testing

To install what is needed for testing run `./setup.bash --test` from the top level of
the repository. This adds the test packages and downloads the browser playwright drives,
on top of what the plain `./setup.bash` installs.

Run python tests from this directory with `pytest`, after activating the virtual
environment with `source ../venv/bin/activate`. The browser runs hidden by default; pass
`--headed` to watch it. If the browser fails to launch, its system libraries are missing
and can be installed with `sudo playwright install-deps firefox`.

These python tests will do the following: 

1. Make a copy of the ODB
2. Make a copy of the database and history
3. Clear the /Shifts directory
4. Clear the database and history
5. Re-run the initial setup for a new blank OBD and database
6. Run tests (ODB/database cleared and frontend restarted between steps)
7. Restore ODB, database, and history to former values

The frontend restart in step 6 is most of the runtime, but it cannot simply be moved to
session scope. `Scheduler` reads its state directories once in `__init__`, so a frontend
left running while step 3 clears `/Shifts` and deletes `data/` is holding paths that no
longer exist, and its next ODB call aborts the whole pytest process. That is why
`start_frontend` stops the frontend *before* clearing. Making the frontend session scoped
would need a way to tell it to rebuild its `Scheduler`, which does not exist today.

## To-do list

More tests to write

* test whole month view, check dates displayed (the 4wk view counts columns but never
  reads a displayed date, so month rollover and DST are untested)
* test min_hours_between_shifts (only 0 and 7 hours on adjacent rows are covered; not
  fractional hours, nor the boundary, nor shifts outside the displayed window)
* test changing databases (csv to parquet and back is untouched)
* start on sunday (needs the ODB set before the page loads, which no test does)
* Changing number of shifts
* Different shift ids (every test hard-codes rows 1-3 and shiftids 1, 2, 3)
* the csv download buttons (~55 lines of untested CSV building). The calendar (.ics)
  button and the shared `save_file` helper are covered by `test_calendar.py`
* `assign_only_available` persistence, and its interaction with the role filter


