-
Notifications
You must be signed in to change notification settings - Fork 195
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
isActiveAction
should take query string into account
#1725
isActiveAction
should take query string into account
#1725
Conversation
Test/ViewSupportSpec.hs
Outdated
|
||
isActivePath #{param}: #{isActivePath $ "/test/TestWithParam?param=" <> param} | ||
isActivePath bar: #{isActivePath ("/test/TestWithParam?param=bar" :: Text)} | ||
|] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpscholten added tests so we have more confidence over the change! 🍻
When I try to add
isActiveController TestController: #{isActiveController @TestController}
I get:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function can only be called from a view. To fix the test you can add a view data structure and render it to HSX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function can only be called from a view
What indicates it? Is it the use of fromFrozenContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep exactly. The renderHtml
does call Context.freeze
before rendering the html https://github.com/digitallyinduced/ihp/blob/master/IHP/Controller/Render.hs#L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some explanation behind this is here https://github.com/digitallyinduced/ihp/blob/master/IHP/Controller/Context.hs#L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, forgot to comment here, pushed a fix to https://github.com/amitaibu/ihp/pull/4/files Once merged the tests should be green 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. @mpscholten can you give a short explanation on how you knew what this fix is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dumped the response body of the the 500 Internal Server Error response. It showed that the error was happening here https://github.com/digitallyinduced/ihp/blob/master/IHP/Controller/Session.hs#L162 That error should never happen. I was first confused why the session was even used, because no code in the tests is doing anything with the session. I placed many error
calls in my local IHP codebase to trace it back. Turns out that renderHtml
calls initFlashMessages
which then accesses the session.
Then I looked thorugh the test code and checked what could be wrong with the session setup. I figured out that we never called the session middleware. After that it was an easy fix, just wiring up the middleware so that the session is available 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dumped the response body of the the 500 Internal Server Error response
How did you do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the
assertTextExists body response = do
response.simpleStatus `shouldBe` status200
function to this:
assertTextExists body response = do
error (show response)
response.simpleStatus `shouldBe` status200
@mpscholten tests are passing, but it shows the build as failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good 👍
I use this function often, and I expect We should have |
How do you use it? How would it work on |
With the example shown, the path would be |
I think for that we'd need an |
In a current project, I have a helper: -- TODO: File An Issue In IHP, The Provided Func Is Broken
isActivePathOrSub :: _ => controller -> Bool
isActivePathOrSub route =
let
currentPath = Wai.rawPathInfo theRequest
in
currentPath `ByteString.isPrefixOf` cs (pathTo route) That seems to work as well. |
No description provided.