From c2f1a2dace23a6b7f84fe441f16e748b61f214ff Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 28 Jan 2021 11:48:57 -0700 Subject: [PATCH] feat: add test for login page --- test/goHome.test.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++ test/login.test.ts | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 test/goHome.test.ts create mode 100644 test/login.test.ts diff --git a/test/goHome.test.ts b/test/goHome.test.ts new file mode 100644 index 00000000..b3faf825 --- /dev/null +++ b/test/goHome.test.ts @@ -0,0 +1,50 @@ +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", () => { + let browser: Browser + let page: Page + let context: BrowserContext + + beforeAll(async () => { + browser = await chromium.launch({ headless: false }) + context = await browser.newContext() + }) + + afterAll(async () => { + await browser.close() + }) + + beforeEach(async () => { + page = await context.newPage() + }) + + afterEach(async () => { + await page.close() + // Remove password from local storage + await context.clearCookies() + }) + + it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => { + await page.goto("http://localhost:8080") + // Type in password + await page.fill(".password", PASSWORD) + // Click the submit button and login + await page.click(".submit") + // Click the Applicaiton menu + await page.click(".menubar-menu-button[title='Application Menu']") + // See the Go Home button + const goHomeButton = ".home-bar[aria-label='Home'] li" + expect(await page.isVisible(goHomeButton)) + // Hover over element without clicking + await page.hover(goHomeButton) + // Click the top left corner of the element + await page.click(goHomeButton) + // Note: we have to click on
  • in the Go Home button for it to work + // Land on coder.com + // expect(await page.url()).toBe("https://coder.com/") + }) +}) diff --git a/test/login.test.ts b/test/login.test.ts new file mode 100644 index 00000000..622adddb --- /dev/null +++ b/test/login.test.ts @@ -0,0 +1,41 @@ +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", () => { + let browser: Browser + let page: Page + let context: BrowserContext + + beforeAll(async () => { + browser = await chromium.launch() + context = await browser.newContext() + }) + + afterAll(async () => { + await browser.close() + }) + + beforeEach(async () => { + page = await context.newPage() + }) + + afterEach(async () => { + await page.close() + // Remove password from local storage + await context.clearCookies() + }) + + it("should be able to login with the password from config.yml", async () => { + await page.goto("http://localhost:8080") + // Type in password + await page.fill(".password", PASSWORD) + // Click the submit button and login + await page.click(".submit") + // See the editor + const codeServerEditor = await page.isVisible(".monaco-workbench") + expect(codeServerEditor).toBeTruthy() + }) +})