Skip to content

Commit

Permalink
Merge pull request #1306 from seanpdoyle/turbo-session-config-properties
Browse files Browse the repository at this point in the history
Delegate `Turbo.session` properties to `Turbo.config`
  • Loading branch information
brunoprietog authored Aug 30, 2024
2 parents 4d65288 + 391452f commit 7ae9546
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ export class Session {
return config.drive.progressBarDelay
}

set drive(value) {
config.drive.enabled = value
}

get drive() {
return config.drive.enabled
}

set formMode(value) {
config.forms.mode = value
}

get formMode() {
return config.forms.mode
}

get location() {
return this.history.location
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/drive_disabled.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
})
</script>
<script>
Turbo.config.drive = false
Turbo.config.drive.enabled = false
</script>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/functional/frame_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ test("successfully following a link to a page without a matching frame shows an

await page.click("#missing-frame-link")

assert.match(await page.innerText("#missing"), /Content missing/)
await expect(page.locator("#missing")).toHaveText("Content missing")

assert.exists(error)
assert.include(error.message, `The response (200) did not contain the expected <turbo-frame id="missing">`)
Expand Down Expand Up @@ -195,7 +195,7 @@ test("failing to follow a link to a page without a matching frame shows an error

await page.click("#missing-page-link")

assert.match(await page.innerText("#missing"), /Content missing/)
await expect(page.locator("#missing")).toHaveText("Content missing")

assert.exists(error)
assert.include(error.message, `The response (404) did not contain the expected <turbo-frame id="missing">`)
Expand Down
19 changes: 19 additions & 0 deletions src/tests/unit/export_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@ test("Turbo interface", () => {
assert.equal(typeof Turbo.cache.clear, "function")
assert.equal(typeof Turbo.navigator, "object")
assert.equal(typeof Turbo.session, "object")
assert.equal(typeof Turbo.session.drive, "boolean")
assert.equal(typeof Turbo.session.formMode, "string")
assert.equal(typeof Turbo.fetch, "function")
})

test("Session interface", () => {
const { session, config } = Turbo

assert.equal(true, session.drive)
assert.equal(true, config.drive.enabled)
assert.equal("on", session.formMode)
assert.equal("on", config.forms.mode)

session.drive = false
session.formMode = "off"

assert.equal(false, session.drive)
assert.equal(false, config.drive.enabled)
assert.equal("off", session.formMode)
assert.equal("off", config.forms.mode)
})

test("StreamActions interface", () => {
assert.equal(typeof StreamActions, "object")
})

0 comments on commit 7ae9546

Please sign in to comment.