2021-01-28 18:48:57 +00:00
|
|
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
|
|
|
|
|
|
|
describe("login", () => {
|
|
|
|
let browser: Browser
|
|
|
|
let page: Page
|
|
|
|
let context: BrowserContext
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2021-01-28 23:23:55 +00:00
|
|
|
browser = await chromium.launch()
|
2021-02-01 21:38:53 +00:00
|
|
|
// Create a new context with the saved storage state
|
|
|
|
const storageState = JSON.parse(process.env.STORAGE || "")
|
|
|
|
context = await browser.newContext({ storageState })
|
2021-01-28 18:48:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2021-02-01 21:38:53 +00:00
|
|
|
// Remove password from local storage
|
|
|
|
await context.clearCookies()
|
|
|
|
|
2021-01-28 18:48:57 +00:00
|
|
|
await browser.close()
|
2021-01-28 23:23:55 +00:00
|
|
|
await context.close()
|
2021-01-28 18:48:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
page = await context.newPage()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
|
2021-01-28 23:23:55 +00: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
|
2021-02-01 21:38:53 +00:00
|
|
|
console.log("woooo =>>>", requestedGoHomeUrl)
|
2021-01-28 23:23:55 +00:00
|
|
|
}
|
|
|
|
})
|
2021-02-01 21:38:53 +00:00
|
|
|
|
|
|
|
// waitUntil: "domcontentloaded"
|
2021-01-28 23:23:55 +00:00
|
|
|
// In case the page takes a long time to load
|
2021-02-01 21:38:53 +00:00
|
|
|
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
|
2021-01-28 23:23:55 +00:00
|
|
|
// Click the Application menu
|
2021-01-28 18:48:57 +00:00
|
|
|
await page.click(".menubar-menu-button[title='Application Menu']")
|
|
|
|
// See the Go Home button
|
2021-01-28 23:23:55 +00:00
|
|
|
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
|
2021-01-28 18:48:57 +00:00
|
|
|
expect(await page.isVisible(goHomeButton))
|
2021-01-28 23:23:55 +00: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
|
2021-02-01 21:38:53 +00:00
|
|
|
await page.on("dialog", (dialog) => dialog.accept())
|
2021-01-28 23:23:55 +00:00
|
|
|
|
2021-02-01 21:38:53 +00:00
|
|
|
// If it takes longer than 3 seconds to navigate, something is wrong
|
|
|
|
await page.waitForRequest(GO_HOME_URL, { timeout: 10000 })
|
2021-01-28 23:23:55 +00:00
|
|
|
expect(requestedGoHomeUrl).toBeTruthy()
|
2021-02-01 21:38:53 +00:00
|
|
|
|
|
|
|
// // Make sure the response for GO_HOME_URL was successful
|
|
|
|
// const response = await page.waitForResponse(
|
|
|
|
// (response) => response.url() === GO_HOME_URL && response.status() === 200,
|
|
|
|
// )
|
|
|
|
// We make sure a request was made to the GO_HOME_URL
|
|
|
|
// expect(response.ok()).toBeTruthy()
|
2021-01-28 18:48:57 +00:00
|
|
|
})
|
|
|
|
})
|