2021-01-28 19:48:57 +01:00
|
|
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
|
|
|
|
|
|
|
describe("login", () => {
|
|
|
|
let browser: Browser
|
|
|
|
let page: Page
|
|
|
|
let context: BrowserContext
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2021-01-29 00:23:55 +01:00
|
|
|
browser = await chromium.launch()
|
2021-01-28 19:48:57 +01:00
|
|
|
context = await browser.newContext()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await browser.close()
|
2021-01-29 00:23:55 +01:00
|
|
|
await context.close()
|
2021-01-28 19:48:57 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
page = await context.newPage()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await page.close()
|
|
|
|
// Remove password from local storage
|
|
|
|
await context.clearCookies()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
|
2021-01-29 00:23:55 +01:00
|
|
|
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
|
|
|
|
let requestedGoHomeUrl = false
|
|
|
|
page.on("request", (request) => {
|
|
|
|
// This ensures that we did make a request to the GO_HOME_URL
|
|
|
|
// Most reliable way to test button
|
|
|
|
// because we don't care if the request has a response
|
|
|
|
// only that it was made
|
|
|
|
if (request.url() === GO_HOME_URL) {
|
|
|
|
requestedGoHomeUrl = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// waitUntil: "networkidle"
|
|
|
|
// In case the page takes a long time to load
|
|
|
|
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "networkidle" })
|
2021-01-28 19:48:57 +01:00
|
|
|
// Type in password
|
2021-01-29 00:23:55 +01:00
|
|
|
await page.fill(".password", process.env.PASSWORD || "password")
|
2021-01-28 19:48:57 +01:00
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
2021-01-29 00:23:55 +01:00
|
|
|
// Click the Application menu
|
2021-01-28 19:48:57 +01:00
|
|
|
await page.click(".menubar-menu-button[title='Application Menu']")
|
|
|
|
// See the Go Home button
|
2021-01-29 00:23:55 +01:00
|
|
|
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
|
2021-01-28 19:48:57 +01:00
|
|
|
expect(await page.isVisible(goHomeButton))
|
2021-01-29 00:23:55 +01:00
|
|
|
// Click it and navigate to coder.com
|
|
|
|
// NOTE: ran into issues of it failing intermittently
|
|
|
|
// without having button: "middle"
|
|
|
|
await page.click(goHomeButton, { button: "middle" })
|
|
|
|
|
|
|
|
// If there are unsaved changes it will show a dialog
|
|
|
|
// asking if you're sure you want to leave
|
|
|
|
page.on("dialog", (dialog) => dialog.accept())
|
|
|
|
|
|
|
|
// We make sure to wait on a request to the GO_HOME_URL
|
|
|
|
await page.waitForRequest(GO_HOME_URL)
|
|
|
|
expect(requestedGoHomeUrl).toBeTruthy()
|
2021-01-28 19:48:57 +01:00
|
|
|
})
|
|
|
|
})
|