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

How to test a redirect after form submission? #19

Closed
randycoulman opened this issue Feb 10, 2024 · 4 comments · Fixed by #21
Closed

How to test a redirect after form submission? #19

randycoulman opened this issue Feb 10, 2024 · 4 comments · Fixed by #21

Comments

@randycoulman
Copy link
Contributor

I'm testing an app that renders a LiveView form and then navigates to another route after submission. How would I test this with PhoenixTest?

It seems like maybe click_button/submit_form should also follow redirects like click_link does, but I'm not sure what other implications that might have.

randycoulman added a commit to randycoulman/freedom_account that referenced this issue Feb 10, 2024
Mostly works, but I've run into a couple of issues:

- [`CaseClauseError` when multiple matches in `assert_has`](germsvel/phoenix_test#18)
- [No obvious way to follow redirects after a form submition](germsvel/phoenix_test#19)
@germsvel
Copy link
Owner

Yeah, this is a great point @randycoulman. Forms should follow redirects.

I'd like to write a test to capture this. Is this a form doing a phx-submit and then the LiveView does a push_navigate?

germsvel added a commit that referenced this issue Feb 10, 2024
Closes #19 

What changed?
============

Our `Live` implementation doesn't handle form redirects, be they to
another LiveView with `push_navigate/2` or to a static page via
`redirect/2`.

This commit updates the implementation to follow redirects the same way
we follow redirects when we click on links.

Testing note
-----------

We also create a new describe block to encapsulate all the testing for
`fill_form/3` + `click_button/2`.
@randycoulman
Copy link
Contributor Author

@germsvel You've already addressed it, but yes: phx-sumbit followed by push_navigate. I'll try out your changes today and see how they work for my app.

@randycoulman
Copy link
Contributor Author

@germsvel 👌 Your changes worked great for my use case! I was able to fully port over to using PhoenixTest for my (still very small) app.

Thanks for this library! Very nice to use!

@germsvel
Copy link
Owner

🎉 Thanks for porting your library to use PhoenixTest @randycoulman! And thanks for coming here when you find issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants