Skip to content

Commit

Permalink
Test coverage to preserve turbo-frame attributes
Browse files Browse the repository at this point in the history
Add test coverage for preserving turbo-frame attributes during render,
making sure that any element state is preserved while the contents are
modified.
  • Loading branch information
seanpdoyle committed Feb 8, 2021
1 parent 490687d commit f2e2f32
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tests/fixtures/frames.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<h1>Frames</h1>

<turbo-frame id="frame">
<turbo-frame id="frame" data-loaded-from="/src/tests/fixtures/frames.html">
<h2>Frames: #frame</h2>
</turbo-frame>

Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/frames/frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
</head>
<body>
<turbo-frame id="frame">
<turbo-frame id="frame" data-loaded-from="/src/tests/fixtures/frames/frame.html">
<h2>Frame: Loaded</h2>
</turbo-frame>

Expand Down
10 changes: 10 additions & 0 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ export class FrameTests extends FunctionalTestCase {
await this.goToLocation("/src/tests/fixtures/frames.html")
}

async "test following a link preserves the current <turbo-frame> element's attributes"() {
const currentPath = await this.pathname

await this.clickSelector("#hello a")
await this.nextBeat

const frame = await this.querySelector("turbo-frame#frame")
this.assert.equal(await frame.getAttribute("data-loaded-from"), currentPath)
}

async "test following a link to a page without a matching frame results in an empty frame"() {
await this.clickSelector("#missing a")
await this.nextBeat
Expand Down

0 comments on commit f2e2f32

Please sign in to comment.