Skip to content

Commit

Permalink
fix(kit): InputDateTime does not change filler on dynamic change of…
Browse files Browse the repository at this point in the history
… `[timeMode]` prop (#6891)
  • Loading branch information
nsbarsukov authored Feb 27, 2024
1 parent c70e4f4 commit 70e039f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
TuiDocumentationPagePO,
tuiGoto,
TuiInputDateTimePO,
TuiSelectPO,
} from '@demo-playwright/utils';
import {expect, Locator, test} from '@playwright/test';

Expand Down Expand Up @@ -147,6 +148,29 @@ test.describe('InputDateTime', () => {
'15.11.2018, '.length,
);
});

test('change filler on dynamic change of [timeMode] prop', async ({page}) => {
await tuiGoto(page, 'components/input-date-time/API?timeMode=HH:MM');
await inputDateTime.textfield.focus();
await expect(inputDateTime.host).toHaveScreenshot('03-timeMode=HH:MM.png');

const timeModeRow = documentationPage.getRow('[timeMode]');
const timeModeSelect = new TuiSelectPO(
(await documentationPage.getSelect(timeModeRow)) as Locator,
);

await timeModeSelect.textfield.click();
await timeModeSelect.selectOptions([1]);
await inputDateTime.textfield.focus();
await expect(inputDateTime.host).toHaveScreenshot('03-timeMode=HH:MM.SS.png');

await timeModeSelect.textfield.click();
await timeModeSelect.selectOptions([2]);
await inputDateTime.textfield.focus();
await expect(inputDateTime.host).toHaveScreenshot(
'03-timeMode=HH:MM.SS.MSS.png',
);
});
});

test.describe('invalid date', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class TuiDocumentationApiPagePO {
}
}

protected getRow(rowName: string): Locator {
return this.page.locator(`.t-table .t-row:has-text("${rowName}")`);
}

protected async getRows(): Promise<Locator[]> {
return this.page.locator('.t-table .t-row:not(.t-row_header)').all();
}
Expand Down
1 change: 1 addition & 0 deletions projects/demo-playwright/utils/page-objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './input-tag.po';
export * from './input-time.po';
export * from './multi-select.po';
export * from './range.po';
export * from './select.po';
export * from './slider.po';
export * from './table-pagination-page.po';
export * from './textfield-with-data-list.po';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class TuiInputDateTimePO {
protected readonly textfield: Locator = this.host.getByRole('textbox');
protected readonly calendar: Locator = this.host.page().locator('tui-calendar');

constructor(private readonly host: Locator) {}
constructor(public readonly host: Locator) {}

protected async selectDayViaCalendar(day: number): Promise<void> {
return this.calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
tuiDateStreamWithTransformer,
TuiInputDateOptions,
} from '@taiga-ui/kit/tokens';
import {combineLatest, map, Observable, takeUntil, timer} from 'rxjs';
import {BehaviorSubject, combineLatest, map, Observable, takeUntil, timer} from 'rxjs';

@Component({
selector: 'tui-input-date-time',
Expand All @@ -78,6 +78,7 @@ export class TuiInputDateTimeComponent
private readonly options = inject(TUI_INPUT_DATE_OPTIONS);
private readonly textfieldSize = inject(TUI_TEXTFIELD_SIZE);
private month: TuiMonth | null = null;
private readonly timeMode$ = new BehaviorSubject<TuiTimeMode>('HH:MM');
protected readonly timeTexts$ = inject(TUI_TIME_TEXTS);
protected readonly dateTexts$ = inject(TUI_DATE_TEXTS);
protected override readonly valueTransformer = inject(
Expand All @@ -98,7 +99,13 @@ export class TuiInputDateTimeComponent
public defaultActiveYearMonth = TuiMonth.currentLocal();

@Input()
public timeMode: TuiTimeMode = 'HH:MM';
public set timeMode(value: TuiTimeMode) {
this.timeMode$.next(value);
}

public get timeMode(): TuiTimeMode {
return this.timeMode$.value;
}

protected open = false;

Expand All @@ -110,8 +117,13 @@ export class TuiInputDateTimeComponent
changeDateSeparator(dateTexts[this.dateFormat], this.dateSeparator),
),
),
this.timeTexts$.pipe(map(texts => texts[this.timeMode])),
]).pipe(map(fillers => this.getDateTimeString(...fillers)));
this.timeTexts$,
this.timeMode$,
]).pipe(
map(([dateFiller, timeTexts, timeMode]) =>
this.getDateTimeString(dateFiller, timeTexts[timeMode]),
),
);

protected readonly dateFormat = inject(TUI_DATE_FORMAT);
protected readonly dateSeparator = inject(TUI_DATE_SEPARATOR);
Expand Down

0 comments on commit 70e039f

Please sign in to comment.