feat: add isConnected method to CodeServer model

This commit is contained in:
Joe Previte 2021-04-30 12:33:20 -07:00
parent 0d9fe6ff44
commit 2cb499385a
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
2 changed files with 23 additions and 0 deletions

View File

@ -38,6 +38,10 @@ test.describe("CodeServer", () => {
expect(await codeServer.isEditorVisible()).toBe(true) expect(await codeServer.isEditorVisible()).toBe(true)
}) })
test.only("should always have a connection", options, async ({ page }) => {
expect(await codeServer.isConnected()).toBe(true)
})
test("should show the Integrated Terminal", options, async ({ page }) => { test("should show the Integrated Terminal", options, async ({ page }) => {
await codeServer.focusTerminal() await codeServer.focusTerminal()
expect(await page.isVisible("#terminal")).toBe(true) expect(await page.isVisible("#terminal")).toBe(true)

View File

@ -56,6 +56,25 @@ export class CodeServer {
return await this.page.isVisible(this.editorSelector) return await this.page.isVisible(this.editorSelector)
} }
/**
* Checks if the editor is visible
*/
async isConnected() {
await this.page.waitForLoadState("networkidle")
// See [aria-label="Remote Host"]
const hostElement = await this.page.$(`[aria-label="Remote Host"]`)
// Returns something like " localhost:8080"
const host = await hostElement?.innerText()
// Check if host (localhost:8080) is in the CODE_SERVER_ADDRESS
// if it is, we're connected!
// if not, we may need to reload the page
// Make sure to trim whitespace too
const isEditorConnected = host ? CODE_SERVER_ADDRESS.includes(host.trim()) : false
return isEditorConnected
}
/** /**
* Focuses Integrated Terminal * Focuses Integrated Terminal
* by using "Terminal: Focus Terminal" * by using "Terminal: Focus Terminal"