diff --git a/portal/jest.config.js b/portal/jest.config.js index 734a5e255..2781d6048 100644 --- a/portal/jest.config.js +++ b/portal/jest.config.js @@ -92,7 +92,7 @@ const config = { // moduleNameMapper: {}, // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], + modulePathIgnorePatterns: ['static/js/__tests__/consts'], // Activates notifications for test results // notify: false, diff --git a/portal/static/js/__tests__/consts/index.js b/portal/static/js/__tests__/consts/index.js new file mode 100644 index 000000000..b4b990c00 --- /dev/null +++ b/portal/static/js/__tests__/consts/index.js @@ -0,0 +1,5 @@ +export const testPatientEmail = process.env.testPatientEmail; +export const testPatientPassword = process.env.testPatientPassword; +export const testStaffEmail = process.env.testStaffEmail; +export const testStaffPassword = process.env.testStaffPassword; +export const homePageURL = process.env.homePageURL; \ No newline at end of file diff --git a/portal/static/js/__tests__/loadPatientHomePage.test.js b/portal/static/js/__tests__/loadPatientHomePage.test.js index d8cb8f00b..5c0e7bee8 100644 --- a/portal/static/js/__tests__/loadPatientHomePage.test.js +++ b/portal/static/js/__tests__/loadPatientHomePage.test.js @@ -1,13 +1,11 @@ import "expect-puppeteer"; import puppeteer from "puppeteer"; +import {testPatientEmail, testPatientPassword, homePageURL} from "./consts"; -//TODO get these from environment variables? -// const homepage = "https://eproms-test.cirg.washington.edu"; -// const testEmail = atob("YWNoZW4yNDAxK3Rlc3QxMTFAZ21haWwuY29t"); -// const testPassword = atob("RWxlYW5vcjI="); -const testEmail = process.env.testPatientEmail; -const testPassword = process.env.testPatientPassword; -const homepage = process.env.homePageURL; +//test variables +// const homePageURL = "https://eproms-test.cirg.washington.edu"; +// const testPatientEmail = atob("YWNoZW4yNDAxK3Rlc3QxMTFAZ21haWwuY29t"); +// const testPatientPassword = atob("RWxlYW5vcjI="); describe("Login in to Patient Home Page", () => { const TIMEOUT_DURATION = 30000; @@ -20,7 +18,7 @@ describe("Login in to Patient Home Page", () => { page = await browser.newPage(); const timeout = TIMEOUT_DURATION; page.setDefaultTimeout(timeout); - await page.goto(homepage); + await page.goto(homePageURL); await page.setViewport({ width: 1477, height: 890, @@ -42,10 +40,10 @@ describe("Login in to Patient Home Page", () => { y: 17.21875, }, }); - await page.locator("#email").fill(testEmail); + await page.locator("#email").fill(testPatientEmail); await page.keyboard.down("Tab"); await page.keyboard.up("Tab"); - await page.locator("#password").fill(testPassword); + await page.locator("#password").fill(testPatientPassword); }); it("should click submit button", async () => { diff --git a/portal/static/js/__tests__/loadPatientsList.test.js b/portal/static/js/__tests__/loadPatientsList.test.js new file mode 100644 index 000000000..5a3e16507 --- /dev/null +++ b/portal/static/js/__tests__/loadPatientsList.test.js @@ -0,0 +1,69 @@ +import "expect-puppeteer"; +import puppeteer from "puppeteer"; +import { testStaffEmail, testStaffPassword, homePageURL } from "./consts"; + +//test variables +// const homePageURL = "https://eproms-test.cirg.washington.edu"; +// const testPatientEmail = atob("YWNoZW4yNDAxK3Rlc3QxMTFAZ21haWwuY29t"); +// const testPatientPassword = atob("RWxlYW5vcjI="); + +describe("Login in to Staff Home Page", () => { + const TIMEOUT_DURATION = 30000; + jest.setTimeout(TIMEOUT_DURATION); + let browser, page; + beforeAll(async () => { + await jestPuppeteer.resetBrowser(); + await jestPuppeteer.resetPage(); + browser = await puppeteer.launch(); + page = await browser.newPage(); + const timeout = TIMEOUT_DURATION; + page.setDefaultTimeout(timeout); + await page.goto(homePageURL); + await page.setViewport({ + width: 1477, + height: 890, + }); + }); + + afterAll(async () => { + browser.close(); + }); + + it('should display "Log in" text on page', async () => { + await expect(page).toMatchTextContent(/Log in/); + }); + + it("should fill in login form", async () => { + await page.locator("#email").click({ + offset: { + x: 108.5, + y: 17.21875, + }, + }); + await page.locator("#email").fill(testStaffEmail); + await page.keyboard.down("Tab"); + await page.keyboard.up("Tab"); + await page.locator("#password").fill(testStaffPassword); + }); + + it("should set remember me cookie", async () => { + let expirationDate = new Date(); + expirationDate.setDate(expirationDate.getDate() + 17); + await page.setCookie({ + name: "Truenth2FA_REMEMBERME", + value: encodeURIComponent(btoa(new Date().getTime())), + path: "/", + expires: expirationDate.valueOf(), + }); + }); + + it("should click submit button", async () => { + await page.locator("#btnLogin").click(); + }); + + // failed due to 2FA, skip it + it.skip("should have staff list on page", async () => { + await page.waitForSelector("#staffList"); + await expect(page).toMatchElement("#staffList"); + }); +});