mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-27 04:35:25 +00:00
feat: add CodeServer page object for e2e tests
This commit is contained in:
parent
5ad8e686bc
commit
2665a4f61b
46
test/e2e/codeServer.test.ts
Normal file
46
test/e2e/codeServer.test.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { STORAGE } from "../utils/constants"
|
||||
import { CodeServer } from "./models/CodeServer"
|
||||
|
||||
test.describe("CodeServer", () => {
|
||||
// Create a new context with the saved storage state
|
||||
// so we don't have to logged in
|
||||
const options: any = {}
|
||||
let codeServer: CodeServer
|
||||
|
||||
// TODO@jsjoeio
|
||||
// Fix this once https://github.com/microsoft/playwright-test/issues/240
|
||||
// is fixed
|
||||
if (STORAGE) {
|
||||
const storageState = JSON.parse(STORAGE) || {}
|
||||
options.contextOptions = {
|
||||
storageState,
|
||||
}
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
codeServer = new CodeServer(page)
|
||||
await codeServer.navigate()
|
||||
})
|
||||
|
||||
test("should open the default folder if not open", options, async ({ page }) => {
|
||||
await codeServer.openFolder()
|
||||
|
||||
// find workspaceStorage in the Explorer menu, which would be open in the User folder
|
||||
// which is the default folder that opens
|
||||
expect(await page.isVisible("text=workspaceStorage")).toBe(true)
|
||||
})
|
||||
|
||||
test("should show the Integrated Terminal", options, async ({ page }) => {
|
||||
await codeServer.viewTerminal()
|
||||
expect(await page.isVisible("#terminal")).toBe(true)
|
||||
})
|
||||
|
||||
test("should open a file with quickOpen", options, async ({ page }) => {
|
||||
await codeServer.openFolder()
|
||||
await codeServer.quickOpen("extensions.json")
|
||||
// If the file is open, we will see an empty array
|
||||
// assuming no extensions are installed
|
||||
expect(await page.isVisible("text=[]"))
|
||||
})
|
||||
})
|
61
test/e2e/models/CodeServer.ts
Normal file
61
test/e2e/models/CodeServer.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { Page } from "playwright"
|
||||
import { CODE_SERVER_ADDRESS } from "../../utils/constants"
|
||||
// This is a Page Object Model
|
||||
// We use these to simplify e2e test authoring
|
||||
// See Playwright docs: https://playwright.dev/docs/pom/
|
||||
export class CodeServer {
|
||||
page: Page
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page
|
||||
}
|
||||
async navigate() {
|
||||
await this.page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
|
||||
// Make sure the editor actually loaded
|
||||
await this.page.isVisible("div.monaco-workbench")
|
||||
}
|
||||
/**
|
||||
* Opens the default folder /User if no arg passed
|
||||
* @param absolutePath Example: /Users/jp/.local/share/code-server/User/
|
||||
*
|
||||
*/
|
||||
async openFolder(absolutePath?: string) {
|
||||
// Check if no folder is opened
|
||||
const folderIsNotOpen = await this.page.isVisible("text=You have not yet opened")
|
||||
|
||||
if (folderIsNotOpen) {
|
||||
// Open the default folder
|
||||
await this.page.keyboard.press("Meta+O")
|
||||
await this.page.keyboard.press("Enter")
|
||||
await this.page.waitForLoadState("networkidle")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the integrated terminal if not already in view
|
||||
* and focuses it
|
||||
*/
|
||||
async viewTerminal() {
|
||||
// Check if Terminal is already in view
|
||||
const isTerminalInView = await this.page.isVisible("#terminal")
|
||||
|
||||
if (!isTerminalInView) {
|
||||
// Open using default keyboard shortcut
|
||||
await this.focusTerminal()
|
||||
await this.page.waitForSelector("#terminal")
|
||||
}
|
||||
}
|
||||
|
||||
async focusTerminal() {
|
||||
await this.page.keyboard.press("Control+Backquote")
|
||||
}
|
||||
|
||||
async quickOpen(input: string) {
|
||||
await this.page.keyboard.press("Meta+P")
|
||||
await this.page.waitForSelector('[aria-describedby="quickInput_message"]')
|
||||
await this.page.keyboard.type(input)
|
||||
await this.page.waitForTimeout(2000)
|
||||
await this.page.keyboard.press("Enter")
|
||||
await this.page.waitForTimeout(2000)
|
||||
}
|
||||
}
|
60
test/e2e/terminal.test.ts
Normal file
60
test/e2e/terminal.test.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { STORAGE } from "../utils/constants"
|
||||
import { CodeServer } from "./models/CodeServer"
|
||||
|
||||
test.describe("Integrated Terminal", () => {
|
||||
// Create a new context with the saved storage state
|
||||
// so we don't have to logged in
|
||||
const options: any = {}
|
||||
const testFileName = "hello.txt"
|
||||
const testString = "new string test from e2e test"
|
||||
let codeServer: CodeServer
|
||||
|
||||
// TODO@jsjoeio
|
||||
// Fix this once https://github.com/microsoft/playwright-test/issues/240
|
||||
// is fixed
|
||||
if (STORAGE) {
|
||||
const storageState = JSON.parse(STORAGE) || {}
|
||||
options.contextOptions = {
|
||||
storageState,
|
||||
}
|
||||
}
|
||||
test.beforeEach(async ({ page }) => {
|
||||
codeServer = new CodeServer(page)
|
||||
await codeServer.navigate()
|
||||
})
|
||||
|
||||
test("should echo a string to a file", options, async ({ page }) => {
|
||||
// Open the default folder
|
||||
await codeServer.openFolder()
|
||||
|
||||
// Open terminal and type in value
|
||||
await codeServer.viewTerminal()
|
||||
await codeServer.focusTerminal()
|
||||
|
||||
await page.keyboard.type(`echo '${testString}' >> ${testFileName}`)
|
||||
await page.keyboard.press("Enter")
|
||||
await page.waitForTimeout(2000)
|
||||
// It should show up on the left sidebar as a new file
|
||||
const isFileVisible = await page.isVisible(`text="${testFileName}"`)
|
||||
expect(isFileVisible).toBe(true)
|
||||
|
||||
if (isFileVisible) {
|
||||
// Check that the file has the test string in it
|
||||
await codeServer.quickOpen(testFileName)
|
||||
expect(await page.isVisible(`text="${testString}"`)).toBe(true)
|
||||
|
||||
// Clean up
|
||||
// Remove file
|
||||
await codeServer.focusTerminal()
|
||||
await page.keyboard.type(`rm ${testFileName}`)
|
||||
await page.keyboard.press("Enter")
|
||||
await page.waitForTimeout(2000)
|
||||
// Close the file from workbench
|
||||
// otherwise it will still be visible
|
||||
// and our assertion will fail
|
||||
await page.keyboard.press(`Meta+W`)
|
||||
expect(await page.isVisible(`text="${testString}"`)).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user