Skip to content

Commit

Permalink
Add test for download
Browse files Browse the repository at this point in the history
  • Loading branch information
moekiorg committed Oct 25, 2024
1 parent bdb9e6a commit e8ef1a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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,

Check failure on line 22 in src/tests/functional/rendering_tests.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
} 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 }) => {
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")
})

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

0 comments on commit e8ef1a6

Please sign in to comment.