|
1 | | -import { test, expect } from "@playwright/test" |
2 | 1 | import { PASSWORD } from "../utils/constants" |
3 | | -import { CodeServer } from "./models/CodeServer" |
| 2 | +import { test, expect } from "./baseFixture" |
4 | 3 |
|
5 | 4 | test.describe("login", () => { |
6 | 5 | // Reset the browser so no cookies are persisted |
7 | 6 | // by emptying the storageState |
8 | | - const options = { |
9 | | - contextOptions: { |
10 | | - storageState: {}, |
11 | | - }, |
12 | | - } |
13 | | - let codeServer: CodeServer |
14 | | - |
15 | | - test.beforeEach(async ({ page }) => { |
16 | | - codeServer = new CodeServer(page) |
17 | | - await codeServer.navigate() |
| 7 | + test.use({ |
| 8 | + storageState: {}, |
18 | 9 | }) |
19 | 10 |
|
20 | | - test("should see the login page", options, async ({ page }) => { |
| 11 | + test("should see the login page", async ({ codeServerPage }) => { |
21 | 12 | // It should send us to the login page |
22 | | - expect(await page.title()).toBe("code-server login") |
| 13 | + expect(await codeServerPage.page.title()).toBe("code-server login") |
23 | 14 | }) |
24 | 15 |
|
25 | | - test("should be able to login", options, async ({ page }) => { |
| 16 | + test("should be able to login", async ({ codeServerPage }) => { |
26 | 17 | // Type in password |
27 | | - await page.fill(".password", PASSWORD) |
| 18 | + await codeServerPage.page.fill(".password", PASSWORD) |
28 | 19 | // Click the submit button and login |
29 | | - await page.click(".submit") |
30 | | - await page.waitForLoadState("networkidle") |
| 20 | + await codeServerPage.page.click(".submit") |
| 21 | + await codeServerPage.page.waitForLoadState("networkidle") |
31 | 22 | // We do this because occassionally code-server doesn't load on Firefox |
32 | 23 | // but loads if you reload once or twice |
33 | | - await codeServer.reloadUntilEditorIsReady() |
| 24 | + await codeServerPage.reloadUntilEditorIsReady() |
34 | 25 | // Make sure the editor actually loaded |
35 | | - expect(await codeServer.isEditorVisible()).toBe(true) |
| 26 | + expect(await codeServerPage.isEditorVisible()).toBe(true) |
36 | 27 | }) |
37 | 28 |
|
38 | | - test("should see an error message for missing password", options, async ({ page }) => { |
| 29 | + test("should see an error message for missing password", async ({ codeServerPage }) => { |
39 | 30 | // Skip entering password |
40 | 31 | // Click the submit button and login |
41 | | - await page.click(".submit") |
42 | | - await page.waitForLoadState("networkidle") |
43 | | - expect(await page.isVisible("text=Missing password")) |
| 32 | + await codeServerPage.page.click(".submit") |
| 33 | + await codeServerPage.page.waitForLoadState("networkidle") |
| 34 | + expect(await codeServerPage.page.isVisible("text=Missing password")) |
44 | 35 | }) |
45 | 36 |
|
46 | | - test("should see an error message for incorrect password", options, async ({ page }) => { |
| 37 | + test("should see an error message for incorrect password", async ({ codeServerPage }) => { |
47 | 38 | // Type in password |
48 | | - await page.fill(".password", "password123") |
| 39 | + await codeServerPage.page.fill(".password", "password123") |
49 | 40 | // Click the submit button and login |
50 | | - await page.click(".submit") |
51 | | - await page.waitForLoadState("networkidle") |
52 | | - expect(await page.isVisible("text=Incorrect password")) |
| 41 | + await codeServerPage.page.click(".submit") |
| 42 | + await codeServerPage.page.waitForLoadState("networkidle") |
| 43 | + expect(await codeServerPage.page.isVisible("text=Incorrect password")) |
53 | 44 | }) |
54 | 45 |
|
55 | | - test("should hit the rate limiter for too many unsuccessful logins", options, async ({ page }) => { |
| 46 | + test("should hit the rate limiter for too many unsuccessful logins", async ({ codeServerPage }) => { |
56 | 47 | // Type in password |
57 | | - await page.fill(".password", "password123") |
| 48 | + await codeServerPage.page.fill(".password", "password123") |
58 | 49 | // Click the submit button and login |
59 | 50 | // The current RateLimiter allows 2 logins per minute plus |
60 | 51 | // 12 logins per hour for a total of 14 |
61 | 52 | // See: src/node/routes/login.ts |
62 | 53 | for (let i = 1; i <= 14; i++) { |
63 | | - await page.click(".submit") |
64 | | - await page.waitForLoadState("networkidle") |
| 54 | + await codeServerPage.page.click(".submit") |
| 55 | + await codeServerPage.page.waitForLoadState("networkidle") |
65 | 56 | // We double-check that the correct error message shows |
66 | 57 | // which should be for incorrect password |
67 | | - expect(await page.isVisible("text=Incorrect password")) |
| 58 | + expect(await codeServerPage.page.isVisible("text=Incorrect password")) |
68 | 59 | } |
69 | 60 |
|
70 | 61 | // The 15th should fail for a different reason: |
71 | 62 | // login rate |
72 | | - await page.click(".submit") |
73 | | - await page.waitForLoadState("networkidle") |
74 | | - expect(await page.isVisible("text=Login rate limited!")) |
| 63 | + await codeServerPage.page.click(".submit") |
| 64 | + await codeServerPage.page.waitForLoadState("networkidle") |
| 65 | + expect(await codeServerPage.page.isVisible("text=Login rate limited!")) |
75 | 66 | }) |
76 | 67 | }) |
0 commit comments