2021-02-05 04:54:08 +07:00
|
|
|
import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
|
|
|
|
import { hash } from "../src/node/util"
|
2021-02-13 02:08:34 +07:00
|
|
|
import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants"
|
2021-02-13 02:43:11 +07:00
|
|
|
import { createCookieIfDoesntExist } from "./helpers"
|
2021-01-29 01:48:57 +07:00
|
|
|
|
2021-03-17 02:49:49 +07:00
|
|
|
describe("Open Help > About", () => {
|
2021-01-29 01:48:57 +07:00
|
|
|
let browser: Browser
|
|
|
|
let page: Page
|
|
|
|
let context: BrowserContext
|
|
|
|
|
2021-02-12 01:18:15 +07:00
|
|
|
beforeAll(async () => {
|
2021-03-17 04:19:36 +07:00
|
|
|
browser = await chromium.launch()
|
2021-02-02 04:38:53 +07:00
|
|
|
// Create a new context with the saved storage state
|
2021-02-13 02:08:34 +07:00
|
|
|
const storageState = JSON.parse(STORAGE) || {}
|
2021-02-05 04:54:08 +07:00
|
|
|
|
|
|
|
const cookieToStore = {
|
|
|
|
sameSite: "Lax" as const,
|
|
|
|
name: "key",
|
2021-02-13 02:08:34 +07:00
|
|
|
value: hash(PASSWORD),
|
2021-02-05 04:54:08 +07:00
|
|
|
domain: "localhost",
|
|
|
|
path: "/",
|
|
|
|
expires: -1,
|
|
|
|
httpOnly: false,
|
|
|
|
secure: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some odd reason, the login method used in globalSetup.ts doesn't always work
|
|
|
|
// I don't know if it's on playwright clearing our cookies by accident
|
|
|
|
// or if it's our cookies disappearing.
|
|
|
|
// This means we need an additional check to make sure we're logged in.
|
|
|
|
// We do this by manually adding the cookie to the browser environment
|
|
|
|
// if it's not there at the time the test starts
|
|
|
|
const cookies: Cookie[] = storageState.cookies || []
|
|
|
|
// If the cookie exists in cookies then
|
|
|
|
// this will return the cookies with no changes
|
|
|
|
// otherwise if it doesn't exist, it will create it
|
|
|
|
// hence the name maybeUpdatedCookies
|
2021-02-13 01:58:56 +07:00
|
|
|
//
|
|
|
|
// TODO(@jsjoeio)
|
|
|
|
// The playwright storage thing sometimes works and sometimes doesn't. We should investigate this further
|
|
|
|
// at some point.
|
|
|
|
// See discussion: https://github.com/cdr/code-server/pull/2648#discussion_r575434946
|
|
|
|
|
2021-02-05 04:54:08 +07:00
|
|
|
const maybeUpdatedCookies = createCookieIfDoesntExist(cookies, cookieToStore)
|
|
|
|
|
|
|
|
context = await browser.newContext({
|
|
|
|
storageState: { cookies: maybeUpdatedCookies },
|
|
|
|
recordVideo: { dir: "./test/videos/" },
|
|
|
|
})
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
|
2021-02-12 01:18:15 +07:00
|
|
|
afterAll(async () => {
|
2021-02-02 04:38:53 +07:00
|
|
|
// Remove password from local storage
|
|
|
|
await context.clearCookies()
|
|
|
|
|
2021-01-29 06:23:55 +07:00
|
|
|
await context.close()
|
2021-02-13 02:37:27 +07:00
|
|
|
await browser.close()
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
|
2021-02-12 01:18:15 +07:00
|
|
|
beforeEach(async () => {
|
2021-01-29 01:48:57 +07:00
|
|
|
page = await context.newPage()
|
|
|
|
})
|
|
|
|
|
2021-03-17 02:49:49 +07:00
|
|
|
it("should see a 'Help' then 'About' button in the Application Menu that opens a dialog", async () => {
|
2021-02-02 04:38:53 +07:00
|
|
|
// waitUntil: "domcontentloaded"
|
2021-01-29 06:23:55 +07:00
|
|
|
// In case the page takes a long time to load
|
2021-02-13 02:08:34 +07:00
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
|
2021-02-03 03:58:51 +07:00
|
|
|
|
2021-03-06 01:58:17 +07:00
|
|
|
// Make sure the editor actually loaded
|
|
|
|
expect(await page.isVisible("div.monaco-workbench"))
|
|
|
|
|
2021-03-17 02:49:49 +07:00
|
|
|
// Click the Application menu
|
2021-03-06 01:58:17 +07:00
|
|
|
await page.click("[aria-label='Application Menu']")
|
2021-03-17 02:49:49 +07:00
|
|
|
// See the Help button
|
|
|
|
const helpButton = "a.action-menu-item span[aria-label='Help']"
|
|
|
|
expect(await page.isVisible(helpButton))
|
2021-02-03 03:58:51 +07:00
|
|
|
|
2021-03-17 04:19:36 +07:00
|
|
|
// Hover the helpButton
|
|
|
|
await page.hover(helpButton)
|
2021-03-17 02:49:49 +07:00
|
|
|
|
2021-03-17 04:19:36 +07:00
|
|
|
// see the About button and click it
|
2021-03-17 02:49:49 +07:00
|
|
|
const aboutButton = "a.action-menu-item span[aria-label='About']"
|
|
|
|
expect(await page.isVisible(aboutButton))
|
2021-03-17 04:19:36 +07:00
|
|
|
// NOTE: it won't work unless you hover it first
|
|
|
|
await page.hover(aboutButton)
|
|
|
|
await page.click(aboutButton)
|
|
|
|
|
|
|
|
const codeServerText = "text=code-server"
|
|
|
|
expect(await page.isVisible(codeServerText))
|
2021-01-29 01:48:57 +07:00
|
|
|
})
|
|
|
|
})
|