Skip to content

Commit

Permalink
chore(kit): InputDate add unit tests of TUI_DATE_SEPARATOR integr…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
nsbarsukov committed Dec 27, 2021
1 parent e0540a7 commit 15c0693
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, DebugElement, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {TUI_DATE_FORMAT, TuiDay} from '@taiga-ui/cdk';
import {TUI_DATE_FORMAT, TUI_DATE_SEPARATOR, TuiDay} from '@taiga-ui/cdk';
import {
TuiHintControllerModule,
TuiRootModule,
Expand Down Expand Up @@ -323,6 +323,44 @@ describe('InputDate + TUI_DATE_FORMAT = MDY integration', () => {
});
});

describe('InputDate + TUI_DATE_FORMAT="MDY" + TUI_DATE_SEPARATOR ="/" (USA format)', () => {
configureTestSuite(() => {
TestBed.configureTestingModule({
...DEFAULT_TESTING_MODULE_META,
providers: [
{provide: TUI_DATE_FORMAT, useValue: 'MDY'},
{provide: TUI_DATE_SEPARATOR, useValue: '/'},
],
});
});

beforeEach(async () => {
await initializeEnvironment();
});

it('accepts valid mm/dd/yyyy', () => {
inputPO.sendText('12272021');

const typedDay = testComponent.control.value;

expect(inputPO.value).toBe('12/27/2021');
expect(typedDay.day).toBe(27);
expect(typedDay.month).toBe(11);
expect(typedDay.year).toBe(2021);
});

it('replaces dots by custom separator', () => {
inputPO.sendText('05.14.1988');

const typedDay = testComponent.control.value;

expect(inputPO.value).toBe('05/14/1988');
expect(typedDay.day).toBe(14);
expect(typedDay.month).toBe(4);
expect(typedDay.year).toBe(1988);
});
});

function mouseDownOnTextfield() {
getTextfield()!.nativeElement.dispatchEvent(
new MouseEvent('mousedown', {bubbles: true}),
Expand Down

0 comments on commit 15c0693

Please sign in to comment.