Skip to content

Commit

Permalink
fix(kit): fix CalendarRange switch month with maxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy committed Aug 4, 2024
1 parent 864e50e commit 07a99ce
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
TuiCalendarRangePO,
TuiDocumentationPagePO,
tuiGoto,
} from '@demo-playwright/utils';
import {expect, Locator, test} from '@playwright/test';

const {describe, beforeEach} = test;

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

beforeEach(({page}) => {
documentationPage = new TuiDocumentationPagePO(page);
example = documentationPage.apiPageExample;
calendarRange = new TuiCalendarRangePO(example.locator('tui-calendar-range'));
});

test('When click on right calendar, months not switch', async ({page}) => {
await tuiGoto(page, 'components/calendar-range/API?maxLength$=0');
await calendarRange.clickRightCalendar();

await documentationPage.prepareApiPageBeforeScreenshot();
await expect(page).toHaveScreenshot('calendar-range-max-length-click.png');

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 / (3 of 4)

[chromium] › tests/kit/calendar-range/calendar-range.spec.ts:22:13 › CalendarRange › API › When click on right calendar

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:22:13 › CalendarRange › API › When click on right calendar, months not switch Error: Screenshot comparison failed: 9127 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/calendar-range/calendar-range.spec.ts-snapshots/calendar-range-max-length-click-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-calendar-range-Calend-2c1f8--When-click-on-right-calendar-months-not-switch-chromium/calendar-range-max-length-click-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-calendar-range-Calend-2c1f8--When-click-on-right-calendar-months-not-switch-chromium/calendar-range-max-length-click-diff.png Call log: - page._expectScreenshot with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - 9127 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - disabled all CSS animations - captured a stable screenshot - 9127 pixels (ratio 0.01 of all image pixels) are different. 25 | 26 | await documentationPage.prepareApiPageBeforeScreenshot(); > 27 | await expect(page).toHaveScreenshot('calendar-range-max-length-click.png'); | ^ 28 | }); 29 | }); 30 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:27:32

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 / (3 of 4)

[chromium] › tests/kit/calendar-range/calendar-range.spec.ts:22:13 › CalendarRange › API › When click on right calendar

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:22:13 › CalendarRange › API › When click on right calendar, months not switch Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 9127 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/calendar-range/calendar-range.spec.ts-snapshots/calendar-range-max-length-click-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-calendar-range-Calend-2c1f8--When-click-on-right-calendar-months-not-switch-chromium-retry1/calendar-range-max-length-click-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-calendar-range-Calend-2c1f8--When-click-on-right-calendar-months-not-switch-chromium-retry1/calendar-range-max-length-click-diff.png Call log: - page._expectScreenshot with timeout 5000ms - verifying given screenshot expectation - taking page screenshot - disabled all CSS animations - 9127 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - taking page screenshot - disabled all CSS animations - captured a stable screenshot - 9127 pixels (ratio 0.01 of all image pixels) are different. 25 | 26 | await documentationPage.prepareApiPageBeforeScreenshot(); > 27 | await expect(page).toHaveScreenshot('calendar-range-max-length-click.png'); | ^ 28 | }); 29 | }); 30 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:27:32
});
});
});
12 changes: 12 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,12 @@
import {Locator} from '@playwright/test';

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

async clickRightCalendar(): Promise<void> {
return this.host
.locator('[automation-id="tui-calendar__calendar"]')
.last()
.click();
}
}
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 './documentation-page.po';
export * from './input-card.po';
export * from './input-card-grouped.po';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class TuiPrimitiveCalendarRangeComponent implements OnInit {
return this.max;
}

if (month.monthBefore(this.min)) {
if (month.monthSameOrBefore(this.min)) {
return this.min.append({month: 1});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[max]="max"
[min]="min"
[minViewedMonth]="cappedUserViewedMonthFirst | tuiMapper: monthOffset : 1"
[month]="userViewedMonthSecond.monthSameOrBefore(min) ? (min | tuiMapper: monthOffset : 1) : userViewedMonthSecond"
[month]="userViewedMonthSecond"
[showAdjacent]="false"
[value]="value"
[(hoveredItem)]="hoveredItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ describe('PrimitiveRangeCalendar component', () => {
component.ngOnInit();
expect(component.userViewedMonthSecond).toEqual(minDate.append({month: 1}));
});

it('When min later than given month, return next month after min', () => {
const minDate = TuiDay.currentLocal().append({month: 1});

component.min = minDate;
component.ngOnInit();

expect(component.userViewedMonthSecond).toEqual(minDate.append({month: 1}));
});
});

describe('cappedUserViewedMonthSecond', () => {
Expand Down

0 comments on commit 07a99ce

Please sign in to comment.