mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-10246] Add logic to make dates semantically conveyed (#12171)
* [ACS-10246] Add logic to make dates semantically conveyed * [ACS-10246] Fix unit test * [ACS-10246] Enhance the logic for converting date * [ACS-10246] Remove tabindex=0 from time element * [ACS-10246] Add unit test for iso method * [ACS-10246] Add unit test * [ACS-10246] Trigger build * [ACS-10246] Remove date checking from isoDate function
This commit is contained in:
@@ -67,19 +67,25 @@ const renderDateCell = (dateConfig: DateConfig, value: number | string | Date, t
|
|||||||
};
|
};
|
||||||
|
|
||||||
const checkDisplayedDate = (expectedDate: string) => {
|
const checkDisplayedDate = (expectedDate: string) => {
|
||||||
const displayedDate = testingUtils.getByCSS('span').nativeElement.textContent.trim();
|
const displayedDate = testingUtils.getByCSS('time').nativeElement.textContent.trim();
|
||||||
|
|
||||||
expect(displayedDate).toBeTruthy();
|
expect(displayedDate).toBeTruthy();
|
||||||
expect(displayedDate).toBe(expectedDate);
|
expect(displayedDate).toBe(expectedDate);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkDisplayedTooltip = (expectedTooltip: string) => {
|
const checkDisplayedTooltip = (expectedTooltip: string) => {
|
||||||
const displayedTooltip = testingUtils.getByCSS('span').nativeElement.title;
|
const displayedTooltip = testingUtils.getByCSS('time').nativeElement.title;
|
||||||
|
|
||||||
expect(displayedTooltip).toBeTruthy();
|
expect(displayedTooltip).toBeTruthy();
|
||||||
expect(displayedTooltip).toBe(expectedTooltip);
|
expect(displayedTooltip).toBe(expectedTooltip);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkDatetimeAttribute = (expectedIso: string) => {
|
||||||
|
const datetime = testingUtils.getByCSS('time').nativeElement.getAttribute('datetime');
|
||||||
|
|
||||||
|
expect(datetime).toBe(expectedIso);
|
||||||
|
};
|
||||||
|
|
||||||
const configureTestingModule = (providers: any[]) => {
|
const configureTestingModule = (providers: any[]) => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [DateCellComponent],
|
imports: [DateCellComponent],
|
||||||
@@ -141,7 +147,7 @@ describe('DateCellComponent', () => {
|
|||||||
expect(component.config().locale).toEqual('en-US');
|
expect(component.config().locale).toEqual('en-US');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display date and tooltip with defaules values if NO dateConfig or appConfig is provided', () => {
|
it('should display date and tooltip with default values if NO dateConfig or appConfig is provided', () => {
|
||||||
appConfigService.config = {
|
appConfigService.config = {
|
||||||
dateValues: {}
|
dateValues: {}
|
||||||
};
|
};
|
||||||
@@ -232,6 +238,16 @@ describe('DateCellComponent', () => {
|
|||||||
renderDateCell(mockDateConfig, mockTimestamp);
|
renderDateCell(mockDateConfig, mockTimestamp);
|
||||||
checkDisplayedDate(expectedDate);
|
checkDisplayedDate(expectedDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render a datetime attribute with the full ISO date value', () => {
|
||||||
|
const mockDateConfig: DateConfig = {
|
||||||
|
format: 'short',
|
||||||
|
tooltipFormat: 'short'
|
||||||
|
};
|
||||||
|
|
||||||
|
renderDateCell(mockDateConfig, mockDate);
|
||||||
|
checkDatetimeAttribute(mockDate.toISOString());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('DateCellComponent locale', () => {
|
describe('DateCellComponent locale', () => {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import { toSignal } from '@angular/core/rxjs-interop';
|
|||||||
selector: 'adf-date-cell',
|
selector: 'adf-date-cell',
|
||||||
template: `
|
template: `
|
||||||
@if (formattedDate()) {
|
@if (formattedDate()) {
|
||||||
<span [title]="title()" class="adf-datatable-cell-value">{{ formattedDate() }}</span>
|
<time [attr.datetime]="isoDate()" [attr.aria-label]="title() || null" [title]="title()" class="adf-datatable-cell-value"
|
||||||
|
>{{ formattedDate() }}
|
||||||
|
</time>
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
@@ -55,6 +57,14 @@ export class DateCellComponent extends DataTableCellComponent implements OnInit
|
|||||||
// Convert value$ observable to signal for reactive computation
|
// Convert value$ observable to signal for reactive computation
|
||||||
private readonly dateValue = toSignal(this.value$);
|
private readonly dateValue = toSignal(this.value$);
|
||||||
|
|
||||||
|
// Computed signal that automatically formats the date to ISO string for datetime attribute
|
||||||
|
protected readonly isoDate = computed(() => {
|
||||||
|
const date = this.dateValue();
|
||||||
|
const parsed = new Date(date);
|
||||||
|
|
||||||
|
return isNaN(parsed.getTime()) ? null : parsed.toISOString();
|
||||||
|
});
|
||||||
|
|
||||||
// Computed signal that automatically formats the date based on value and config
|
// Computed signal that automatically formats the date based on value and config
|
||||||
protected readonly formattedDate = computed(() => {
|
protected readonly formattedDate = computed(() => {
|
||||||
const date = this.dateValue();
|
const date = this.dateValue();
|
||||||
|
|||||||
Reference in New Issue
Block a user