Skip to content

Commit

Permalink
[ADF-3936] Lock file checkboxes need refresh to appear checked (#10293)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekpluta authored Oct 10, 2024
1 parent 9e96fed commit a3033f9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
};
Expand All @@ -47,31 +82,36 @@ 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);
expect(component.form.value.isTimeLock).toBe(true);
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));

Expand All @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit a3033f9

Please sign in to comment.