Skip to content

Commit

Permalink
fix: change the test to en_US locale
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqi73 committed Oct 31, 2019
1 parent ffe8e4b commit 512c85f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 65 deletions.
2 changes: 1 addition & 1 deletion components/date-picker/abstract-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export abstract class AbstractPickerComponent implements OnInit, OnChanges, OnDe
this.cdr.markForCheck();
}

private setFormat(): void {}
protected setFormat(): void {}

private setDefaultPlaceHolder(): void {
if (!this.isCustomPlaceHolder && this.nzLocale) {
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/date-range-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class DateRangePickerComponent extends AbstractPickerComponent implements
}
}

private setFormat(): void {
protected setFormat(): void {
// Default format when it's empty
if (this.showWeek) {
// TODO: Complete weekFormat in every locale file
Expand Down
71 changes: 26 additions & 45 deletions components/date-picker/nz-date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { isSameDay } from 'date-fns';

import { dispatchKeyboardEvent, dispatchMouseEvent, typeInElement, NgStyleInterface } from 'ng-zorro-antd/core';
import en_US from '../i18n/languages/en_US';

import { enUS } from 'date-fns/locale';
import { NzI18nModule, NzI18nService, NZ_DATE_LOCALE } from 'ng-zorro-antd/i18n';
import { en_US, zh_CN, NzI18nModule, NzI18nService, NZ_I18N } from 'ng-zorro-antd/i18n';
import { NzDatePickerComponent } from './nz-date-picker.component';
import { NzDatePickerModule } from './nz-date-picker.module';

Expand All @@ -31,6 +29,7 @@ describe('NzDatePickerComponent', () => {
TestBed.configureTestingModule({
imports: [FormsModule, NoopAnimationsModule, NzDatePickerModule, NzI18nModule],
providers: [
{ provide: NZ_I18N, useValue: en_US }
// { provide: NZ_DATE_CONFIG, useValue: { firstDayOfWeek: 1 } }
],
declarations: [NzTestDatePickerComponent]
Expand Down Expand Up @@ -130,21 +129,19 @@ describe('NzDatePickerComponent', () => {
}));

it('should support changing language at runtime', fakeAsync(() => {
fixture.detectChanges();
expect(getPickerTrigger().placeholder).toBe('请选择日期');
i18nService.setLocale(en_US);
// i18nService.setDateLocale(en);
fixture.detectChanges();
expect(getPickerTrigger().placeholder).toBe('Select date');

i18nService.setLocale(zh_CN);
fixture.detectChanges();
expect(getPickerTrigger().placeholder).toBe('请选择日期');
dispatchMouseEvent(getPickerTriggerWrapper(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(
(queryFromOverlay('.ant-calendar-date-input-wrap input.ant-calendar-input') as HTMLInputElement).placeholder
).toBe('Select date');
expect(queryFromOverlay('.ant-calendar-table .ant-calendar-column-header-inner').textContent).toContain('Su');
).toBe('请选择日期');
expect(queryFromOverlay('.ant-calendar-table .ant-calendar-column-header-inner').textContent).toContain('');
}));

/* Issue https://github.com/NG-ZORRO/ng-zorro-antd/issues/1539 */
Expand Down Expand Up @@ -265,10 +262,10 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
};
// Should fail to submit a disabled date
submit('2018-11-15');
submit('11/15/2018');
expect(getPickerContainer()).not.toBeNull();
// But it should be fine to submit an enabled date
submit('2018-11-11');
submit('11/11/2019');
expect(getPickerContainer()).toBeNull();
}));

Expand Down Expand Up @@ -406,6 +403,18 @@ describe('NzDatePickerComponent', () => {
expect(result.getMonth() + 1).toBe(10);
expect(result.getDate()).toBe(25);
}));

it('should nzFormat has default value', fakeAsync(() => {
fixtureInstance.nzValue = new Date('2019-10-31 18:30:13');
fixtureInstance.nzShowTime = true;
i18nService.setLocale(zh_CN);
fixture.detectChanges();
expect(fixtureInstance.datePickerComp.defaultFormat).toBe('YYYY年M月D日 HH时mm分ss秒');
openPickerByClickTrigger();
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe(
'2019年10月31日 18时30分13秒'
);
}));
});

describe('panel switch and move forward/afterward', () => {
Expand All @@ -414,8 +423,6 @@ describe('NzDatePickerComponent', () => {
it('should support date panel changes', fakeAsync(() => {
fixtureInstance.nzValue = new Date('2018-11-11');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
openPickerByClickTrigger();
// Click previous year button
dispatchMouseEvent(queryFromOverlay('.ant-calendar-prev-year-btn'), 'click');
Expand All @@ -438,7 +445,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(queryFromOverlay('.ant-calendar-month-select').textContent!.indexOf('10') > -1).toBeTruthy();
expect(queryFromOverlay('.ant-calendar-month-select').textContent!.indexOf('Oct') > -1).toBeTruthy();
// Click next month button * 2
dispatchMouseEvent(queryFromOverlay('.ant-calendar-next-month-btn'), 'click');
fixture.detectChanges();
Expand All @@ -448,7 +455,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(queryFromOverlay('.ant-calendar-month-select').textContent!.indexOf('12') > -1).toBeTruthy();
expect(queryFromOverlay('.ant-calendar-month-select').textContent!.indexOf('Dec') > -1).toBeTruthy();
}));

it('should support month panel changes', fakeAsync(() => {
Expand Down Expand Up @@ -658,7 +665,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
flush();
fixture.detectChanges();
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2018-11-11 00:22:33');
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('11/11/2018 00:22:33');
}));

it('should not reset time', fakeAsync(() => {
Expand All @@ -672,7 +679,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
flush();
fixture.detectChanges();
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2019-07-29 13:03:33');
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('7/28/2019 13:03:33');
}));

it('should support nzShowTime.nzFormat', fakeAsync(() => {
Expand Down Expand Up @@ -821,7 +828,7 @@ describe('NzDatePickerComponent', () => {
expect(input.classList.contains('ant-calendar-input-invalid')).toBeTruthy();

// Correct inputing
input.value = '2018-11-22';
input.value = '11/22/2018';
input.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }));
// dispatchKeyboardEvent(input, 'keyup', ENTER); // Not working?
fixture.detectChanges();
Expand Down Expand Up @@ -890,32 +897,6 @@ describe('NzDatePickerComponent', () => {
}
});

describe('date-fns testing', () => {
let fixture: ComponentFixture<NzTestDatePickerComponent>;
let fixtureInstance: NzTestDatePickerComponent;

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [FormsModule, NoopAnimationsModule, NzDatePickerModule, NzI18nModule],
providers: [{ provide: NZ_DATE_LOCALE, useValue: enUS }],
declarations: [NzTestDatePickerComponent]
});
TestBed.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(NzTestDatePickerComponent);
fixtureInstance = fixture.componentInstance;
fixtureInstance.useSuite = 1;
});

it('should nzFormat has default value', fakeAsync(() => {
fixtureInstance.nzShowTime = true;
fixture.detectChanges();
expect(fixtureInstance.datePickerComp.nzFormat).toBe('MMM d, y h:mm:ss a');
}));
});

@Component({
template: `
<ng-container [ngSwitch]="useSuite">
Expand Down
41 changes: 23 additions & 18 deletions components/date-picker/nz-range-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { differenceInDays, isSameDay } from 'date-fns';

import { dispatchMouseEvent, typeInElement, NgStyleInterface } from 'ng-zorro-antd/core';

import { en_US, NzI18nModule, NZ_I18N } from 'ng-zorro-antd';
import { CandyDate } from '../core';
import { NzDatePickerModule } from './nz-date-picker.module';

Expand All @@ -24,8 +25,8 @@ describe('NzRangePickerComponent', () => {

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [FormsModule, NoopAnimationsModule, NzDatePickerModule],
providers: [],
imports: [FormsModule, NoopAnimationsModule, NzDatePickerModule, NzI18nModule],
providers: [{ provide: NZ_I18N, useValue: en_US }],
declarations: [NzTestRangePickerComponent]
});

Expand Down Expand Up @@ -338,15 +339,15 @@ describe('NzRangePickerComponent', () => {
dispatchMouseEvent(queryFromOverlay('.ant-calendar-range-left .ant-calendar-prev-month-btn'), 'click');
fixture.detectChanges();
expect(
queryFromOverlay('.ant-calendar-range-left .ant-calendar-month-select').textContent!.indexOf('5') > -1
queryFromOverlay('.ant-calendar-range-left .ant-calendar-month-select').textContent!.indexOf('May') > -1
).toBeTruthy();
// Click next month button * 2
dispatchMouseEvent(queryFromOverlay('.ant-calendar-range-left .ant-calendar-next-month-btn'), 'click');
fixture.detectChanges();
dispatchMouseEvent(queryFromOverlay('.ant-calendar-range-left .ant-calendar-next-month-btn'), 'click');
fixture.detectChanges();
expect(
queryFromOverlay('.ant-calendar-range-left .ant-calendar-month-select').textContent!.indexOf('7') > -1
queryFromOverlay('.ant-calendar-range-left .ant-calendar-month-select').textContent!.indexOf('Jul') > -1
).toBeTruthy();
}));
}); // /panel switch and move forward/afterward
Expand Down Expand Up @@ -397,7 +398,7 @@ describe('NzRangePickerComponent', () => {
'click'
);
fixture.detectChanges();
expect(getPickerPanelLeftInput().value).toBe('2018-11-11 00:22:33');
expect(getPickerPanelLeftInput().value).toBe('11/11/2018 00:22:33');
}));

it('should support nzShowTime.nzFormat', fakeAsync(() => {
Expand Down Expand Up @@ -611,14 +612,18 @@ describe('NzRangePickerComponent', () => {
fixture.detectChanges();
openPickerByClickTrigger();

expect(queryFromOverlay('.ant-calendar-range-right .ant-calendar-month-select').textContent).toContain('6');
expect(queryFromOverlay('.ant-calendar-range-right .ant-calendar-month-select').textContent!.trim()).toContain(
'Jun'
);

// Open time picker panel
dispatchMouseEvent(queryFromOverlay('.ant-calendar-time-picker-btn'), 'click');
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(queryFromOverlay('.ant-calendar-range-right .ant-calendar-month-select').textContent).toContain('5');
expect(queryFromOverlay('.ant-calendar-range-right .ant-calendar-month-select').textContent!.trim()).toContain(
'May'
);
}));

it('should support nzRanges', fakeAsync(() => {
Expand Down Expand Up @@ -665,9 +670,9 @@ describe('NzRangePickerComponent', () => {
const leftInput = getPickerPanelLeftInput();
const rightInput = getPickerPanelRightInput();

typeInElement('2018-11-11', leftInput);
typeInElement('11/11/2018', leftInput);
fixture.detectChanges();
typeInElement('2018-12-12', rightInput);
typeInElement('12/12/2018', rightInput);
rightInput.dispatchEvent(new KeyboardEvent('keyup', { key: 'enter' }));
fixture.detectChanges();
tick(500);
Expand All @@ -687,14 +692,14 @@ describe('NzRangePickerComponent', () => {

const leftInput = getPickerPanelLeftInput();
const rightInput = getPickerPanelRightInput();
const newDateString = ['2019-09-15 11:08:22', '2020-10-10 11:08:22'];
const newDateString = ['9/15/2019 11:08:22', '10/10/2020 11:08:22'];
typeInElement(newDateString[0], leftInput);
fixture.detectChanges();
typeInElement(newDateString[1], rightInput);
rightInput.dispatchEvent(new KeyboardEvent('keyup', { key: 'enter' }));
fixture.detectChanges();
tick(500);
expect(nzOnChange).toHaveBeenCalledWith([new Date(newDateString[0]), new Date(newDateString[1])]);
expect(nzOnChange).toHaveBeenCalledWith([new Date('2019-09-15 11:08:22'), new Date('2020-10-10 11:08:22')]);
}));

it('should not change value when click ESC', fakeAsync(() => {
Expand All @@ -706,31 +711,31 @@ describe('NzRangePickerComponent', () => {
const leftInput = getPickerPanelLeftInput();
const rightInput = getPickerPanelRightInput();

typeInElement('2019-11-05', leftInput);
typeInElement('11/5/2019', leftInput);
fixture.detectChanges();
// value should be change
expect(getFirstSelectedDayCell().textContent!.trim()).toBe('5');
typeInElement('2019-12-08', rightInput);
typeInElement('12/8/2019', rightInput);
fixture.detectChanges();
tick(500);
expect(getSecondSelectedDayCell().textContent!.trim()).toBe('8');
dispatchMouseEvent(queryFromOverlay('.cdk-overlay-backdrop'), 'click');
fixture.detectChanges();
tick(500);
expect(getRangePickerLeftInput()!.value).toBe('2018-09-11');
expect(getRangePickerLeftInput()!.value).toBe('9/11/2018');
}));

it('should auto sort range value when start is after end', fakeAsync(() => {
fixture.detectChanges();
openPickerByClickTrigger();
const leftInput = getPickerPanelLeftInput();
const rightInput = getPickerPanelRightInput();
typeInElement('2019-08-10', leftInput);
typeInElement('8/10/2019', leftInput);
fixture.detectChanges();
typeInElement('2018-02-06', rightInput);
typeInElement('2/6/2018', rightInput);
fixture.detectChanges();
expect(leftInput.value).toBe('2018-02-06');
expect(rightInput.value).toBe('2019-08-10');
expect(leftInput.value).toBe('2/6/2018');
expect(rightInput.value).toBe('8/10/2019');
}));
}); // /specified date picker testing

Expand Down

0 comments on commit 512c85f

Please sign in to comment.