Skip to content

Commit

Permalink
chore(demo-playwright): CalendarSheet add
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy committed Oct 24, 2024
1 parent f638ff6 commit 6a08b9a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ test.describe('InputDateRange', () => {
await expect(inputDateRange.textfield).toHaveValue('Today');

await inputDateRange.textfield.click();
await calendar.clickOnCalendarDay(21);

const [calendarSheet] = await calendar.getCalendarSheets();

await calendarSheet?.clickOnDay(21);

await expect(inputDateRange.textfield).toHaveValue(
`21.09.2020${CHAR_NO_BREAK_SPACE}${CHAR_NO_BREAK_SPACE}25.09.2020`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test.describe('InputDate', () => {
test.describe('API', () => {
let documentationPage: TuiDocumentationPagePO;
let example: Locator;

let inputDate!: TuiInputDatePO;
let calendar!: TuiCalendarPO;

Expand All @@ -23,17 +24,21 @@ test.describe('InputDate', () => {
example = documentationPage.apiPageExample;

inputDate = new TuiInputDatePO(example.locator('tui-input-date'));

calendar = new TuiCalendarPO(inputDate.calendar);
});

test('Click any day after `Until today` was selected', async ({page}) => {
await tuiGoto(page, 'components/input-date/API?items$=1');

await inputDate.textfield.click();
await inputDate.itemButton.click();
await calendar.itemButton.click();

await inputDate.textfield.click();
await calendar.clickOnCalendarDay(1);

const [calendarSheet] = await calendar.getCalendarSheets();

await calendarSheet?.clickOnDay(1);

await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png');

Check failure on line 43 in projects/demo-playwright/tests/kit/input-date/input-date.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date/input-date.spec.ts:31:13 › InputDate › API › Click any day after `Until today` was selected

1) [chromium] › tests/kit/input-date/input-date.spec.ts:31:13 › InputDate › API › Click any day after `Until today` was selected Error: Screenshot comparison failed: 498 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/input-date/input-date.spec.ts-snapshots/01-input-date-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-input-346f6-er-Until-today-was-selected-chromium/01-input-date-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-input-346f6-er-Until-today-was-selected-chromium/01-input-date-diff.png Call log: - expect.toHaveScreenshot(01-input-date.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - taking element screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable - 498 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - taking element screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable - captured a stable screenshot - 498 pixels (ratio 0.01 of all image pixels) are different. 41 | await calendarSheet?.clickOnDay(1); 42 | > 43 | await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png'); | ^ 44 | }); 45 | }); 46 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts:43:47

Check failure on line 43 in projects/demo-playwright/tests/kit/input-date/input-date.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (3 of 4)

[chromium] › tests/kit/input-date/input-date.spec.ts:31:13 › InputDate › API › Click any day after `Until today` was selected

1) [chromium] › tests/kit/input-date/input-date.spec.ts:31:13 › InputDate › API › Click any day after `Until today` was selected Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 498 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/input-date/input-date.spec.ts-snapshots/01-input-date-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-input-346f6-er-Until-today-was-selected-chromium-retry1/01-input-date-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-input-346f6-er-Until-today-was-selected-chromium-retry1/01-input-date-diff.png Call log: - expect.toHaveScreenshot(01-input-date.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - taking element screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable - 498 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('#demo-content').locator('tui-input-date').getByRole('textbox') - locator resolved to <input tabindex="0" tuimaskaccessor="" aria-invalid="false" _ngcontent-tui-demo-c171="" id="tui_interactive_561601061540000" class="t-input ng-untouched ng-valid ng-dirty" automation-id="tui-primitive-textfield__native-input"/> - taking element screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable - captured a stable screenshot - 498 pixels (ratio 0.01 of all image pixels) are different. 41 | await calendarSheet?.clickOnDay(1); 42 | > 43 | await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png'); | ^ 44 | }); 45 | }); 46 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts:43:47
});
Expand Down
25 changes: 25 additions & 0 deletions projects/demo-playwright/utils/page-objects/calendar-sheet.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {Locator} from '@playwright/test';

export class TuiCalendarSheetPO {
constructor(private readonly host: Locator) {}

async getDays(): Promise<Locator[]> {
return this.host
.locator(
'[automation-id="tui-primitive-calendar__cell"], [automation-id="tui-primitive-calendar-mobile__cell"]',
)
.all();
}

async clickOnDay(day: number): Promise<void> {
const cells = await this.getDays();

for (const cell of cells) {
if ((await cell.textContent())?.trim() === day.toString()) {
await cell.click();

break;
}
}
}
}
23 changes: 12 additions & 11 deletions projects/demo-playwright/utils/page-objects/calendar.po.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {Locator} from '@playwright/test';

import {TuiCalendarSheetPO} from './calendar-sheet.po';

export class TuiCalendarPO {
constructor(private readonly host: Locator) {}
readonly itemButton: Locator = this.host
.page()
.locator('tui-dropdown tui-calendar ~ * button');

async getDays(): Promise<Locator[]> {
return this.host.locator('[automation-id="tui-primitive-calendar__cell"]').all();
}
constructor(private readonly host: Locator) {}

async clickOnCalendarDay(day: number): Promise<void> {
const cells = await this.getDays();
async getCalendarSheets(): Promise<TuiCalendarSheetPO[]> {
const locators = await this.host
.page()
.locator('tui-primitive-calendar, tui-primitive-calendar-mobile')
.all();

for (const cell of cells) {
if ((await cell.textContent())?.trim() === day.toString()) {
return cell.click();
}
}
return locators.map(x => new TuiCalendarSheetPO(x));
}
}
1 change: 1 addition & 0 deletions projects/demo-playwright/utils/page-objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './calendar.po';
export * from './calendar-range.po';
export * from './calendar-sheet.po';
export * from './documentation-page.po';
export * from './input-card.po';
export * from './input-card-grouped.po';
Expand Down
3 changes: 0 additions & 3 deletions projects/demo-playwright/utils/page-objects/input-date.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import {Locator} from '@playwright/test';
export class TuiInputDatePO {
readonly textfield: Locator = this.host.getByRole('textbox');
readonly calendar: Locator = this.host.page().locator('tui-calendar');
readonly itemButton: Locator = this.host
.page()
.locator('tui-dropdown tui-calendar ~ * button');

constructor(private readonly host: Locator) {}
}

0 comments on commit 6a08b9a

Please sign in to comment.