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

Add tests for pausable Frame Rendering #635

Merged
merged 2 commits into from
Jul 18, 2022
Merged
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: 3 additions & 0 deletions src/observers/form_link_interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class FormLinkInterceptor implements LinkInterceptorDelegate {
const method = link.getAttribute("data-turbo-method")
if (method) form.setAttribute("method", method)

const turboFrame = link.getAttribute("data-turbo-frame")
if (turboFrame) form.setAttribute("data-turbo-frame", turboFrame)

const turboConfirm = link.getAttribute("data-turbo-confirm")
if (turboConfirm) form.setAttribute("data-turbo-confirm", turboConfirm)

Expand Down
22 changes: 14 additions & 8 deletions src/tests/fixtures/pausable_rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<script type="module">
addEventListener('turbo:before-render', function(event) {
event.preventDefault()
if (confirm('Continue rendering?')) {
event.detail.resume()
} else {
alert('Rendering aborted')
}
})
for (const event of ["turbo:before-render", "turbo:before-frame-render"]) {
addEventListener(event, function(event) {
event.preventDefault()
if (confirm("Continue rendering?")) {
event.detail.resume()
}
})
}
</script>
</head>
<body>
<section>
<h1>Pausable Rendering</h1>
<p><a id="link" href="/src/tests/fixtures/one.html">Link</a></p>

<turbo-frame id="hello">
<h2>Pausable Frame Rendering</h2>

<a id="frame-link" href="/src/tests/fixtures/frames/hello.html">#hello Frame Link</a>
</turbo-frame>
</section>
</body>
</html>
24 changes: 20 additions & 4 deletions src/tests/functional/pausable_rendering_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@ test("test aborts rendering", async ({ page }) => {

firstDialog.dismiss()

const nextDialog = await page.waitForEvent("dialog")
assert.equal(await page.textContent("h1"), "Pausable Rendering")
})

assert.strictEqual(nextDialog.message(), "Rendering aborted")
nextDialog.accept()
test("test pauses and resumes rendering a Frame", async ({ page }) => {
page.on("dialog", (dialog) => {
assert.strictEqual(dialog.message(), "Continue rendering?")
dialog.accept()
})

assert.equal(await page.textContent("h1"), "Pausable Rendering")
await page.click("#frame-link")
await nextBeat()

assert.equal(await page.textContent("#hello h2"), "Hello from a frame")
})

test("test aborts rendering a Frame", async ({ page }) => {
page.on("dialog", (dialog) => {
assert.strictEqual(dialog.message(), "Continue rendering?")
dialog.dismiss()
})

assert.equal(await page.textContent("#hello h2"), "Pausable Frame Rendering")
})