From 1a15f35c4550f2ed67a2df019943ad37b7731f33 Mon Sep 17 00:00:00 2001 From: mdlufy Date: Tue, 22 Oct 2024 19:29:49 +0300 Subject: [PATCH 1/4] fix(kit): `InputDate` click any day after `Until today` selected --- .../tests/kit/input-date/input-date.spec.ts | 39 +++++++++++++++++++ .../utils/page-objects/index.ts | 1 + .../utils/page-objects/input-date.po.ts | 25 ++++++++++++ .../input-date/input-date.component.ts | 10 ++++- .../input-date/input-date.template.html | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 projects/demo-playwright/tests/kit/input-date/input-date.spec.ts create mode 100644 projects/demo-playwright/utils/page-objects/input-date.po.ts diff --git a/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts b/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts new file mode 100644 index 000000000000..658d071951ab --- /dev/null +++ b/projects/demo-playwright/tests/kit/input-date/input-date.spec.ts @@ -0,0 +1,39 @@ +import {TuiDocumentationPagePO, tuiGoto} from '@demo-playwright/utils'; +import type {Locator} from '@playwright/test'; +import {expect, test} from '@playwright/test'; + +import {TuiInputDatePO} from '../../../utils'; + +test.describe('InputDate', () => { + test.describe('API', () => { + let example: Locator; + let inputDate!: TuiInputDatePO; + let documentationPage: TuiDocumentationPagePO; + + test.use({ + viewport: { + width: 600, + height: 800, + }, + }); + + test.beforeEach(({page}) => { + documentationPage = new TuiDocumentationPagePO(page); + example = documentationPage.apiPageExample; + + inputDate = new TuiInputDatePO(example.locator('tui-input-date')); + }); + + 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.clickItemButton(); + + await inputDate.textfield.click(); + await inputDate.clickOnCalendarDay(1); + + await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png'); + }); + }); +}); diff --git a/projects/demo-playwright/utils/page-objects/index.ts b/projects/demo-playwright/utils/page-objects/index.ts index 4924e3a6a281..6ebc2eb3ffc8 100644 --- a/projects/demo-playwright/utils/page-objects/index.ts +++ b/projects/demo-playwright/utils/page-objects/index.ts @@ -3,6 +3,7 @@ export * from './calendar-range.po'; export * from './documentation-page.po'; export * from './input-card.po'; export * from './input-card-grouped.po'; +export * from './input-date.po'; export * from './input-date-range.po'; export * from './input-date-time.po'; export * from './input-month.po'; diff --git a/projects/demo-playwright/utils/page-objects/input-date.po.ts b/projects/demo-playwright/utils/page-objects/input-date.po.ts new file mode 100644 index 000000000000..d1b1fb82c307 --- /dev/null +++ b/projects/demo-playwright/utils/page-objects/input-date.po.ts @@ -0,0 +1,25 @@ +import {Locator} from '@playwright/test'; + +import {TuiCalendarPO} from './calendar.po'; + +export class TuiInputDatePO { + readonly textfield: Locator = this.host.locator( + '[automation-id="tui-primitive-textfield__native-input"]', + ); + + constructor(private readonly host: Locator) {} + + async clickItemButton(): Promise { + const itemButton = this.host + .page() + .locator('[automation-id="tui-input-date__button"]'); + + await itemButton.click(); + } + + async clickOnCalendarDay(day: number): Promise { + const calendar = new TuiCalendarPO(this.host.page().locator('tui-calendar')); + + await calendar.clickOnCalendarDay(day); + } +} diff --git a/projects/kit/components/input-date/input-date.component.ts b/projects/kit/components/input-date/input-date.component.ts index e9ad3b30b548..fe106b1a19a4 100644 --- a/projects/kit/components/input-date/input-date.component.ts +++ b/projects/kit/components/input-date/input-date.component.ts @@ -210,7 +210,15 @@ export class TuiInputDateComponent } get computedMask(): MaskitoOptions { - return this.activeItem + /** + * TODO: we can delete this workaround in v4.0 + * after solving this issue: + * https://github.com/taiga-family/maskito/issues/604 + */ + const nativeValueIsNotSynced = + this.textfield?.nativeFocusableElement?.value !== this.computedValue; + + return this.activeItem || nativeValueIsNotSynced ? MASKITO_DEFAULT_OPTIONS : this.computeMaskOptions( this.dateFormat, diff --git a/projects/kit/components/input-date/input-date.template.html b/projects/kit/components/input-date/input-date.template.html index 828ff01c0c38..8d1ceb2831b6 100644 --- a/projects/kit/components/input-date/input-date.template.html +++ b/projects/kit/components/input-date/input-date.template.html @@ -71,6 +71,7 @@ class="t-button" >