mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
used date-fns instead of moment.js in code as well as in test cases
This commit is contained in:
@@ -28,9 +28,10 @@ import { RenditionService } from '../common/services/rendition.service';
|
||||
|
||||
import { SharedLinksApiService } from './services/shared-links-api.service';
|
||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||
import moment from 'moment';
|
||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { format } from 'date-fns';
|
||||
import endOfDay from 'date-fns/endOfDay';
|
||||
|
||||
describe('ShareDialogComponent', () => {
|
||||
let node;
|
||||
@@ -256,7 +257,7 @@ describe('ShareDialogComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.form.controls['time'].setValue(moment());
|
||||
component.form.controls['time'].setValue(new Date());
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -305,7 +306,7 @@ describe('ShareDialogComponent', () => {
|
||||
|
||||
it('should update node with input date and end of day time when type is `date`', fakeAsync(() => {
|
||||
const dateTimePickerType = 'date';
|
||||
const date = moment('2525-01-01 13:00:00');
|
||||
const date = new Date('2525-01-01 13:00:00');
|
||||
spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType as any);
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -316,9 +317,7 @@ describe('ShareDialogComponent', () => {
|
||||
fixture.detectChanges();
|
||||
tick(500);
|
||||
|
||||
let expiryDate = date.endOf('day').utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
||||
const expiryDate = format(endOfDay(date as Date), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||
|
||||
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
||||
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
||||
@@ -329,7 +328,7 @@ describe('ShareDialogComponent', () => {
|
||||
|
||||
it('should update node with input date and time when type is `datetime`', fakeAsync(() => {
|
||||
const dateTimePickerType = 'datetime';
|
||||
const date = moment('2525-01-01 13:00:00');
|
||||
const date = new Date('2525-01-01 13:00:00');
|
||||
spyOn(appConfigService, 'get').and.returnValue(dateTimePickerType);
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -340,9 +339,7 @@ describe('ShareDialogComponent', () => {
|
||||
fixture.detectChanges();
|
||||
tick(100);
|
||||
|
||||
let expiryDate = date.utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
||||
const expiryDate = format((new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||
|
||||
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
||||
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
||||
|
||||
@@ -35,10 +35,13 @@ import { ContentService } from '../common/services/content.service';
|
||||
import { SharedLinksApiService } from './services/shared-links-api.service';
|
||||
import { SharedLinkBodyCreate, SharedLinkEntry } from '@alfresco/js-api';
|
||||
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
||||
import moment from 'moment';
|
||||
import { ContentNodeShareSettings } from './content-node-share.settings';
|
||||
import { takeUntil, debounceTime } from 'rxjs/operators';
|
||||
import { RenditionService } from '../common/services/rendition.service';
|
||||
import { format } from 'date-fns';
|
||||
import add from 'date-fns/add';
|
||||
import endOfDay from 'date-fns/endOfDay';
|
||||
|
||||
|
||||
type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
|
||||
|
||||
@@ -51,7 +54,7 @@ type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
|
||||
})
|
||||
export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
minDate = moment().add(1, 'd');
|
||||
minDate = add(new Date(), { days: 1 });
|
||||
sharedId: string;
|
||||
fileName: string;
|
||||
baseShareUrl: string;
|
||||
@@ -112,10 +115,9 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||
takeUntil(this.onDestroy$)
|
||||
)
|
||||
.subscribe(value => this.onTimeChanged(value));
|
||||
|
||||
}
|
||||
|
||||
onTimeChanged(date: moment.Moment) {
|
||||
onTimeChanged(date: Date | string) {
|
||||
this.updateNode(date);
|
||||
}
|
||||
|
||||
@@ -273,19 +275,19 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.form.setValue({
|
||||
sharedUrl: `${this.baseShareUrl}${this.sharedId}`,
|
||||
time: expiryDate ? moment(expiryDate).local() : null
|
||||
time: expiryDate ? new Date(expiryDate) : null
|
||||
}, { emitEvent: false });
|
||||
|
||||
return expiryDate;
|
||||
}
|
||||
|
||||
private updateNode(date: moment.Moment) {
|
||||
private updateNode(date: Date | string) {
|
||||
let expiryDate: Date | string;
|
||||
if (date) {
|
||||
if (this.type === 'date') {
|
||||
expiryDate = date.endOf('day').utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
expiryDate = format(endOfDay(date as Date), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||
} else {
|
||||
expiryDate = date.utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
expiryDate = format((new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||
}
|
||||
} else {
|
||||
expiryDate = null;
|
||||
@@ -309,24 +311,19 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private sharedLinkWithExpirySettings(expiryDate: Date | string) {
|
||||
if (typeof expiryDate === 'string') {
|
||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
||||
}
|
||||
const nodeObject: SharedLinkBodyCreate = {
|
||||
nodeId: this.data.node.entry.id,
|
||||
expiresAt: expiryDate as Date
|
||||
};
|
||||
|
||||
this.createSharedLinks(nodeObject);
|
||||
}
|
||||
|
||||
private updateEntryExpiryDate(date: moment.Moment) {
|
||||
private updateEntryExpiryDate(date: Date | string) {
|
||||
const {properties} = this.data.node.entry;
|
||||
|
||||
if (properties) {
|
||||
properties['qshare:expiryDate'] = date
|
||||
? date.local()
|
||||
? new Date(date)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
"apollo-angular": "^4.2.1",
|
||||
"chart.js": "2.9.4",
|
||||
"cropperjs": "1.5.13",
|
||||
"date-fns": "^2.30.0",
|
||||
"dotenv-expand": "^5.1.0",
|
||||
"editorjs-html": "3.4.2",
|
||||
"editorjs-paragraph-with-alignment": "3.0.0",
|
||||
|
||||
Reference in New Issue
Block a user