mirror of https://git.tuxpa.in/a/code-server.git
feat: add test to visit go home in app menu
This commit is contained in:
parent
d7e41a3187
commit
3033c8f9a2
|
@ -24,6 +24,9 @@ jobs:
|
||||||
test:
|
test:
|
||||||
needs: linux-amd64
|
needs: linux-amd64
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PASSWORD: e45432jklfdsab
|
||||||
|
CODE_SERVER_ADDRESS: http://localhost:8080
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Download release packages
|
- name: Download release packages
|
||||||
|
@ -37,7 +40,7 @@ jobs:
|
||||||
- uses: microsoft/playwright-github-action@v1
|
- uses: microsoft/playwright-github-action@v1
|
||||||
- name: Install dependencies and run tests
|
- name: Install dependencies and run tests
|
||||||
run: |
|
run: |
|
||||||
node ./release-packages/code-server*-linux-amd64 &
|
node ./release-packages/code-server*-linux-amd64 --home $CODE_SERVER_ADDRESS/healthz &
|
||||||
yarn --frozen-lockfile
|
yarn --frozen-lockfile
|
||||||
yarn test
|
yarn test
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ main() {
|
||||||
# information. We must also run it from the root otherwise coverage will not
|
# information. We must also run it from the root otherwise coverage will not
|
||||||
# include our source files.
|
# include our source files.
|
||||||
cd "$OLDPWD"
|
cd "$OLDPWD"
|
||||||
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@"
|
# We use the same environment variables set in ci.yml in the test job
|
||||||
|
CS_DISABLE_PLUGINS=true PASSWORD=e45432jklfdsab CODE_SERVER_ADDRESS=http://localhost:8080 ./test/node_modules/.bin/jest "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
||||||
|
|
||||||
// NOTE: this is hard-coded and passed as an environment variable
|
|
||||||
// See the test job in ci.yml
|
|
||||||
const PASSWORD = "e45432jklfdsab"
|
|
||||||
|
|
||||||
describe("login", () => {
|
describe("login", () => {
|
||||||
let browser: Browser
|
let browser: Browser
|
||||||
let page: Page
|
let page: Page
|
||||||
let context: BrowserContext
|
let context: BrowserContext
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
browser = await chromium.launch({ headless: false })
|
browser = await chromium.launch()
|
||||||
context = await browser.newContext()
|
context = await browser.newContext()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
await context.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -29,22 +26,40 @@ describe("login", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
|
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
|
||||||
await page.goto("http://localhost:8080")
|
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" })
|
||||||
// Type in password
|
// Type in password
|
||||||
await page.fill(".password", PASSWORD)
|
await page.fill(".password", process.env.PASSWORD || "password")
|
||||||
// Click the submit button and login
|
// Click the submit button and login
|
||||||
await page.click(".submit")
|
await page.click(".submit")
|
||||||
// Click the Applicaiton menu
|
// Click the Application menu
|
||||||
await page.click(".menubar-menu-button[title='Application Menu']")
|
await page.click(".menubar-menu-button[title='Application Menu']")
|
||||||
// See the Go Home button
|
// See the Go Home button
|
||||||
const goHomeButton = ".home-bar[aria-label='Home'] li"
|
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
|
||||||
expect(await page.isVisible(goHomeButton))
|
expect(await page.isVisible(goHomeButton))
|
||||||
// Hover over element without clicking
|
// Click it and navigate to coder.com
|
||||||
await page.hover(goHomeButton)
|
// NOTE: ran into issues of it failing intermittently
|
||||||
// Click the top left corner of the element
|
// without having button: "middle"
|
||||||
await page.click(goHomeButton)
|
await page.click(goHomeButton, { button: "middle" })
|
||||||
// Note: we have to click on <li> in the Go Home button for it to work
|
|
||||||
// Land on coder.com
|
// If there are unsaved changes it will show a dialog
|
||||||
// expect(await page.url()).toBe("https://coder.com/")
|
// 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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
||||||
|
|
||||||
// NOTE: this is hard-coded and passed as an environment variable
|
|
||||||
// See the test job in ci.yml
|
|
||||||
const PASSWORD = "e45432jklfdsab"
|
|
||||||
|
|
||||||
describe("login", () => {
|
describe("login", () => {
|
||||||
let browser: Browser
|
let browser: Browser
|
||||||
let page: Page
|
let page: Page
|
||||||
|
@ -29,9 +25,9 @@ describe("login", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to login with the password from config.yml", async () => {
|
it("should be able to login with the password from config.yml", async () => {
|
||||||
await page.goto("http://localhost:8080")
|
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080")
|
||||||
// Type in password
|
// Type in password
|
||||||
await page.fill(".password", PASSWORD)
|
await page.fill(".password", process.env.PASSWORD || "password")
|
||||||
// Click the submit button and login
|
// Click the submit button and login
|
||||||
await page.click(".submit")
|
await page.click(".submit")
|
||||||
// See the editor
|
// See the editor
|
||||||
|
|
Loading…
Reference in New Issue