mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ADF-3936] Lock file checkboxes need refresh to appear checked (#10293)
This commit is contained in:
parent
9e96fed71e
commit
a3033f9f17
@ -20,12 +20,47 @@ import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { NodeLockDialogComponent } from './node-lock.dialog';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { addMinutes } from 'date-fns';
|
||||
import { Node, NodeEntry } from '@alfresco/js-api';
|
||||
|
||||
describe('NodeLockDialogComponent', () => {
|
||||
let fixture: ComponentFixture<NodeLockDialogComponent>;
|
||||
let component: NodeLockDialogComponent;
|
||||
let expiryDate: Date;
|
||||
|
||||
const nodeMock: Node = {
|
||||
isLocked: true,
|
||||
properties: {
|
||||
['cm:testProperty']: 'TEST_PROPERTY',
|
||||
['cm:lockType']: 'TEST_LOCK',
|
||||
['cm:expiryDate']: addMinutes(new Date(), 90)
|
||||
},
|
||||
id: 'node-id',
|
||||
name: 'node-name',
|
||||
nodeType: 'cm:content',
|
||||
allowableOperations: ['update'],
|
||||
isFile: true,
|
||||
isFolder: false,
|
||||
modifiedAt: null,
|
||||
modifiedByUser: null,
|
||||
createdAt: null,
|
||||
createdByUser: null
|
||||
};
|
||||
|
||||
const setComponentData = (isLocked: boolean, properties?: any) => {
|
||||
component.data = {
|
||||
node: {
|
||||
...nodeMock,
|
||||
isLocked,
|
||||
properties: properties ?? {
|
||||
['cm:lockType']: 'WRITE_LOCK',
|
||||
['cm:expiryDate']: expiryDate
|
||||
}
|
||||
},
|
||||
onError: () => {}
|
||||
};
|
||||
fixture.detectChanges();
|
||||
};
|
||||
|
||||
const dialogRef = {
|
||||
close: jasmine.createSpy('close')
|
||||
};
|
||||
@ -47,23 +82,10 @@ describe('NodeLockDialogComponent', () => {
|
||||
beforeEach(() => {
|
||||
jasmine.clock().mockDate(new Date());
|
||||
expiryDate = addMinutes(new Date(), 1);
|
||||
|
||||
component.data = {
|
||||
node: {
|
||||
id: 'node-id',
|
||||
name: 'node-name',
|
||||
isLocked: true,
|
||||
properties: {
|
||||
['cm:lockType']: 'WRITE_LOCK',
|
||||
['cm:expiryDate']: expiryDate
|
||||
}
|
||||
},
|
||||
onError: () => {}
|
||||
};
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should init dialog with form inputs', () => {
|
||||
it('should init dialog with form inputs and set isLocked, allowOwner, isTimeLock to true', () => {
|
||||
setComponentData(true);
|
||||
expect(component.nodeName).toBe('node-name');
|
||||
expect(component.form.value.isLocked).toBe(true);
|
||||
expect(component.form.value.allowOwner).toBe(true);
|
||||
@ -71,7 +93,25 @@ describe('NodeLockDialogComponent', () => {
|
||||
expect(component.form.value.time).toEqual(expiryDate);
|
||||
});
|
||||
|
||||
it('should init dialog with form inputs and set allowOwner, isTimeLock to false', () => {
|
||||
setComponentData(true, { ['cm:lockType']: 'OTHER_LOCK_TYPE' });
|
||||
expect(component.form.value.isLocked).toBe(true);
|
||||
expect(component.form.value.allowOwner).toBe(false);
|
||||
expect(component.form.value.isTimeLock).toBe(false);
|
||||
});
|
||||
|
||||
it('should init dialog with form inputs and set isLocked if there is cm:lockType property', () => {
|
||||
setComponentData(false);
|
||||
expect(component.form.value.isLocked).toBe(true);
|
||||
});
|
||||
|
||||
it('should init dialog with form inputs and set isLocked, allowOwner, isTimeLock to false', () => {
|
||||
setComponentData(false);
|
||||
expect(component.form.value.isLocked).toBe(true);
|
||||
});
|
||||
|
||||
it('should call dialog to close with form data when submit is successfully', fakeAsync(() => {
|
||||
setComponentData(true);
|
||||
const node: any = { entry: {} };
|
||||
spyOn(component.nodesApi, 'lockNode').and.returnValue(Promise.resolve(node));
|
||||
|
||||
@ -82,7 +122,22 @@ describe('NodeLockDialogComponent', () => {
|
||||
expect(dialogRef.close).toHaveBeenCalledWith(node.entry);
|
||||
}));
|
||||
|
||||
it('should call dialog and set isLocked and node properties', fakeAsync(() => {
|
||||
setComponentData(true);
|
||||
const nodeEntryMock: NodeEntry = {
|
||||
entry: nodeMock
|
||||
};
|
||||
spyOn(component.nodesApi, 'lockNode').and.returnValue(Promise.resolve(nodeEntryMock));
|
||||
component.submit();
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.data.node).toEqual(nodeEntryMock.entry);
|
||||
expect(component.data.isLocked).toBeFalsy();
|
||||
}));
|
||||
|
||||
it('should call onError if submit fails', fakeAsync(() => {
|
||||
setComponentData(true);
|
||||
spyOn(component.nodesApi, 'lockNode').and.returnValue(Promise.reject(new Error('error')));
|
||||
spyOn(component.data, 'onError');
|
||||
|
||||
|
@ -74,7 +74,7 @@ export class NodeLockDialogComponent implements OnInit {
|
||||
const time = isTimeLock ? new Date(node.properties['cm:expiryDate']) : new Date();
|
||||
|
||||
this.form = this.formBuilder.group({
|
||||
isLocked: node.isLocked || false,
|
||||
isLocked: !!node.properties['cm:lockType'] || node.isLocked,
|
||||
allowOwner: node.properties['cm:lockType'] === 'WRITE_LOCK',
|
||||
isTimeLock,
|
||||
time
|
||||
@ -113,6 +113,7 @@ export class NodeLockDialogComponent implements OnInit {
|
||||
this.toggleLock()
|
||||
.then((node: NodeEntry) => {
|
||||
this.data.node.isLocked = this.form.value.isLocked;
|
||||
this.data.node.properties = node.entry.properties;
|
||||
this.dialog.close(node.entry);
|
||||
})
|
||||
.catch((error: any) => this.data.onError(error));
|
||||
|
Loading…
x
Reference in New Issue
Block a user