Skip to content

Commit

Permalink
chore(legacy): InputDate add test for several items
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlufy committed Nov 5, 2024
1 parent 77e7fd6 commit f6caf49
Showing 1 changed file with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ChangeDetectionStrategy, Component, ViewChild} from '@angular/core';
import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {TuiDay, TuiValueTransformer} from '@taiga-ui/cdk';
import {TUI_LAST_DAY, TuiDay, TuiValueTransformer} from '@taiga-ui/cdk';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core';
import {TUI_DATE_FORMAT, TuiHint, TuiRoot} from '@taiga-ui/core';
import {NG_EVENT_PLUGINS} from '@taiga-ui/event-plugins';
Expand All @@ -13,6 +13,7 @@ import {
TuiInputDateModule,
TuiTextfieldControllerModule,
} from '@taiga-ui/legacy';
import {TuiNamedDay} from '@taiga-ui/legacy/classes';
import {TuiNativeInputPO, TuiPageObject} from '@taiga-ui/testing';
import {of} from 'rxjs';

Expand All @@ -30,12 +31,14 @@ describe('InputDate', () => {
<tui-root>
<tui-input-date
[formControl]="control"
[items]="items"
[min]="min"
[readOnly]="readOnly"
[tuiHintContent]="hintContent"
[tuiTextfieldCleaner]="cleaner"
[tuiTextfieldLabelOutside]="labelOutside"
[tuiTextfieldSize]="size"
[(ngModel)]="value"
>
Select date
</tui-input-date>
Expand All @@ -57,6 +60,10 @@ describe('InputDate', () => {

public labelOutside = false;

public items: TuiNamedDay[] = [];

public value: TuiDay | null = new TuiDay(2017, 2, 1);

public size: TuiSizeL | TuiSizeS = 'm';

public hintContent: string | null = 'prompt';
Expand Down Expand Up @@ -183,6 +190,64 @@ describe('InputDate', () => {
});
});
});

describe('With items', () => {
beforeEach(() => {
testComponent.items = [
new TuiNamedDay(
new TuiDay(2017, 2, 1),
'Current',
TuiDay.currentLocal(),
),
new TuiNamedDay(
TUI_LAST_DAY.append({year: -1}),
'Until today',
TuiDay.currentLocal(),
),
];
});

it('when entering item date, input shows named date', async () => {
inputPO.sendText('01.02.2017');

await fixture.whenStable();

expect(inputPO.value).toBe('Current');
});

it('when control value updated with item date, input shows named date', async () => {
testComponent.control.setValue(TUI_LAST_DAY.append({year: -1}));
fixture.detectChanges();

await fixture.whenStable();

expect(inputPO.value).toBe('Until today');
});

it('when ngModel value updated with item date, input shows named date', async () => {
testComponent.value = TUI_LAST_DAY.append({year: -1});
fixture.detectChanges();

await fixture.whenStable();

expect(inputPO.value).toBe('Until today');
});

it('when selected item date via calendar, input shows named date', async () => {
mouseDownOnTextfield();

expect(getCalendar()).not.toBeNull();

const calendarCell = getCalendarCell(1);

calendarCell?.nativeElement.click();

fixture.detectChanges();
await fixture.whenStable();

expect(inputPO.value).toBe('Current');
});
});
});

describe('InputDate + TUI_DATE_FORMAT = YMD integration', () => {
Expand Down

0 comments on commit f6caf49

Please sign in to comment.