Skip to content

Commit

Permalink
[ACS-5645] added unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasa-Nataliya committed Sep 18, 2023
1 parent 2000b06 commit 85eb0ab
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projects/aca-content/assets/app.extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@
"click": "EXPAND_INFO_DRAWER"
},
"rules": {
"visible": "canNotShowExpand"
"visible": "canShowExpand"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion projects/aca-content/src/lib/aca-content.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class ContentServiceExtensionModule {
canToggleFavorite: rules.canToggleFavorite,
isLibraryManager: rules.isLibraryManager,
canEditAspects: rules.canEditAspects,
canNotShowExpand: rules.canNotShowExpand,
canShowExpand: rules.canShowExpand,
canInfoPreview: rules.canInfoPreview,
showInfoSelectionButton: rules.showInfoSelectionButton,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { DetailsComponent } from './details.component';
import { ActivatedRoute } from '@angular/router';
import { of, Subject } from 'rxjs';
import { BehaviorSubject, of, Subject } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Store } from '@ngrx/store';
import { ContentApiService } from '@alfresco/aca-shared';
Expand All @@ -49,6 +49,16 @@ describe('DetailsComponent', () => {
select: () => mockStream
};

const extensionsServiceMock = {
getAllowedSidebarActions: jasmine.createSpy('getAllowedSidebarActions')
};

const mockAspectActions = [];

// Mock the observable returned by getAllowedSidebarActions
const mockObservable = new BehaviorSubject(mockAspectActions);
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(mockObservable);

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, DetailsComponent],
Expand Down Expand Up @@ -128,4 +138,12 @@ describe('DetailsComponent', () => {
fixture.detectChanges();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node]));
});

it('should set aspectActions from extensions', () => {
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(of(mockAspectActions));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.aspectActions).toEqual(mockAspectActions);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Store } from '@ngrx/store';
import { NodeEntry } from '@alfresco/js-api';
import { DownloadNodesAction, EditOfflineAction, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppExtensionService } from '@alfresco/aca-shared';

describe('ToggleEditOfflineComponent', () => {
let fixture: ComponentFixture<ToggleEditOfflineComponent>;
Expand All @@ -38,6 +39,10 @@ describe('ToggleEditOfflineComponent', () => {
let selectSpy: jasmine.Spy;
let selection: any;

const extensionsMock = {
updateSidebarActions: jasmine.createSpy('updateSidebarActions')
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, ToggleEditOfflineComponent],
Expand All @@ -48,6 +53,10 @@ describe('ToggleEditOfflineComponent', () => {
select: () => {},
dispatch: () => {}
}
},
{
provide: AppExtensionService,
useValue: extensionsMock
}
]
});
Expand Down Expand Up @@ -133,4 +142,14 @@ describe('ToggleEditOfflineComponent', () => {
})
]);
});

it('should call updateSidebarActions on click', async () => {
selectSpy.and.returnValue(of(selection));
fixture.detectChanges();

await component.onClick();
fixture.detectChanges();

expect(extensionsMock.updateSidebarActions).toHaveBeenCalled();
});
});
22 changes: 22 additions & 0 deletions projects/aca-shared/rules/src/app.rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ describe('app.evaluators', () => {
});
});

describe('canShowExpand', () => {
it('should return false when isLibraries returns true', () => {
const context: any = {
navigation: {
url: '/libraries'
}
};

expect(app.canShowExpand(context)).toBe(false);
});

it('should return false when isDetails returns true', () => {
const context: any = {
navigation: {
url: '/details'
}
};

expect(app.canShowExpand(context)).toBe(false);
});
});

describe('hasLockedFiles', () => {
it('should return [false] if selection not present', () => {
const context: any = {};
Expand Down
2 changes: 1 addition & 1 deletion projects/aca-shared/rules/src/app.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export const canEditAspects = (context: RuleContext): boolean =>
repository.isMajorVersionAvailable(context, '7')
].every(Boolean);

export const canNotShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean);
export const canShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean);

/**
* Checks if user can manage permissions for the selected node.
Expand Down
32 changes: 32 additions & 0 deletions projects/aca-shared/rules/src/navigation.rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,38 @@ describe('navigation.evaluators', () => {
});
});

describe('isDetails', () => {
it('should return [true] if url ends with `/details`', () => {
const context: any = {
navigation: {
url: '/path/details'
}
};

expect(app.isDetails(context)).toBe(true);
});

it('should return [true] if url starts with `/details`', () => {
const context: any = {
navigation: {
url: '/details/path'
}
};

expect(app.isDetails(context)).toBe(true);
});

it('should return [true] if url includes with `/details`', () => {
const context: any = {
navigation: {
url: '/details/path'
}
};

expect(app.isDetails(context)).toBe(true);
});
});

describe('isRecentFiles', () => {
it('should return [true] if url starts with `/recent-files`', () => {
const context: any = {
Expand Down

0 comments on commit 85eb0ab

Please sign in to comment.