Skip to content

Commit

Permalink
feat(kit): add snapshot tests to TuiCalendarRange with range changer
Browse files Browse the repository at this point in the history
  • Loading branch information
zhd-dm committed Aug 20, 2024
1 parent 1a1a4e1 commit 8f0503d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {DemoRoute} from '@demo/routes';
import {
TuiCalendarRangePO,
TuiDocumentationPagePO,
tuiGoto,
} from '@demo-playwright/utils';
import {expect, type Locator, test} from '@playwright/test';

test.describe('CalendarRange', () => {
let example!: Locator;
let calendarRange!: TuiCalendarRangePO;
let documentationPage!: TuiDocumentationPagePO;

test.beforeEach(async ({page}) => {
await tuiGoto(page, DemoRoute.CalendarRange, {date: new Date(2024, 9, 31)});

documentationPage = new TuiDocumentationPagePO(page);
example = documentationPage.getExample('#with-another-range-switcher');
calendarRange = new TuiCalendarRangePO(example.locator('tui-calendar-range'));
});

test.describe('Examples', () => {
test('With another range switcher', async () => {
const getRangeSwitcher = (): Locator =>
example.locator('p button[data-appearance="link"]');

await expect(example).toHaveScreenshot(

Check failure on line 27 in projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher Error: Screenshot comparison failed: Timeout 5000ms exceeded. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/calendar-range/calendar-range.spec.ts-snapshots/05-calendar-range-correct-display-defaults-items-and-values-chromium-linux.png Call log: - expect.toHaveScreenshot(05-calendar-range-correct-display-defaults-items-and-values.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#with-another-range-switcher [automation-id="tui-doc-example"]') - Timeout 5000ms exceeded. 25 | example.locator('p button[data-appearance="link"]'); 26 | > 27 | await expect(example).toHaveScreenshot( | ^ 28 | '05-calendar-range-correct-display-defaults-items-and-values.png', 29 | ); 30 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:27:35

Check failure on line 27 in projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: Timeout 5000ms exceeded. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/calendar-range/calendar-range.spec.ts-snapshots/05-calendar-range-correct-display-defaults-items-and-values-chromium-linux.png Call log: - expect.toHaveScreenshot(05-calendar-range-correct-display-defaults-items-and-values.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#with-another-range-switcher [automation-id="tui-doc-example"]') - Timeout 5000ms exceeded. 25 | example.locator('p button[data-appearance="link"]'); 26 | > 27 | await expect(example).toHaveScreenshot( | ^ 28 | '05-calendar-range-correct-display-defaults-items-and-values.png', 29 | ); 30 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:27:35

Check failure on line 27 in projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:23:13 › CalendarRange › Examples › With another range switcher Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: Timeout 5000ms exceeded. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/calendar-range/calendar-range.spec.ts-snapshots/05-calendar-range-correct-display-defaults-items-and-values-chromium-linux.png Call log: - expect.toHaveScreenshot(05-calendar-range-correct-display-defaults-items-and-values.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#with-another-range-switcher [automation-id="tui-doc-example"]') - Timeout 5000ms exceeded. 25 | example.locator('p button[data-appearance="link"]'); 26 | > 27 | await expect(example).toHaveScreenshot( | ^ 28 | '05-calendar-range-correct-display-defaults-items-and-values.png', 29 | ); 30 | at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:27:35
'05-calendar-range-correct-display-defaults-items-and-values.png',
);

await calendarRange.selectItem(1);
await calendarRange.itemHasCheckmark(1);

await expect(example).toHaveScreenshot(
'05-calendar-range-correct-display-range-switcher-after-select-week.png',
);

getRangeSwitcher().click();

await expect(example).toHaveScreenshot(
'05-calendar-range-correct-display-items-and-values-after-click-on-month-range-switcher.png',
);

getRangeSwitcher().click();

await expect(example).toHaveScreenshot(
'05-calendar-range-correct-display-items-and-values-after-click-on-quarter-range-switcher.png',
);

getRangeSwitcher().click();

await expect(example).toHaveScreenshot(
'05-calendar-range-correct-display-defaults-items-and-values.png',
);
});
});
});
29 changes: 29 additions & 0 deletions projects/demo-playwright/utils/page-objects/calendar-range.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {expect, type Locator} from '@playwright/test';

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

public async getItems(): Promise<Locator[]> {
const dataList = this.host.locator('[automation-id="tui-calendar-range__menu"]');

await expect(dataList).toBeAttached();

return dataList.locator('[tuiOption]').all();
}

public async selectItem(index: number): Promise<void> {
const items = await this.getItems();

await items[index].click();
}

public async itemHasCheckmark(index: number): Promise<boolean> {
const items = await this.getItems();

const itemCheckmark = await items[index]
.locator('[automation-id="tui-calendar-range__checkmark"]')
.count();

return !!itemCheckmark;
}
}
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,4 +1,5 @@
export * from './calendar.po';
export * from './calendar-range.po';
export * from './combo-box.po';
export * from './documentation-api-page.po';
export * from './documentation-page.po';
Expand Down

0 comments on commit 8f0503d

Please sign in to comment.