Skip to content

Commit

Permalink
ACS-6252 Unit tests for changes for AppExtensionService
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderSklorz committed Nov 21, 2023
1 parent ac5889f commit 924ceff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
49 changes: 46 additions & 3 deletions projects/aca-shared/src/lib/services/app.extension.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,14 @@ describe('AppExtensionService', () => {
});

describe('search', () => {
let config: ExtensionConfig;

beforeEach(() => {
extensions.setEvaluators({
visible: () => true,
notVisible: () => false
});

applyConfig({
config = {
$id: 'test',
$name: 'test',
$version: '1.0.0',
Expand Down Expand Up @@ -1105,22 +1106,64 @@ describe('AppExtensionService', () => {
}
]
}
});
};
});

it('should load the search extension', () => {
applyConfig(config);
expect(service.search.length).toBe(2);
expect(service.search[0].id).toBe('app.search');
expect(service.search[1].id).toBe('app.search-1');
});

it('should not load the disabled search extension', () => {
applyConfig(config);
expect(service.search.find(({ id }) => id === 'app.search-2')).toBe(undefined, 'disabled configuration shown in the result');
});

it('should not load the not visible search extension', () => {
applyConfig(config);
expect(service.search.find(({ id }) => id === 'app.search-3')).toBe(undefined, 'not visible configuration shown in the result');
});

it('should contain category if it has no rules field', () => {
applyConfig(config);
const search = service.search[0];
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});

it('should contain category if it has no visible field in rules', () => {
config.features.search[0].categories[0].rules = {};

applyConfig(config);
const search = service.search[0];
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});

it('should contain category if it has visible field and extensions.evaluateRule returns true', () => {
spyOn(extensions, 'evaluateRule').and.returnValue(true);
const visible = 'test';
config.features.search[0].categories[0].rules = { visible };

applyConfig(config);
const search = service.search[0];
expect(extensions.evaluateRule).toHaveBeenCalledWith(visible, service);
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});

it('should not contain category if it has visible field and extensions.evaluateRule returns false', () => {
spyOn(extensions, 'evaluateRule').and.returnValue(false);
const visible = 'test';
config.features.search[0].categories[0].rules = { visible };

applyConfig(config);
const search = service.search[0];
expect(extensions.evaluateRule).toHaveBeenCalledWith(visible, service);
expect(search.categories.length).toBe(0);
});
});

describe('rules', () => {
Expand Down
8 changes: 4 additions & 4 deletions projects/aca-shared/src/lib/services/app.extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { ViewerRules } from '../models/viewer.rules';
import { Badge, SettingsGroupRef } from '../models/types';
import { NodePermissionService } from '../services/node-permission.service';
import { filter, map } from 'rxjs/operators';
import { SearchCategory, SearchConfiguration } from '@alfresco/adf-content-services';
import { SearchCategory } from '@alfresco/adf-content-services';

@Injectable({
providedIn: 'root'
Expand All @@ -67,7 +67,7 @@ export class AppExtensionService implements RuleContext {
navbar: Array<NavBarGroupRef> = [];
sidebarTabs: Array<SidebarTabRef> = [];
contentMetadata: any;
search: SearchConfiguration[];
search: any;
viewerRules: ViewerRules = {};
settingGroups: Array<SettingsGroupRef> = [];

Expand Down Expand Up @@ -168,8 +168,8 @@ export class AppExtensionService implements RuleContext {
this.sidebarTabs = this.loader.getElements<SidebarTabRef>(config, 'features.sidebar.tabs');
this.contentMetadata = this.loadContentMetadata(config);
this.search = this.loadSearchForms(config);
this.search.forEach((searchSet) => {
searchSet.categories = searchSet.categories.filter((category) => this.filterVisible(category));
this.search?.forEach((searchSet) => {
searchSet.categories = searchSet.categories?.filter((category) => this.filterVisible(category));
});

this.documentListPresets = {
Expand Down

0 comments on commit 924ceff

Please sign in to comment.