Skip to content

Commit

Permalink
[AAE-17666] Remove date cell e2es covered by unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgny committed Dec 11, 2023
1 parent f528283 commit b1f328e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 52 deletions.
8 changes: 1 addition & 7 deletions demo-shell/src/app/components/files/files.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
key="createdAt"
sortingKey="createdAt"
type="date"
[format]="enableMediumTimeFormat ? 'medium' : 'timeAgo'"
[format]="'timeAgo'"
class="adf-ellipsis-cell">
</data-column>

Expand Down Expand Up @@ -330,12 +330,6 @@
</mat-slide-toggle>
</section>

<section>
<mat-slide-toggle [(ngModel)]="enableMediumTimeFormat" id="enableMediumTimeFormat">
Enable medium time format for document list
</mat-slide-toggle>
</section>

<section>
<mat-slide-toggle [(ngModel)]="displayEmptyMetadata" id="displayEmptyMetadata">
Display Empty Metadata
Expand Down
1 change: 0 additions & 1 deletion demo-shell/src/app/components/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {

permissionsStyle: PermissionStyleModel[] = [];
stickyHeader: boolean;
enableMediumTimeFormat = false;
displayEmptyMetadata = false;

constructor(
Expand Down
27 changes: 0 additions & 27 deletions e2e/content-services/document-list/document-list-component.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { createApiService, LoginPage, StringUtil, UploadActions, UserModel, User
import { FileModel } from '../../models/ACS/file.model';
import { NavigationBarPage } from '../../core/pages/navigation-bar.page';
import { NodeEntry } from '@alfresco/js-api';
import { format } from 'date-fns';

describe('Document List Component', () => {
let uploadedFolder: NodeEntry;
Expand Down Expand Up @@ -70,14 +69,6 @@ describe('Document List Component', () => {
name: browser.params.resources.Files.ADF_DOCUMENTS.DOCX.file_name,
location: browser.params.resources.Files.ADF_DOCUMENTS.DOCX.file_path
});
const timeAgoFileModel = new FileModel({
name: browser.params.resources.Files.ADF_DOCUMENTS.TEST.file_name,
location: browser.params.resources.Files.ADF_DOCUMENTS.TEST.file_path
});
const mediumFileModel = new FileModel({
name: browser.params.resources.Files.ADF_DOCUMENTS.PDF_B.file_name,
location: browser.params.resources.Files.ADF_DOCUMENTS.PDF_B.file_path
});

let pdfUploadedNode: NodeEntry;
let docxUploadedNode: NodeEntry;
Expand Down Expand Up @@ -138,24 +129,6 @@ describe('Document List Component', () => {
await contentServicesPage.checkColumnCreatedByHeader();
await contentServicesPage.checkColumnCreatedHeader();
});

it('[C279928] Should be able to display date with timeAgo', async () => {
await apiService.login(acsUser.username, acsUser.password);
timeAgoUploadedNode = await uploadActions.uploadFile(timeAgoFileModel.location, timeAgoFileModel.name, '-my-');
await contentServicesPage.goToDocumentList();
const dateValue = await contentServicesPage.getColumnValueForRow(timeAgoFileModel.name, 'Created');
await expect(dateValue).toMatch(/(ago|few)/);
});

it('[C279929] Should be able to display the date with date type', async () => {
await apiService.login(acsUser.username, acsUser.password);
mediumDateUploadedNode = await uploadActions.uploadFile(mediumFileModel.location, mediumFileModel.name, '-my-');
const createdDate = format(new Date(mediumDateUploadedNode.entry.createdAt), 'PP');
await contentServicesPage.goToDocumentList();
await contentServicesPage.enableMediumTimeFormat();
const dateValue = await contentServicesPage.getColumnValueForRow(mediumFileModel.name, 'Created');
await expect(dateValue).toContain(createdDate);
});
});

describe('Column Sorting', () => {
Expand Down
5 changes: 0 additions & 5 deletions e2e/core/pages/content-services.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ export class ContentServicesPage {
await BrowserVisibility.waitUntilElementIsClickable(this.uploadFileButton);
}

async enableMediumTimeFormat(): Promise<void> {
const mediumTimeFormat = $('#enableMediumTimeFormat');
await BrowserActions.click(mediumTimeFormat);
}

async checkPaginationIsNotDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.emptyPagination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down

0 comments on commit b1f328e

Please sign in to comment.