openproject
openproject copied to clipboard
Relax expectations for flash messages in tests
Ticket
None
Follow up to #16789 (this comment) and #16863.
What are you trying to accomplish?
Make the test code more intentional when we want to be precise with flash messages, and less verbose when we just want to dismiss them, the flash helpers do not have implicit values for :type
and :message
anymore, and do not require them to be present either.
What approach did you choose and why?
Previously expect_flash
default value for type
was :success
, meaning that code like expect_flash(message: "An error occurred")
implicitly expected a :success
flash, which is not obvious by reading the code.
This commit changes the default value for type
to :any
for all flash helpers, so that there is no implicit expectations on the flash type anymore. expect_flash(message: "An error occurred")
would then check the flash message text and only the flash message text, which is a fair expectation.
Additionally, it also relaxes the expectation on the message text so that expect_and_dismiss_flash
and other helpers can be called without :type
or :message
parameters, and it will be done regardless of the flash type and message text.
Finally it also adds documentation to all flash helpers.
Merge checklist
- [ ] Added/updated tests
- [ ] Added/updated documentation in Lookbook (patterns, previews, etc)
- [ ] Tested major browsers (Chrome, Firefox, Edge, ...)