Skip to content

Commit

Permalink
Add a test that stream actions rendered into the HTML are executed
Browse files Browse the repository at this point in the history
As a consequence of the fundamental way in which Stream actions are implemented,
they can also be executed by rendering them within any HTML that's included on
the dom.

Since this is already being used as the feature in the community, adding this
test will ensure this keeps working.
  • Loading branch information
radanskoric committed May 24, 2024
1 parent 9fb05e3 commit f25d5cd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/tests/functional/stream_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ test("receiving a remove stream message preserves focus blurs the activeElement"
assert.notOk(await hasSelector(page, ":focus"))
})

test("rendering a stream message into the HTML executes it", async ({ page }) => {
await page.evaluate(() => {
document.body.insertAdjacentHTML(
"afterbegin",
`
<turbo-stream action="append" target="messages">
<template>
<div class="message">Hello world!</div>
</template>
</turbo-stream>
`
)
})
await nextBeat()

const messages = await page.locator("#messages .message")
assert.deepEqual(await messages.allTextContents(), ["First", "Hello world!"])
})

async function getReadyState(page, id) {
return page.evaluate((id) => {
const element = document.getElementById(id)
Expand Down

0 comments on commit f25d5cd

Please sign in to comment.