Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addon-mobile): InputDateRange throws error on single date selection #9411

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ export class TuiMobileCalendarDropdown {
}

protected confirm(value: any): void {
const normalizedValue = this.range ? this.selectedPeriod : value;

if (this.control) {
this.control.value = value;
this.control.value = normalizedValue;
}

this.observer?.next(value);
this.observer?.next(normalizedValue);
this.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@
import type {Locator} from '@playwright/test';
import {expect, test} from '@playwright/test';

import {
TUI_PLAYWRIGHT_MOBILE_USER_AGENT,
TUI_PLAYWRIGHT_MOBILE_VIEWPORT_HEIGHT,
TUI_PLAYWRIGHT_MOBILE_VIEWPORT_WIDTH,
} from '../../../playwright.options';
import {
CHAR_NO_BREAK_SPACE,
TuiCalendarPO,
TuiCalendarSheetPO,
TuiDocumentationPagePO,
tuiGoto,
TuiInputDateRangePO,
TuiMobileCalendarPO,
} from '../../../utils';

test.describe('InputDateRange', () => {
let example!: Locator;
let inputDateRange!: TuiInputDateRangePO;
let documentationPage!: TuiDocumentationPagePO;

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

test.beforeEach(async ({page}) => {
await tuiGoto(page, DemoRoute.InputDateRange);

test.beforeEach(({page}) => {
documentationPage = new TuiDocumentationPagePO(page);
example = documentationPage.apiPageExample;

inputDateRange = new TuiInputDateRangePO(example.locator('tui-input-date-range'));
});

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

test.beforeEach(() => {
example = documentationPage.apiPageExample;
inputDateRange = new TuiInputDateRangePO(
example.locator('tui-input-date-range'),
);
});

['s', 'm', 'l'].forEach((size) => {
test(`correct filler display for size ${size.toUpperCase()}`, async ({
page,
Expand All @@ -43,7 +52,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
`01-textfield-size-${size}-empty.png`,
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
`01-calendar-size-${size}-empty.png`,
);

Expand All @@ -52,7 +61,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
`02-textfield-size-${size}-set-day.png`,
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
`02-calendar-size-${size}-set-day.png`,
);

Expand All @@ -61,7 +70,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
`03-textfield-size-${size}-set-from-date.png`,
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
`03-calendar-size-${size}-set-from-date.png`,
);

Expand All @@ -70,7 +79,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
`04-textfield-size-${size}-set-to-date.png`,
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
`04-calendar-size-${size}-set-to-date.png`,
);
});
Expand All @@ -83,7 +92,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
'05-textfield-maximum-month.png',
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
'05-calendar-maximum-month.png',
);
});
Expand All @@ -104,7 +113,7 @@
await expect(inputDateRange.textfield).toHaveScreenshot(
'06-textfield-maximum-month-with-items.png',
);
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
'06-calendar-maximum-month-with-items.png',
);
});
Expand Down Expand Up @@ -156,8 +165,8 @@
});

test('Select from [items] => select date range from calendar', async ({page}) => {
const calendar = new TuiCalendarPO(
inputDateRange.calendarRange.locator('tui-calendar'),
const calendarSheet = new TuiCalendarSheetPO(
inputDateRange.calendar.locator('tui-calendar-sheet'),
);

await tuiGoto(
Expand All @@ -171,7 +180,7 @@
await expect(inputDateRange.textfield).toHaveValue('Today');

await inputDateRange.textfield.click();
await calendar.clickOnCalendarDay(21);
await calendarSheet.clickOnDay(21);

await expect(inputDateRange.textfield).toHaveValue(
`21.09.2020${CHAR_NO_BREAK_SPACE}–${CHAR_NO_BREAK_SPACE}25.09.2020`,
Expand All @@ -191,9 +200,45 @@

await expect(example).toHaveScreenshot('09-calendar-shows-end-of-period.png');
});

test.describe('Mobile emulation', () => {
test.use({
viewport: {
width: TUI_PLAYWRIGHT_MOBILE_VIEWPORT_WIDTH,
height: TUI_PLAYWRIGHT_MOBILE_VIEWPORT_HEIGHT,
},
userAgent: TUI_PLAYWRIGHT_MOBILE_USER_AGENT,
});

let mobileCalendar!: TuiMobileCalendarPO;

test.beforeEach(() => {
mobileCalendar = new TuiMobileCalendarPO(inputDateRange.calendar);
});

test('Selection of only single date produces range with the same start and end', async ({
page,
}) => {
await tuiGoto(page, `${DemoRoute.InputDateRange}/API`);
await inputDateRange.textfieldIcon.click();

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

await calendarSheet?.clickOnDay(17);
await mobileCalendar.confirmButton.click();

await expect(inputDateRange.textfield).toHaveValue(

Check failure on line 230 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:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end

1) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end Error: Timed out 5000ms waiting for expect(locator).toHaveValue(expected) Locator: locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') Expected string: "17.08.2020 – 17.08.2020" Received string: "" Call log: - expect.toHaveValue with timeout 5000ms - waiting for locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" 228 | await mobileCalendar.confirmButton.click(); 229 | > 230 | await expect(inputDateRange.textfield).toHaveValue( | ^ 231 | `17.08.2020${CHAR_NO_BREAK_SPACE}–${CHAR_NO_BREAK_SPACE}17.08.2020`, 232 | ); 233 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:230:56

Check failure on line 230 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:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end

1) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveValue(expected) Locator: locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') Expected string: "17.08.2020 – 17.08.2020" Received string: "" Call log: - expect.toHaveValue with timeout 5000ms - waiting for locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" 228 | await mobileCalendar.confirmButton.click(); 229 | > 230 | await expect(inputDateRange.textfield).toHaveValue( | ^ 231 | `17.08.2020${CHAR_NO_BREAK_SPACE}–${CHAR_NO_BREAK_SPACE}17.08.2020`, 232 | ); 233 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:230:56

Check failure on line 230 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:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end

1) [chromium] › tests/kit/input-date-range/input-date-range.spec.ts:219:17 › InputDateRange › API › Mobile emulation › Selection of only single date produces range with the same start and end Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveValue(expected) Locator: locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') Expected string: "17.08.2020 – 17.08.2020" Received string: "" Call log: - expect.toHaveValue with timeout 5000ms - waiting for locator('#demo-content').locator('tui-input-date-range').getByRole('textbox') - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" - locator resolved to <input tabindex="0" inputmode="" placeholder="" aria-invalid="false" _ngcontent-ng-c1657133415="" id="tui_interactive_431601061540000" class="t-input ng-pristine ng-valid ng-touched" automation-id="tui-primitive-textfield__native-input"/> - unexpected value "" 228 | await mobileCalendar.confirmButton.click(); 229 | > 230 | await expect(inputDateRange.textfield).toHaveValue( | ^ 231 | `17.08.2020${CHAR_NO_BREAK_SPACE}–${CHAR_NO_BREAK_SPACE}17.08.2020`, 232 | ); 233 | }); at /home/runner/work/taiga-ui/taiga-ui/projects/demo-playwright/tests/kit/input-date-range/input-date-range.spec.ts:230:56
`17.08.2020${CHAR_NO_BREAK_SPACE}–${CHAR_NO_BREAK_SPACE}17.08.2020`,
);
});
});
});

test.describe('Examples', () => {
test.beforeEach(async ({page}) => {
await tuiGoto(page, DemoRoute.InputDateRange);
});

test('Select second same range => after close/open calendar displays selected period displays correctly', async () => {
const example = documentationPage.getExample('#custom-period');

Expand All @@ -209,7 +254,7 @@
expect(await inputDateRange.itemHasCheckmark(2)).toBeTruthy();

await expect(inputDateRange.textfield).toHaveValue('Yet another yesterday');
await expect(inputDateRange.calendarRange).toHaveScreenshot(
await expect(inputDateRange.calendar).toHaveScreenshot(
'08-calendar-correct-selected-period-after-close-open.png',
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type {Locator} from '@playwright/test';

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

public async getDays(): Promise<Locator[]> {
return this.host.locator('[automation-id="tui-calendar-sheet__cell"]').all();
return this.host
.locator(
'[automation-id="tui-calendar-sheet__cell"], [automation-id="tui-primitive-calendar-mobile__cell"]',
)
.all();
}

public async clickOnCalendarDay(day: number): Promise<void> {
public async clickOnDay(day: number): Promise<void> {
const cells = await this.getDays();

for (const cell of cells) {
Expand Down
3 changes: 2 additions & 1 deletion projects/demo-playwright/utils/page-objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './calendar.po';
export * from './calendar-range.po';
export * from './calendar-sheet.po';
export * from './combo-box.po';
export * from './documentation-api-page.po';
export * from './documentation-page.po';
Expand All @@ -14,6 +14,7 @@ export * from './input-range.po';
export * from './input-slider.po';
export * from './input-tag.po';
export * from './input-time.po';
export * from './mobile-calendar.po';
export * from './multi-select.po';
export * from './range.po';
export * from './select.po';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import {expect} from '@playwright/test';

export class TuiInputDateRangePO {
public readonly textfield: Locator = this.host.getByRole('textbox');
public readonly calendarRange: Locator = this.host
public readonly textfieldIcon: Locator = this.host.getByTestId(
'tui-input-date-range__icon',
);

public readonly calendar: Locator = this.host
.page()
.locator('tui-calendar-range');
.locator('tui-calendar-range, tui-mobile-calendar');

public readonly items = this.calendarRange.locator(
public readonly items = this.calendar.locator(
'[automation-id="tui-calendar-range__menu"]',
);

constructor(private readonly host: Locator) {}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {TuiCalendarSheetPO} from '@demo-playwright/utils';
import type {Locator} from '@playwright/test';

export class TuiMobileCalendarPO {
public cancelButton = this.host.getByTestId('tui-mobile-calendar__cancel');
public confirmButton = this.host.getByTestId('tui-mobile-calendar__confirm');

constructor(private readonly host: Locator) {}

public async getCalendarSheets(): Promise<TuiCalendarSheetPO[]> {
const locators = await this.host
.page()
.locator('tui-calendar-sheet, tui-mobile-calendar-sheet')
.all();

return locators.map((x) => new TuiCalendarSheetPO(x));
}
}
Loading