[AAE-17666] Remove date cell e2es covered by unit tests (#9153)

This commit is contained in:
Tomasz Gnyp
2023-12-12 14:41:51 +01:00
committed by GitHub
parent f5282834bc
commit 468c32691d
7 changed files with 36 additions and 52 deletions

View File

@@ -2,14 +2,14 @@
<span
[title]="tooltip | adfLocalizedDate: config.tooltipFormat: config.locale"
class="adf-datatable-cell-value"
*ngIf="format === 'timeAgo'; else standard_date">
*ngIf="config.format === 'timeAgo'; else standard_date">
{{ date | adfTimeAgo: config.locale }}
</span>
<ng-template #standard_date>
<span
class="adf-datatable-cell-value"
[title]="tooltip | adfLocalizedDate: config.tooltipFormat: config.locale">
{{ date | adfLocalizedDate: format: config.locale }}
{{ date | adfLocalizedDate: config.format: config.locale }}
</span>
</ng-template>
</ng-container>

View File

@@ -175,13 +175,13 @@ describe('DateCellComponent', () => {
checkDisplayedDate(expectedDate);
});
it('should display date and override dateConfig by column format if is provided', () => {
it('should display date and override column format by dateConfig if is provided', () => {
component.column = mockColumn;
const mockDateConfig: DateConfig = {
format: 'short'
};
const expectedDate = 'Wednesday, October 25, 2023 at 12:00:00 AM GMT+00:00';
const expectedDate = '10/25/23, 12:00 AM';
renderDateCell(mockDateConfig, mockDate, mockTooltip);
checkDisplayedDate(expectedDate);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Input, OnInit, ViewEncapsulation, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation, inject } from '@angular/core';
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component';
import { AppConfigService } from '../../../app-config/app-config.service';
import { DateConfig } from '../../data/data-column.model';
@@ -28,7 +28,8 @@ import { LocalizedDatePipe, TimeAgoPipe } from '../../../pipes';
selector: 'adf-date-cell',
templateUrl: './date-cell.component.html',
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-content-cell' }
host: { class: 'adf-datatable-content-cell' },
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DateCellComponent extends DataTableCellComponent implements OnInit {
@@ -50,14 +51,36 @@ export class DateCellComponent extends DataTableCellComponent implements OnInit
this.setConfig();
}
get format(): string {
return this.column?.format ?? this.config.format;
private setConfig(): void {
if (this.dateConfig) {
this.setCustomConfig();
} else {
this.setDefaultConfig();
}
}
private setConfig(): void {
this.config.format = this.dateConfig?.format || this.getAppConfigPropertyValue('dateValues.defaultDateFormat', this.defaultDateConfig.format);
this.config.tooltipFormat = this.dateConfig?.tooltipFormat || this.getAppConfigPropertyValue('dateValues.defaultTooltipDateFormat', this.defaultDateConfig.tooltipFormat);
this.config.locale = this.dateConfig?.locale || this.getAppConfigPropertyValue('dateValues.defaultLocale', this.defaultDateConfig.locale);
private setCustomConfig(): void {
this.config.format = this.dateConfig?.format || this.getDefaultFormat();
this.config.tooltipFormat = this.dateConfig?.tooltipFormat || this.getDefaultTooltipFormat();
this.config.locale = this.dateConfig?.locale || this.getDefaultLocale();
}
private setDefaultConfig(): void {
this.config.format = this.getDefaultFormat();
this.config.tooltipFormat = this.getDefaultTooltipFormat();
this.config.locale = this.getDefaultLocale();
}
private getDefaultFormat(): string {
return this.column?.format || this.getAppConfigPropertyValue('dateValues.defaultDateFormat', this.defaultDateConfig.format);
}
private getDefaultLocale(): string {
return this.getAppConfigPropertyValue('dateValues.defaultLocale', this.defaultDateConfig.locale);
}
private getDefaultTooltipFormat(): string {
return this.getAppConfigPropertyValue('dateValues.defaultTooltipDateFormat', this.defaultDateConfig.tooltipFormat);
}
private getAppConfigPropertyValue(key: string, defaultValue: string): string {