diff --git a/helpers/login.ts b/helpers/login.ts index 770e991..f6a7c7a 100644 --- a/helpers/login.ts +++ b/helpers/login.ts @@ -1,4 +1,4 @@ -import type { Page } from '@playwright/test'; +import type { BrowserContext, Page } from '@playwright/test'; import { expect } from '@playwright/test'; import { LOGIN_PAGE, SHOPKEEP_ROUTES } from './routes'; @@ -11,8 +11,9 @@ export const LOGIN_BUTTON_SELECTOR = 'button#login'; const E2E_ACCOUNT_LOGIN = 'e2e_tester@shopcanal.com'; -export const logInSuccessfully = async (page: Page): Promise => { +export const logInSuccessfully = async (page: Page, context: BrowserContext): Promise => { if (process.env.APP_TEST_PASSWORD) { + await logout(context); await page.goto(LOGIN_PAGE); // Fill out email and password @@ -32,3 +33,7 @@ export const logInSuccessfully = async (page: Page): Promise => { expect(true).toBe(false); } }; + +export const logout = async (context: BrowserContext): Promise => { + await context.clearCookies(); +}; diff --git a/tests/login.spec.ts b/tests/login.spec.ts index c84b779..e7b84df 100644 --- a/tests/login.spec.ts +++ b/tests/login.spec.ts @@ -24,8 +24,11 @@ test.describe('Login', () => { * Tests that the user can fill out the email and password inputs, then * click login and be redirected to the app */ - test('can fill out valid email and password and successfully log in', async ({ page }) => { - await logInSuccessfully(page); + test('can fill out valid email and password and successfully log in', async ({ + context, + page, + }) => { + await logInSuccessfully(page, context); }); /** diff --git a/tests/shopkeep/discover.spec.ts b/tests/shopkeep/discover.spec.ts index 57a52e5..24bc2f0 100644 --- a/tests/shopkeep/discover.spec.ts +++ b/tests/shopkeep/discover.spec.ts @@ -11,8 +11,8 @@ test.describe('Shopkeep Discover', () => { * We need to be logged in for each test, so we should log in before each one * and then navigate to the Discover page */ - test.beforeEach(async ({ page }) => { - await logInSuccessfully(page); + test.beforeEach(async ({ context, page }) => { + await logInSuccessfully(page, context); await page.goto(SHOPKEEP_ROUTES.DISCOVER); expect(page.url().includes(SHOPKEEP_ROUTES.DISCOVER)).toBeTruthy(); diff --git a/tests/shopkeep/inventory-management.spec.ts b/tests/shopkeep/inventory-management.spec.ts index 7cb3357..91dda8b 100644 --- a/tests/shopkeep/inventory-management.spec.ts +++ b/tests/shopkeep/inventory-management.spec.ts @@ -7,10 +7,10 @@ import { logInSuccessfully } from '../../helpers/login'; */ test.describe('Shopkeep Inventory Management', () => { /** - * We need to be logged in for each test, so we should log in before each one. + * We need to be logged in for each test, so we should log in before this test suite runs. */ - test.beforeEach(async ({ page }) => { - await logInSuccessfully(page); + test.beforeEach(async ({ context, page }) => { + await logInSuccessfully(page, context); }); /** diff --git a/tests/shopkeep/navigation.spec.ts b/tests/shopkeep/navigation.spec.ts index 363898b..371e0c8 100644 --- a/tests/shopkeep/navigation.spec.ts +++ b/tests/shopkeep/navigation.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { logInSuccessfully } from '../../helpers/login'; +import { logInSuccessfully, logout } from '../../helpers/login'; import { SHOPKEEP_ROUTES } from '../../helpers/routes'; /** @@ -9,10 +9,14 @@ import { SHOPKEEP_ROUTES } from '../../helpers/routes'; test.describe('Shopkeep Navigation', () => { /** - * We need to be logged in for each test, so we should log in before each one. + * We need to be logged in for each test, so we should log in before this test suite runs. */ - test.beforeEach(async ({ page }) => { - await logInSuccessfully(page); + test.beforeEach(async ({ context, page }) => { + await logInSuccessfully(page, context); + }); + + test.afterEach(async ({ context }) => { + await logout(context); }); test('can navigate successfully to the Inventory page from the Overview tab', async ({ diff --git a/tests/shopkeep/requests.spec.ts b/tests/shopkeep/requests.spec.ts index 4d643aa..1c35930 100644 --- a/tests/shopkeep/requests.spec.ts +++ b/tests/shopkeep/requests.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { logInSuccessfully } from '../../helpers/login'; +import { logInSuccessfully, logout } from '../../helpers/login'; import { SHOPKEEP_ROUTES } from '../../helpers/routes'; /** @@ -18,8 +18,8 @@ test.describe('Shopkeep Requests', () => { * We need to be logged in for each test, so we should log in before each one * and then navigate to the Discover page */ - test.beforeEach(async ({ page }) => { - await logInSuccessfully(page); + test.beforeEach(async ({ context, page }) => { + await logInSuccessfully(page, context); await page.goto(SHOPKEEP_ROUTES.REQUESTS); expect(page.url().includes(SHOPKEEP_ROUTES.REQUESTS)).toBeTruthy(); @@ -28,6 +28,10 @@ test.describe('Shopkeep Requests', () => { await page.waitForSelector('text=Showing 2 product requests'); }); + test.afterEach(async ({ context }) => { + await logout(context); + }); + test('displays two requests and tabs for filtering requests by status', async ({ page }) => { // Check that there are two list items const requestLineItems = await page.$$(LIST_ITEM_SELECTOR); diff --git a/tests/supplier/navigation.spec.ts b/tests/supplier/navigation.spec.ts index fe06ea3..04021a1 100644 --- a/tests/supplier/navigation.spec.ts +++ b/tests/supplier/navigation.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { logInSuccessfully } from '../../helpers/login'; +import { logInSuccessfully, logout } from '../../helpers/login'; import { SUPPLIER_ROUTES } from '../../helpers/routes'; /** @@ -9,16 +9,23 @@ import { SUPPLIER_ROUTES } from '../../helpers/routes'; test.describe('Supplier Navigation', () => { /** - * We need to be logged in for each test, so we should log in before each one. + * We need to be logged in for each test, so we should log in before this test suite runs. */ - test.beforeEach(async ({ page }) => { - await logInSuccessfully(page); + test.beforeEach(async ({ page, context }) => { + await logInSuccessfully(page, context); // Navigate to the overview page of the Supplier app await page.goto(SUPPLIER_ROUTES.OVERVIEW); }); + test.afterEach(async ({ context }) => { + await logout(context); + }); + test('renders the SUP Overview page', async ({ page }) => { + // Click the Overview link in the nav + await page.click('button#Overview'); + await page.waitForSelector('text=Welcome to Canal'); await page.waitForSelector('text=The status of products listed on Canal is shown here.'); await page.waitForSelector('text=The percentage of each sale your storefront partners keep.');