Skip to content

Commit

Permalink
Add a "reload" method to the frame element (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse authored Jul 14, 2021
1 parent 76eb046 commit 49f8213
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/elements/frame_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class FrameElement extends HTMLElement {
this.delegate.disconnect()
}

reload() {
const { src } = this;
this.src = null;
this.src = src;
}

attributeChangedCallback(name: string) {
if (name == "loading") {
this.delegate.loadingStyleChanged()
Expand Down
13 changes: 13 additions & 0 deletions src/tests/functional/loading_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export class LoadingTests extends TurboDriveTestCase {
this.assert.equal(await contents.getVisibleText(), "Frames: #frame")
}

async "test reloading a frame reloads the content"() {
await this.nextBeat

await this.clickSelector("#loading-eager summary")
await this.nextBeat

const frameContent = "#loading-eager turbo-frame#frame h2"
this.assert.ok(await this.hasSelector(frameContent))
// @ts-ignore
await this.remote.execute(() => document.querySelector("#loading-eager turbo-frame")?.reload())
this.assert.ok(await this.hasSelector(frameContent))
}

async "test navigating away from a page does not reload its frames"() {
await this.clickSelector("#one")
await this.nextBody
Expand Down

0 comments on commit 49f8213

Please sign in to comment.