Skip to content

Commit

Permalink
puppeteer test
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Aug 12, 2024
1 parent e31745f commit 4520f19
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
66 changes: 63 additions & 3 deletions test/frontend/__tests__/bonds.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import puppeteer from "puppeteer"
import { saveScreenshot, createPage, paste } from "../helpers/common"
import { createNewNotebook, getPlutoUrl, runAllChanged, setupPlutoBrowser, shutdownCurrentNotebook, waitForPlutoToCalmDown } from "../helpers/pluto"
import { saveScreenshot, createPage, paste, waitForContentToBecome, waitForContent } from "../helpers/common"
import {
createNewNotebook,
getPlutoUrl,
importNotebook,
runAllChanged,
setupPlutoBrowser,
shutdownCurrentNotebook,
waitForCellOutput,
waitForPlutoToCalmDown,
} from "../helpers/pluto"

// https://github.com/fonsp/Pluto.jl/issues/928
describe("Bonds should run once when refreshing page", () => {
describe("@bind", () => {
/**
* Launch a shared browser instance for all tests.
* I don't use jest-puppeteer because it takes away a lot of control and works buggy for me,
Expand Down Expand Up @@ -78,4 +87,55 @@ numberoftimes = Ref(0)
})
expect(output_after_reload).toBe(output_after_running_bonds)
})

it("should ignore intermediate bond values while the notebook is running", async () => {
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

const chill = async () => {
await wait(300)
await waitForPlutoToCalmDown(page)
await wait(1500)
await waitForPlutoToCalmDown(page)
}

await importNotebook(page, "test_bind_dynamics.jl")
await chill()
await chill()

const id = `029e1d1c-bf42-4e2c-a141-1e2eecc0800d`
const output_selector = `pluto-cell[id="${id}"] pluto-output`

//page.click is stupid
const click = async (sel) => {
await page.waitForSelector(sel)
await page.evaluate((sel) => document.querySelector(sel).click(), sel)
}

const reset = async () => {
await click(`#reset_xs_button`)
await wait(300)
await waitForPlutoToCalmDown(page)
await waitForContentToBecome(page, output_selector, "")
await wait(300)
await waitForPlutoToCalmDown(page)
await waitForContentToBecome(page, output_selector, "")
await wait(300)
}

const start = async () => {
await click(`#add_x_button`)
await chill()

return await waitForContent(page, output_selector)
}

await reset()
await start()

await chill()

await reset()
const val = await start()
expect(val).toBe("1,done")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ macro bind(def, element)
end

# ╔═║ a0fe4e4d-eee5-4420-bd58-3f12749a9ed1
@bind reset_xs html"<input id=resetxs type=button value=reset_xs>"
@bind reset_xs html"<input id=reset_xs_button type=button value=reset_xs>"

# ╔═║ 58db6bd4-58a6-11ef-3795-fd6e57eceb68
@bind x html"""<div>
Expand Down Expand Up @@ -46,7 +46,7 @@ btn.onclick = () => {
go()
}
</script>
<button id=startx>Start</button>
<button id=add_x_button>Start</button>
</div>"""

# ╔═║ 8568c646-0233-4a95-8332-2351e9c56027
Expand Down Expand Up @@ -86,6 +86,6 @@ end
# β•Ÿβ”€58db6bd4-58a6-11ef-3795-fd6e57eceb68
# β•Ÿβ”€8568c646-0233-4a95-8332-2351e9c56027
# ╠═8a20fa4a-ac02-4a37-a54e-e4224628db66
# ╠═29f1d840-574e-463c-87d3-4b938e123493
# β•Ÿβ”€3155b6e0-8e19-4583-b2ab-4ab2db1f10b9
# ╠═029e1d1c-bf42-4e2c-a141-1e2eecc0800d
# ╠═29f1d840-574e-463c-87d3-4b938e123493

0 comments on commit 4520f19

Please sign in to comment.