Skip to content

Commit 6a05889

Browse files
committed
feat: add e2e test for logout
1 parent 66e05e5 commit 6a05889

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export enum Cookie {
2-
Key = "key",
2+
Key = 'key',
33
}

test/e2e/logout.test.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { chromium, Page, Browser, BrowserContext } from "playwright"
2+
import { CODE_SERVER_ADDRESS, PASSWORD, E2E_VIDEO_DIR } from "../utils/constants"
3+
4+
describe("logout", () => {
5+
let browser: Browser
6+
let page: Page
7+
let context: BrowserContext
8+
9+
beforeAll(async () => {
10+
browser = await chromium.launch({ headless: false })
11+
context = await browser.newContext({
12+
recordVideo: { dir: E2E_VIDEO_DIR },
13+
})
14+
})
15+
16+
afterAll(async () => {
17+
await browser.close()
18+
})
19+
20+
beforeEach(async () => {
21+
page = await context.newPage()
22+
})
23+
24+
afterEach(async () => {
25+
await page.close()
26+
// Remove password from local storage
27+
await context.clearCookies()
28+
})
29+
30+
it("should be able login and logout", async () => {
31+
await page.goto(CODE_SERVER_ADDRESS)
32+
// Type in password
33+
await page.fill(".password", PASSWORD)
34+
// Click the submit button and login
35+
await page.click(".submit")
36+
// See the editor
37+
const codeServerEditor = await page.isVisible(".monaco-workbench")
38+
expect(codeServerEditor).toBeTruthy()
39+
40+
// Click the Application menu
41+
await page.click("[aria-label='Application Menu']")
42+
43+
// See the Log out button
44+
const logoutButton = "a.action-menu-item span[aria-label='Log out']"
45+
expect(await page.isVisible(logoutButton))
46+
47+
await page.hover(logoutButton)
48+
await page.click(logoutButton)
49+
50+
const currentUrl = await page.url()
51+
expect(currentUrl).toBe(`${CODE_SERVER_ADDRESS}/login`)
52+
})
53+
})

test/unit/util.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSDOM } from "jsdom"
2+
import { Cookie as CookieEnum } from "../../lib/vscode/src/vs/server/common/cookie"
23
import {
34
arrayify,
45
generateUuid,
@@ -11,7 +12,6 @@ import {
1112
trimSlashes,
1213
normalize,
1314
} from "../../src/common/util"
14-
import { Cookie as CookieEnum } from "../../src/node/routes/login"
1515
import { hash } from "../../src/node/util"
1616
import { PASSWORD } from "../utils/constants"
1717
import { checkForCookie, createCookieIfDoesntExist, loggerModule, Cookie } from "../utils/helpers"

0 commit comments

Comments
 (0)