-
Notifications
You must be signed in to change notification settings - Fork 434
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
Communicate Visit direction with html[data-turbo-visit-direction]
#1007
Changes from 4 commits
050fe38
3111416
c39c223
badfd69
319adf2
6912e88
2bc7c13
70cda68
c6f82a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
readEventLogs, | ||
scrollToSelector, | ||
visitAction, | ||
waitUntilSelector, | ||
willChangeBody | ||
} from "../helpers/page" | ||
|
||
|
@@ -220,6 +221,55 @@ test("test Visit with network error", async ({ page }) => { | |
await nextEventNamed(page, "turbo:fetch-request-error") | ||
}) | ||
|
||
test("test Visit direction data attribute when clicking a link", async ({ page }) => { | ||
domchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await Promise.all([ | ||
waitUntilSelector(page, "[data-turbo-visit-direction='forward']") | ||
.then(() => waitUntilSelector(page, "html:not([data-turbo-visit-direction])")), | ||
page.click("#same-origin-link") | ||
]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can write these tests without relying on page.click("#same-origin-link")
await waitUntilSelector(page, "[data-turbo-visit-direction='forward']")
await waitUntilNoSelector(page, "[data-turbo-visit-direction]") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I tried this and I don't this it worked because the attribute is added and removed quicker than the assertions can track. If I recall correctly, in the time it takes for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also line 226-227 ensures the attribute is added and removed in the correct order There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @domchristie what do you think of a660c7b? The trick is that you don't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, that works locally but seems very flaky on CI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our best option is to use the mutation logs so we are not so dependent on the exact assertion timing. With the mutation log, even if the attribute is no longer present in the page, we can still assert that it was present at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, @domchristie if you can push those changes to your branch I'll merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @afcapel I will do (I’ve just moved house, and will have a reliable internet connection next week) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@afcapel Done |
||
}) | ||
|
||
test("test Visit direction detdata attribute when navigating back", async ({ page }) => { | ||
domchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await page.click("#same-origin-link") | ||
await nextEventNamed(page, "turbo:load") | ||
await Promise.all([ | ||
waitUntilSelector(page, "[data-turbo-visit-direction='back']") | ||
.then(() => waitUntilSelector(page, "html:not([data-turbo-visit-direction])")), | ||
page.goBack() | ||
]) | ||
}) | ||
|
||
test("test Visit direction attribute when navigating forward", async ({ page }) => { | ||
domchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await page.click("#same-origin-link") | ||
await nextEventNamed(page, "turbo:load") | ||
await page.goBack() | ||
await nextEventNamed(page, "turbo:load") | ||
await Promise.all([ | ||
waitUntilSelector(page, "[data-turbo-visit-direction='forward']") | ||
.then(() => waitUntilSelector(page, "html:not([data-turbo-visit-direction])")), | ||
page.goForward() | ||
]) | ||
}) | ||
|
||
test("test Visit direction attribute on a replace visit", async ({ page }) => { | ||
domchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await Promise.all([ | ||
waitUntilSelector(page, "[data-turbo-visit-direction='none']") | ||
.then(() => waitUntilSelector(page, "html:not([data-turbo-visit-direction])")), | ||
page.click("#same-origin-replace-link") | ||
]) | ||
}) | ||
|
||
test("test Turbo history state after a reload", async ({ page }) => { | ||
domchristie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await page.click("#same-origin-link") | ||
await nextEventNamed(page, "turbo:load") | ||
await page.reload() | ||
assert.equal( | ||
await page.evaluate(() => window.history.state.turbo.restorationIndex), | ||
1, | ||
"restorationIndex is persisted between reloads" | ||
) | ||
}) | ||
|
||
async function visitLocation(page, location) { | ||
return page.evaluate((location) => window.Turbo.visit(location), location) | ||
} |
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 wasn't aware of this until today, but browsers persist the state between refreshes (🤯). This means this feature should still work after a reload (e.g. after assets are invalidated and a user taps Back)
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.
TIL, fascinating.