Skip to content

Commit d9202d9

Browse files
authored
[Playwright] PEPPER-1125 New tissue request test (#2235)
* playwright tissue request test
1 parent b7c17b1 commit d9202d9

31 files changed

+1539
-26
lines changed

playwright-e2e/dsm/component/date-picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class DatePicker {
7676
await this.monthPicker().locator(this.clickableCell(), { hasText: monthName }).click();
7777

7878
// pick day of month
79-
await this.dayPicker().locator(this.clickableCell(), { hasText: date }).click();
79+
await this.dayPicker().locator(this.clickableCell(), { hasText: date }).first().click();
8080

8181
// calendar close automatically
8282
return getDate(new Date(yyyy, month, parseInt(date)));

playwright-e2e/dsm/component/filters/sections/search/search.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class Search {
3333
public async dates(columnName: string, { from: fromValue, to: toValue, additionalFilters }: Partial<DateConfig>): Promise<void> {
3434
await this.setAdditionalFilters(columnName, additionalFilters);
3535

36+
if (!fromValue && !toValue) {
37+
return;
38+
}
39+
3640
let fromDate!: string;
3741
let toDate!: string;
3842

playwright-e2e/dsm/component/modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class Modal {
88
private readonly rootSelector: Locator;
99

1010
constructor(private readonly page: Page) {
11-
this.rootSelector = this.page.locator('.modal-dialog');
11+
this.rootSelector = this.page.locator('app-modal, .modal-dialog');
1212
}
1313

1414
public toLocator(): Locator {

playwright-e2e/dsm/component/smid.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { expect, Locator, Page } from '@playwright/test';
2+
import Input from 'dss/component/input';
3+
import { waitForResponse } from 'utils/test-utils';
4+
import Modal from './modal';
5+
6+
interface InputData {
7+
value: string;
8+
selectCheckbox?: boolean;
9+
}
10+
11+
export default class SMID {
12+
private readonly modalComponent: Modal;
13+
14+
constructor(private readonly page: Page, private readonly tissueIndex: number) {
15+
this.modalComponent = new Modal(this.page);
16+
}
17+
18+
public async getValueAt(index: number): Promise<string> {
19+
const input = await this.getInputAt(index);
20+
return input.currentValue();
21+
}
22+
23+
public async fillInputs(inputData: (InputData | string)[]): Promise<void> {
24+
for (let i = 0; i < inputData.length; i++) {
25+
const field = inputData[i];
26+
const value = typeof field === 'object' ? field.value : field;
27+
const selectCheckbox = typeof field === 'object' ? field.selectCheckbox : false;
28+
29+
const isInputVisible = await this.isInputVisible(i);
30+
if (!isInputVisible) {
31+
await this.addField();
32+
}
33+
await this.fillField(value, i);
34+
selectCheckbox && await this.selectCheckbox(i);
35+
}
36+
}
37+
38+
public async deleteInputAt(index: number): Promise<void> {
39+
const deleteBtnLocator = this.fields.nth(index).locator('//td/button');
40+
await expect(deleteBtnLocator, `Delete button is not visible at index ${index}`).toBeVisible();
41+
42+
await deleteBtnLocator.click();
43+
}
44+
45+
public async close(): Promise<void> {
46+
await this.clickModalBtn('close');
47+
}
48+
49+
public async onlyKeepSelectedSMIDs(): Promise<void> {
50+
await this.clickModalBtn('Only keep selected SM-IDs');
51+
await waitForResponse(this.page, { uri: 'patch' });
52+
}
53+
54+
/* Helper Functions */
55+
private async isInputVisible(index: number): Promise<boolean> {
56+
return this.fields.nth(index).isVisible();
57+
}
58+
59+
private async addField(): Promise<void> {
60+
await this.addBtn.click();
61+
}
62+
63+
private async fillField(value: string, index: number): Promise<void> {
64+
const fieldInput = await this.getInputAt(index);
65+
const currentValue = await fieldInput.currentValue();
66+
if (currentValue.trim() !== value) {
67+
await fieldInput.fillSimple(value);
68+
await waitForResponse(this.page, { uri: 'patch' });
69+
}
70+
}
71+
72+
private async selectCheckbox(index: number): Promise<void> {
73+
const checkboxLocator = this.fields.nth(index).locator('//td/mat-checkbox');
74+
await expect(checkboxLocator, `Checkbox is not visible at index ${index}`).toBeVisible();
75+
await checkboxLocator.click();
76+
}
77+
78+
private async getInputAt(index: number): Promise<Input> {
79+
const fieldLocator = this.fields.nth(index).locator('//td/md-input-container');
80+
await expect(fieldLocator, `Input field is not visible at index ${index}`).toBeVisible();
81+
return new Input(this.page, { root: fieldLocator });
82+
}
83+
84+
private async clickModalBtn(label: 'Only keep selected SM-IDs' | 'close'): Promise<void> {
85+
await this.modalComponent.getButton({ label }).click();
86+
}
87+
88+
89+
/* Locators */
90+
private get modalBody(): Locator {
91+
return this.modalComponent.bodyLocator();
92+
}
93+
94+
private get modal(): Locator {
95+
return this.page.locator(`(//app-tissue)[${this.tissueIndex + 1}]/app-modal`);
96+
}
97+
98+
private get fields(): Locator {
99+
return this.modalBody.locator('//table/tr[td[md-input-container]]');
100+
}
101+
102+
private get addBtn(): Locator {
103+
return this.modalBody.locator(`//div[@class='app-modal-body']/button`);
104+
}
105+
}

0 commit comments

Comments
 (0)