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

Date range test coverage improvement #7647

Merged
merged 22 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
073104c
test(date-range-picker): input format tests #5732
PlamenaMiteva May 5, 2020
debae51
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular…
PlamenaMiteva May 29, 2020
c21ba7d
chore(date-range-picker): fix lint errors
PlamenaMiteva Jun 1, 2020
d559e5c
refactor(date-range-picker): fix validation; use displayFormat in 2 i…
jackofdiamond5 Jun 3, 2020
d7b2b8b
chore(date-range-picker): moving some tests to unit tests
PlamenaMiteva Jun 1, 2020
30c9a27
Merge branch 'PMiteva/date-range-tests' of https://github.com/IgniteU…
PlamenaMiteva Jun 3, 2020
9e170c1
refactor(date-range-picker): set displayFormat onChanges
jackofdiamond5 Jun 4, 2020
94087ea
refactor(date-range): update input format onChanges & afterViewInit
jackofdiamond5 Jun 8, 2020
e38d0f0
test(date-range-picker): add display format tests #7477
PlamenaMiteva Jun 9, 2020
87a7e49
test(date-range-picker): test cancelable onClosing event #7477
PlamenaMiteva Jun 9, 2020
f45b146
test(date-range-picker): add test on label #7477
PlamenaMiteva Jun 11, 2020
897667f
refactor(date-range-picker): move formatter function to single input …
jackofdiamond5 Jun 11, 2020
1f7b2f2
Merge branch 'PMiteva/date-range-tests' of https://github.com/IgniteU…
PlamenaMiteva Jun 12, 2020
c89fdc8
test(date-range-picker): add formatter test #7477
PlamenaMiteva Jun 12, 2020
ea02193
test(date-range-picker): refactoring date formatting tests #7477
PlamenaMiteva Jun 16, 2020
419905e
refactor(date-range-picker): fallback to Intl if formatDate fails
jackofdiamond5 Jun 19, 2020
d09afb5
Merge branch '9.1.x' of https://github.com/IgniteUI/igniteui-angular …
jackofdiamond5 Jun 22, 2020
dff5cf8
refactor(date-range-picker): add const SingleInputDatesConcatenationS…
jackofdiamond5 Jun 23, 2020
b15e18d
Merge branch '9.1.x' into PMiteva/date-range-tests
kdinev Jun 24, 2020
9fd7242
Merge branch '9.1.x' into PMiteva/date-range-tests
kdinev Jun 25, 2020
972afa0
Merge branch '9.1.x' into PMiteva/date-range-tests
rkaraivanov Jun 25, 2020
4f94776
Merge branch '9.1.x' into PMiteva/date-range-tests
Lipata Jun 26, 2020
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
@@ -1,5 +1,6 @@
import { isIE } from '../core/utils';
import { DatePart, DatePartInfo } from '../directives/date-time-editor/date-time-editor.common';
import { formatDate, FormatWidth, getLocaleDateFormat } from '@angular/common';

/**
* This enum is used to keep the date validation result.
Expand Down Expand Up @@ -48,7 +49,7 @@ export abstract class DatePickerUtil {


/**
* TODO: Unit tests for all public methods.
* TODO: (in issue #6483) Unit tests and docs for all public methods.
*/


Expand Down Expand Up @@ -147,6 +148,38 @@ export abstract class DatePickerUtil {
return DatePickerUtil.getMask(parts);
}

public static formatDate(value: number | Date, format: string, locale: string, timezone?: string): string {
let formattedDate: string;
try {
formattedDate = formatDate(value, format, locale, timezone);
} catch {
this.logMissingLocaleSettings(locale);
const formatter = new Intl.DateTimeFormat(locale);
formattedDate = formatter.format(value);
}

return formattedDate;
}

public static getLocaleDateFormat(locale: string, displayFormat?: string): string {
const formatKeys = Object.keys(FormatWidth) as (keyof FormatWidth)[];
const targetKey = formatKeys.find(k => k.toLowerCase() === displayFormat?.toLowerCase().replace('date', ''));
if (!targetKey) {
// if displayFormat is not shortDate, longDate, etc.
// or if it is not set by the user
return displayFormat;
}
let format: string;
try {
format = getLocaleDateFormat(locale, FormatWidth[targetKey]);
} catch {
this.logMissingLocaleSettings(locale);
format = DatePickerUtil.getDefaultInputFormat(locale);
}

return format;
}

public static isDateOrTimeChar(char: string): boolean {
return DATE_CHARS.indexOf(char) !== -1 || TIME_CHARS.indexOf(char) !== -1;
}
Expand Down Expand Up @@ -303,6 +336,11 @@ export abstract class DatePickerUtil {
return _value.getTime() < _minValue.getTime();
}

private static logMissingLocaleSettings(locale: string): void {
console.warn(`Missing locale data for the locale ${locale}. Please refer to https://angular.io/guide/i18n#i18n-pipes`);
console.warn('Using default browser locale settings.');
}

private static ensureLeadingZero(part: DatePartInfo) {
switch (part.type) {
case DatePart.Date:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, ContentChild, Pipe, PipeTransform, Output, EventEmitter, HostListener, Directive } from '@angular/core';
import { formatDate } from '@angular/common';
import { NgControl } from '@angular/forms';
import { IgxInputDirective, IgxInputState } from '../input-group/public_api';
import { IgxInputGroupComponent } from '../input-group/input-group.component';
import { IgxInputGroupBase } from '../input-group/input-group.common';
import { DatePickerUtil } from '../date-picker/date-picker.utils';
import { IgxDateTimeEditorDirective } from '../directives/date-time-editor/public_api';

/**
Expand All @@ -17,14 +17,17 @@ export interface DateRange {
/** @hidden @internal */
@Pipe({ name: 'dateRange' })
export class DateRangePickerFormatPipe implements PipeTransform {
public transform(values: DateRange, inputFormat?: string, locale?: string): string {
if (!values) {
public transform(values: DateRange, appliedFormat?: string,
locale?: string, formatter?: (_: DateRange) => string): string {
if (!values || !values.start && !values.end) {
return '';
}
if (formatter) {
return formatter(values);
}
const { start, end } = values;
// TODO: move default locale from IgxDateTimeEditorDirective to its commons file/use displayFormat
const startDate = inputFormat ? formatDate(start, inputFormat, locale || 'en') : start?.toLocaleDateString();
const endDate = inputFormat ? formatDate(end, inputFormat, locale || 'en') : end?.toLocaleDateString();
const startDate = appliedFormat ? DatePickerUtil.formatDate(start, appliedFormat, locale || 'en') : start?.toLocaleDateString();
const endDate = appliedFormat ? DatePickerUtil.formatDate(end, appliedFormat, locale || 'en') : end?.toLocaleDateString();
let formatted;
if (start) {
formatted = `${startDate} - `;
Expand All @@ -33,7 +36,6 @@ export class DateRangePickerFormatPipe implements PipeTransform {
}
}

// TODO: no need to set format twice
return formatted ? formatted : '';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
<ng-template #defTemplate>
<igx-input-group (click)="open()">
<input #singleInput igxInput type="text" readonly
[placeholder]="this.value ? '' : appliedFormat"
[placeholder]="this.value ? '' : singleInputFormat"
role="combobox"
aria-haspopup="grid"
[attr.aria-expanded]="!toggle.collapsed"
[attr.aria-labelledby]="this.label?.id"
[value]="this.value | dateRange: this.inputFormat : this.locale"
[value]="this.value | dateRange: this.appliedFormat : this.locale : this.formatter"
/>

<igx-prefix *ngIf="!this.toggleComponents.length">
Expand Down
Loading