Skip to content

Commit 60ca453

Browse files
committed
feat: add test to visit go home in app menu
1 parent d498b03 commit 60ca453

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

test/goHome.test.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ describe("login", () => {
1010
let context: BrowserContext
1111

1212
beforeAll(async () => {
13-
browser = await chromium.launch({ headless: false })
13+
browser = await chromium.launch()
1414
context = await browser.newContext()
1515
})
1616

1717
afterAll(async () => {
1818
await browser.close()
19+
await context.close()
1920
})
2021

2122
beforeEach(async () => {
@@ -30,21 +31,25 @@ describe("login", () => {
3031

3132
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
3233
await page.goto("http://localhost:8080")
34+
// In case the page takes a long time to load
35+
await page.waitForTimeout(2000)
3336
// Type in password
3437
await page.fill(".password", PASSWORD)
3538
// Click the submit button and login
3639
await page.click(".submit")
3740
// Click the Applicaiton menu
3841
await page.click(".menubar-menu-button[title='Application Menu']")
3942
// See the Go Home button
40-
const goHomeButton = ".home-bar[aria-label='Home'] li"
43+
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
4144
expect(await page.isVisible(goHomeButton))
42-
// Hover over element without clicking
43-
await page.hover(goHomeButton)
44-
// Click the top left corner of the element
45+
// Click it and navigate to coder.com
4546
await page.click(goHomeButton)
46-
// Note: we have to click on <li> in the Go Home button for it to work
47-
// Land on coder.com
48-
// expect(await page.url()).toBe("https://coder.com/")
47+
48+
// If there are unsaved changes it will show a dialog
49+
// asking if you're sure you want to leave
50+
page.on("dialog", (dialog) => dialog.accept())
51+
52+
await page.waitForTimeout(5000)
53+
expect(await page.url()).toBe("https://coder.com/")
4954
})
5055
})

0 commit comments

Comments
 (0)