Skip to content

Commit

Permalink
fix(kit): CalendarRange shows last available month when max and ite…
Browse files Browse the repository at this point in the history
…ms set
  • Loading branch information
mdlufy committed Sep 24, 2024
1 parent 9741bfc commit 6d3665a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ test.describe('CalendarRange', () => {
let calendarRange!: TuiCalendarRangePO;
let documentationPage!: TuiDocumentationPagePO;

test.use({
viewport: {width: 650, height: 650},
});

test.beforeEach(async ({page}) => {
await tuiGoto(page, DemoRoute.CalendarRange, {
date: new Date(2020, 8, 25),
});

documentationPage = new TuiDocumentationPagePO(page);
example = documentationPage.apiPageExample;

calendarRange = new TuiCalendarRangePO(example.locator('tui-calendar-range'));
});

test.describe('Examples', () => {
Expand Down Expand Up @@ -57,4 +64,12 @@ test.describe('CalendarRange', () => {
);
});
});

test.describe('API', () => {
test('Maximum month when items not empty', async ({page}) => {
await tuiGoto(page, `${DemoRoute.CalendarRange}/API?items$=1&max$=4`);

await expect(example).toHaveScreenshot('06-maximum-month-with-items.png');

Check failure on line 72 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:69:13 › CalendarRange › API › Maximum month when items not empty

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:69:13 › CalendarRange › API › Maximum month when items not empty Error: Screenshot comparison failed: 7629 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/06-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium/06-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium/06-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. 70 | await tuiGoto(page, `${DemoRoute.CalendarRange}/API?items$=1&max$=4`); 71 | > 72 | await expect(example).toHaveScreenshot('06-maximum-month-with-items.png'); | ^ 73 | }); 74 | }); 75 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:72:35

Check failure on line 72 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:69:13 › CalendarRange › API › Maximum month when items not empty

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:69:13 › CalendarRange › API › Maximum month when items not empty Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 7629 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/06-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium-retry1/06-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium-retry1/06-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. 70 | await tuiGoto(page, `${DemoRoute.CalendarRange}/API?items$=1&max$=4`); 71 | > 72 | await expect(example).toHaveScreenshot('06-maximum-month-with-items.png'); | ^ 73 | }); 74 | }); 75 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:72:35

Check failure on line 72 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:69:13 › CalendarRange › API › Maximum month when items not empty

1) [chromium] › tests/kit/calendar-range/calendar-range.spec.ts:69:13 › CalendarRange › API › Maximum month when items not empty Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 7629 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/06-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium-retry2/06-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-calendar-range-c-dc325--month-when-items-not-empty-chromium-retry2/06-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('#demo-content') - locator resolved to <div id="demo-content" _ngcontent-ng-c3888982576="">…</div> - 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 - 7629 pixels (ratio 0.01 of all image pixels) are different. 70 | await tuiGoto(page, `${DemoRoute.CalendarRange}/API?items$=1&max$=4`); 71 | > 72 | await expect(example).toHaveScreenshot('06-maximum-month-with-items.png'); | ^ 73 | }); 74 | }); 75 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/calendar-range/calendar-range.spec.ts:72:35
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ test.describe('InputDateRange', () => {
});
});

test('Maximum month when items not empty', async ({page}) => {
await tuiGoto(page, `${DemoRoute.InputDateRange}/API?items$=1&max$=7`);
await inputDateRange.textfield.click();

await expect(inputDateRange.textfield).toHaveScreenshot(
'06-textfield-maximum-month-with-items.png',
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(

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

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty

2) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty Error: Screenshot comparison failed: 7657 pixels (ratio 0.02 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/input-date-range/input-date-range.spec.ts-snapshots/06-calendar-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium/06-calendar-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium/06-calendar-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-calendar-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. 105 | '06-textfield-maximum-month-with-items.png', 106 | ); > 107 | await expect(inputDateRange.calendarRange).toHaveScreenshot( | ^ 108 | '06-calendar-maximum-month-with-items.png', 109 | ); 110 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:107:56

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

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty

2) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 7657 pixels (ratio 0.02 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/input-date-range/input-date-range.spec.ts-snapshots/06-calendar-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium-retry1/06-calendar-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium-retry1/06-calendar-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-calendar-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. 105 | '06-textfield-maximum-month-with-items.png', 106 | ); > 107 | await expect(inputDateRange.calendarRange).toHaveScreenshot( | ^ 108 | '06-calendar-maximum-month-with-items.png', 109 | ); 110 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:107:56

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

View workflow job for this annotation

GitHub Actions / playwright / (6 of 9)

[chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty

2) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:100:13 › InputDateRange › API › Maximum month when items not empty Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Screenshot comparison failed: 7657 pixels (ratio 0.02 of all image pixels) are different. Expected: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/snapshots/tests/kit/input-date-range/input-date-range.spec.ts-snapshots/06-calendar-maximum-month-with-items-chromium-linux.png Received: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium-retry2/06-calendar-maximum-month-with-items-actual.png Diff: /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests-results/tests-kit-input-date-range-be903--month-when-items-not-empty-chromium-retry2/06-calendar-maximum-month-with-items-diff.png Call log: - expect.toHaveScreenshot(06-calendar-maximum-month-with-items.png) with timeout 5000ms - verifying given screenshot expectation - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. - waiting 100ms before taking screenshot - waiting for locator('tui-calendar-range') - locator resolved to <tui-calendar-range _nghost-ng-c759019108="" class="ng-star-inserted" _ngcontent-ng-c1708677694="">…</tui-calendar-range> - 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 - 7657 pixels (ratio 0.02 of all image pixels) are different. 105 | '06-textfield-maximum-month-with-items.png', 106 | ); > 107 | await expect(inputDateRange.calendarRange).toHaveScreenshot( | ^ 108 | '06-calendar-maximum-month-with-items.png', 109 | ); 110 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:107:56
'06-calendar-maximum-month-with-items.png',
);
});

test.describe('prevents changes if you enter an invalid date', () => {
test('day > 31', async ({page}) => {
await tuiGoto(page, `${DemoRoute.InputDateRange}/API`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export class TuiCalendarRange implements OnInit, OnChanges {
if (this.value) {
this.defaultViewedMonth = this.items.length ? this.value.to : this.value.from;
} else if (this.max && this.defaultViewedMonth.monthSameOrAfter(this.max)) {
this.defaultViewedMonth = this.max.append({month: -1});
this.defaultViewedMonth = this.items.length
? this.max
: this.max.append({month: -1});
} else if (this.min && this.defaultViewedMonth.monthSameOrBefore(this.min)) {
this.defaultViewedMonth = this.min;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ describe('rangeCalendarComponent', () => {
expect(component.defaultViewedMonth).toEqual(minDate);
});

it('when max and items not empty, defaultViewedMonth is max', () => {
const maxDate = TuiDay.currentLocal();

testComponent.max = maxDate;
fixture.detectChanges();

component.ngOnInit();
fixture.detectChanges();

expect(component.defaultViewedMonth).toEqual(maxDate);
});

it('isItemActive returns true when value is set to today after being changed to yesterday', () => {
const today = TuiDay.currentLocal();
const yesterday = today.append({day: -1});
Expand Down

0 comments on commit 6d3665a

Please sign in to comment.