Skip to content

Commit

Permalink
Merge pull request #34 from shopcanal/alex-whitaker.dont-login-so-much
Browse files Browse the repository at this point in the history
test: log out before we attempt login for each test
  • Loading branch information
alex-whitaker committed Nov 23, 2021
2 parents 47c3b09 + b8a8a7d commit d6e5414
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 20 deletions.
9 changes: 7 additions & 2 deletions helpers/login.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<void> => {
export const logInSuccessfully = async (page: Page, context: BrowserContext): Promise<void> => {
if (process.env.APP_TEST_PASSWORD) {
await logout(context);
await page.goto(LOGIN_PAGE);

// Fill out email and password
Expand All @@ -32,3 +33,7 @@ export const logInSuccessfully = async (page: Page): Promise<void> => {
expect(true).toBe(false);
}
};

export const logout = async (context: BrowserContext): Promise<void> => {
await context.clearCookies();
};
7 changes: 5 additions & 2 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/shopkeep/discover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions tests/shopkeep/inventory-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

/**
Expand Down
12 changes: 8 additions & 4 deletions tests/shopkeep/navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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 ({
Expand Down
10 changes: 7 additions & 3 deletions tests/shopkeep/requests.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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();
Expand All @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions tests/supplier/navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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.');
Expand Down

0 comments on commit d6e5414

Please sign in to comment.