Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/native/browser_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export class BrowserAdapter {
case SystemStatusCode.networkFailure:
case SystemStatusCode.timeoutFailure:
case SystemStatusCode.contentTypeMismatch:
return this.reload({
this.reload({
reason: "request_failed",
context: {
statusCode
}
})
return visit.fail()
Comment on lines -46 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I execute this branch locally with the changes in this file reverted, the tests still pass.

Can you help me understand how this change is related to the test coverage you've added?

How is a call to visit.fail() related to clicking an <a> element to download a file?

default:
return visit.loadResponse()
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1>Rendering</h1>
<p><a id="delayed-link" href="/__turbo/delayed_response">Delayed link</a></p>
<p><a id="redirect-link" href="/__turbo/redirect">Redirect link</a></p>
<p><a id="es_locale_link" href="/src/tests/fixtures/es_locale.html">Change html[lang]</a></p>
<p><a id="download-link" href="/__turbo/download">Download link</a></p>
<form>
<input type="text" id="text-input">
<input type="radio" id="radio-input">
Expand Down
13 changes: 12 additions & 1 deletion src/tests/functional/rendering_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assert } from "chai"
import {
clearLocalStorage,
disposeAll,
hasSelector,
isScrolledToTop,
nextBeat,
nextBody,
Expand All @@ -17,7 +18,8 @@ import {
sleep,
strictElementEquals,
textContent,
visitAction
visitAction,
waitUntilNoSelector
} from "../helpers/page"

test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -580,6 +582,15 @@ test("rendering a redirect response replaces the body once and only once", async
assert.ok(await noNextBodyMutation(page), "replaces <body> element once")
})


test.only("hides progress bar when reloading due to request failure", async ({ page }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the .only call?

Suggested change
test.only("hides progress bar when reloading due to request failure", async ({ page }) => {
test("hides progress bar when reloading due to request failure", async ({ page }) => {

await page.click("#download-link")
await page.waitForEvent('download')

await waitUntilNoSelector(page, ".turbo-progress-bar")
assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "hides progress bar")
Comment on lines +588 to +591
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rebase this branch, you'll be able to re-write this assertion using Playwright's expect assertions:

Suggested change
await page.waitForEvent('download')
await waitUntilNoSelector(page, ".turbo-progress-bar")
assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "hides progress bar")
await page.waitForEvent("download")
await expect(page.locator(".turbo-progress-bar"), "hides progress bar").not.toBeAttached()

})

function deepElementsEqual(page, left, right) {
return page.evaluate(
([left, right]) => left.length == right.length && left.every((element) => right.includes(element)),
Expand Down
4 changes: 4 additions & 0 deletions src/tests/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ router.get("/file.unknown_html", (request, response) => {
response.sendFile(path.join(__dirname, "../../src/tests/fixtures/visit.html"))
})

router.get("/download", (request, response) => {
response.download(path.join(__dirname, "../../src/tests/fixtures/svg.svg"))
})

function receiveMessage(content, id, target) {
const data = renderSSEData(renderMessage(content, id, target))
for (const response of streamResponses) {
Expand Down