Skip to content

Commit

Permalink
#225: Change print width to 120 for playwright files
Browse files Browse the repository at this point in the history
  • Loading branch information
bstein committed Sep 21, 2022
1 parent 77bd29c commit cca398c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 91 deletions.
2 changes: 1 addition & 1 deletion playwright/.prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
printWidth: 80
printWidth: 120
tabWidth: 2
useTabs: false
semi: true
Expand Down
16 changes: 5 additions & 11 deletions playwright/electron-app-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ElectronApplication,
Page,
_electron as electron
} from '@playwright/test';
import { ElectronApplication, Page, _electron as electron } from '@playwright/test';

export class ElectronAppManager {
static app: ElectronApplication;
Expand Down Expand Up @@ -51,18 +47,16 @@ export class ElectronAppManager {

static async mockIpcMainHandle(channel: string, returnValue: any) {
await ElectronAppManager.app.evaluate(
({ ipcMain }, params) =>
ipcMain.handle(params.channel, () => params.returnValue),
({ ipcMain }, params) => ipcMain.handle(params.channel, () => params.returnValue),
{ channel, returnValue }
);
}

static async removeAllIpcMainListeners(channel?: string) {
try {
await ElectronAppManager.app?.evaluate(
({ ipcMain }, params) => ipcMain.removeAllListeners(params.channel),
{ channel }
);
await ElectronAppManager.app?.evaluate(({ ipcMain }, params) => ipcMain.removeAllListeners(params.channel), {
channel
});
} catch {}
}
}
6 changes: 1 addition & 5 deletions playwright/mocks/ipc-main-handle.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
PROJECT_INVALID,
PROJECT_NEW,
PROJECT_OFFICE_HVAC
} from './projects.mocks';
import { PROJECT_INVALID, PROJECT_NEW, PROJECT_OFFICE_HVAC } from './projects.mocks';

export interface ShowOpenDialogMock {
canceled: boolean;
Expand Down
8 changes: 2 additions & 6 deletions playwright/page-objects/modals/modal.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ export class ModalPageObject extends BasePageObject {
}

async areButtonsOk() {
await expect(this.buttons).toHaveCount(
Object.keys(this.EXPECTED_BUTTONS).length
);
await expect(this.buttons).toHaveCount(Object.keys(this.EXPECTED_BUTTONS).length);
const allInnerTexts = await this.buttons.allInnerTexts();
Object.values(this.EXPECTED_BUTTONS).forEach(buttonText =>
expect(allInnerTexts).toContain(buttonText)
);
Object.values(this.EXPECTED_BUTTONS).forEach(buttonText => expect(allInnerTexts).toContain(buttonText));
}

async isOk() {
Expand Down
21 changes: 4 additions & 17 deletions playwright/page-objects/modals/project-modal.po.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import { ElectronAppManager } from '../../electron-app-manager';
import {
IPC_MAIN_HANDLE_MOCKS,
ShowMessageBoxMock,
ShowOpenDialogMock
} from '../../mocks';
import { IPC_MAIN_HANDLE_MOCKS, ShowMessageBoxMock, ShowOpenDialogMock } from '../../mocks';
import { ModalPageObject } from './modal.po';

export class ProjectModalPageObject extends ModalPageObject {
readonly EXPECTED_TITLE: string;
readonly EXPECTED_BUTTONS: Record<string, string>;
readonly OPEN_BUTTON_TEXT: string;

async open(
showOpenDialogMock?: ShowOpenDialogMock,
showMessageBoxMock?: ShowMessageBoxMock
) {
async open(showOpenDialogMock?: ShowOpenDialogMock, showMessageBoxMock?: ShowMessageBoxMock) {
if (showOpenDialogMock !== undefined) {
await ElectronAppManager.mockIpcMainHandle(
IPC_MAIN_HANDLE_MOCKS.showOpenDialogChannel,
showOpenDialogMock
);
await ElectronAppManager.mockIpcMainHandle(IPC_MAIN_HANDLE_MOCKS.showOpenDialogChannel, showOpenDialogMock);
}
if (showMessageBoxMock !== undefined) {
await ElectronAppManager.mockIpcMainHandle(
IPC_MAIN_HANDLE_MOCKS.showMessageBoxChannel,
showMessageBoxMock
);
await ElectronAppManager.mockIpcMainHandle(IPC_MAIN_HANDLE_MOCKS.showMessageBoxChannel, showMessageBoxMock);
}

await this.clickButton(this.OPEN_BUTTON_TEXT);
Expand Down
9 changes: 2 additions & 7 deletions playwright/page-objects/nav.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ export class NavPageObject extends BasePageObject {
return iconImgSrc.slice(iconImgSrc.lastIndexOf('/') + 1);
}

async isItemOk(
item: Locator,
expectedPageDetails: Omit<PageDetails, 'title'>
) {
async isItemOk(item: Locator, expectedPageDetails: Omit<PageDetails, 'title'>) {
expect(await this.getRouteFor(item)).toBe(expectedPageDetails.route);
expect(await this.getIconAltFor(item)).toBe(expectedPageDetails.iconAlt);
expect(await this.getIconImgNameFor(item)).toBe(
expectedPageDetails.iconImgName
);
expect(await this.getIconImgNameFor(item)).toBe(expectedPageDetails.iconImgName);
}

async areItemsOk() {
Expand Down
4 changes: 1 addition & 3 deletions playwright/page-objects/pages/page.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export class PagePageObject extends BasePageObject {
}

async isTitleOk() {
await expect(await this.getTitle()).toHaveText(
this.EXPECTED_PAGE_DETAILS.title
);
await expect(await this.getTitle()).toHaveText(this.EXPECTED_PAGE_DETAILS.title);
}

async isNavOk() {
Expand Down
4 changes: 1 addition & 3 deletions playwright/page-objects/toasts/toast.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export class ToastPageObject extends BasePageObject {
}

async isLevelOk() {
await expect(this.toast).toHaveClass(
new RegExp(ToastLevels[this.EXPECTED_LEVEL])
);
await expect(this.toast).toHaveClass(new RegExp(ToastLevels[this.EXPECTED_LEVEL]));
}

async isOk() {
Expand Down
20 changes: 4 additions & 16 deletions playwright/tests/nav.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { test } from '@playwright/test';
import { ElectronAppManager } from '../electron-app-manager';
import {
EXPECTED_DETAILS_BY_PAGE,
IPC_MAIN_HANDLE_MOCKS,
PROJECT_NEW,
PROJECT_OFFICE_HVAC
} from '../mocks';
import { EXPECTED_DETAILS_BY_PAGE, IPC_MAIN_HANDLE_MOCKS, PROJECT_NEW, PROJECT_OFFICE_HVAC } from '../mocks';
import {
NavPageObject,
NewProjectModalPageObject,
Expand All @@ -26,24 +21,17 @@ test.afterEach(async () => {
await ElectronAppManager.closeApp();
});

const PROJECT_TYPES: Record<
string,
{ projectName: string; beforeEach: () => Promise<void> }
> = {
const PROJECT_TYPES: Record<string, { projectName: string; beforeEach: () => Promise<void> }> = {
existing: {
projectName: PROJECT_OFFICE_HVAC.name,
beforeEach: async () => {
await selectProjPO.open(
IPC_MAIN_HANDLE_MOCKS.showOpenDialog.validOfficeHVAC
);
await selectProjPO.open(IPC_MAIN_HANDLE_MOCKS.showOpenDialog.validOfficeHVAC);
}
},
new: {
projectName: PROJECT_NEW.name,
beforeEach: async () => {
await selectProjPO.clickButton(
selectProjPO.EXPECTED_BUTTONS.MAKE_NEW_PROJECT
);
await selectProjPO.clickButton(selectProjPO.EXPECTED_BUTTONS.MAKE_NEW_PROJECT);
await newProjPO.nameInput.fill(PROJECT_NEW.name);
await newProjPO.open(IPC_MAIN_HANDLE_MOCKS.showOpenDialog.validNew);
}
Expand Down
27 changes: 5 additions & 22 deletions playwright/tests/select-project-modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { expect, test } from '@playwright/test';
import { ElectronAppManager } from '../electron-app-manager';
import {
EXPECTED_DETAILS_BY_PAGE,
IPC_MAIN_HANDLE_MOCKS,
PROJECT_NEW,
PROJECT_OFFICE_HVAC
} from '../mocks';
import { EXPECTED_DETAILS_BY_PAGE, IPC_MAIN_HANDLE_MOCKS, PROJECT_NEW, PROJECT_OFFICE_HVAC } from '../mocks';
import {
NavPageObject,
NewProjectModalPageObject,
Expand All @@ -19,9 +14,7 @@ const selectProjPO = new SelectProjectModalPageObject();
const navPO = new NavPageObject();
const noServerStartToastPO = new NoServerStartToastPageObject();

const testNoServerStartToast = (
noServerStartToastPO: NoServerStartToastPageObject
) =>
const testNoServerStartToast = (noServerStartToastPO: NoServerStartToastPageObject) =>
test('"Server no longer starts by default" toast is shown', async () => {
await noServerStartToastPO.isOk();
});
Expand All @@ -45,9 +38,7 @@ test('correct title and buttons are shown', async () => {
test.describe('click "Make New Project" button', () => {
const newProjPO = new NewProjectModalPageObject();
test.beforeEach(async () => {
await selectProjPO.clickButton(
selectProjPO.EXPECTED_BUTTONS.MAKE_NEW_PROJECT
);
await selectProjPO.clickButton(selectProjPO.EXPECTED_BUTTONS.MAKE_NEW_PROJECT);
});

test.describe('"New Project" modal', () => {
Expand Down Expand Up @@ -103,12 +94,7 @@ test.describe('click "Open Existing Project" button', () => {
...EXPECTED_DETAILS_BY_PAGE.ANALYSIS,
title: PROJECT_OFFICE_HVAC.name
});
test.beforeEach(
async () =>
await selectProjPO.open(
IPC_MAIN_HANDLE_MOCKS.showOpenDialog.validOfficeHVAC
)
);
test.beforeEach(async () => await selectProjPO.open(IPC_MAIN_HANDLE_MOCKS.showOpenDialog.validOfficeHVAC));

test('modal closes', async () => {
await selectProjPO.dialog.waitFor({ state: 'hidden' });
Expand All @@ -119,10 +105,7 @@ test.describe('click "Open Existing Project" button', () => {
});

test('select invalid directory and modal remains open', async () => {
await selectProjPO.open(
IPC_MAIN_HANDLE_MOCKS.showOpenDialog.invalid,
IPC_MAIN_HANDLE_MOCKS.showMessageBox.ok
);
await selectProjPO.open(IPC_MAIN_HANDLE_MOCKS.showOpenDialog.invalid, IPC_MAIN_HANDLE_MOCKS.showMessageBox.ok);
await selectProjPO.isOk();
});
test('cancel dialog and modal remains open', async () => {
Expand Down

0 comments on commit cca398c

Please sign in to comment.