Skip to content

Commit

Permalink
fix(kit): InputDate click any day after Until today selected (#9582)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy authored Oct 24, 2024
2 parents 81ed55c + 6a08b9a commit 6d8a4df
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 13 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
46 changes: 46 additions & 0 deletions projects/demo-playwright/tests/kit/input-date/input-date.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {TuiDocumentationPagePO, tuiGoto} from '@demo-playwright/utils';
import type {Locator} from '@playwright/test';
import {expect, test} from '@playwright/test';

import {TuiCalendarPO, TuiInputDatePO} from '../../../utils';

test.describe('InputDate', () => {
test.describe('API', () => {
let documentationPage: TuiDocumentationPagePO;
let example: Locator;

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

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'));

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 calendar.itemButton.click();

await inputDate.textfield.click();

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

await calendarSheet?.clickOnDay(1);

await expect(inputDate.textfield).toHaveScreenshot('01-input-date.png');
});
});
});
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));
}
}
2 changes: 2 additions & 0 deletions projects/demo-playwright/utils/page-objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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';
export * from './input-date.po';
export * from './input-date-range.po';
export * from './input-date-time.po';
export * from './input-month.po';
Expand Down
8 changes: 8 additions & 0 deletions projects/demo-playwright/utils/page-objects/input-date.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Locator} from '@playwright/test';

export class TuiInputDatePO {
readonly textfield: Locator = this.host.getByRole('textbox');
readonly calendar: Locator = this.host.page().locator('tui-calendar');

constructor(private readonly host: Locator) {}
}
10 changes: 9 additions & 1 deletion projects/kit/components/input-date/input-date.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6d8a4df

Please sign in to comment.