mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
Fixed configuration issue preventing unit tests for rules getting executed (#4466)
* Fixed configuration issue preventing unit tests for rules getting executed * Added unit tests for SnackbarEffects to improve coverage * Added unit tests for RouterEffects to improve coverage * Excluding store actions, models, selectors and states from getting included in code coverage * Added type to store
This commit is contained in:
parent
1ef1976a4c
commit
8c1d2f3cd7
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "aca-shared",
|
"name": "aca-shared",
|
||||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||||
"sourceRoot": "projects/aca-shared/src",
|
"sourceRoot": "projects/aca-shared",
|
||||||
"projectType": "library",
|
"projectType": "library",
|
||||||
"prefix": "lib",
|
"prefix": "lib",
|
||||||
"targets": {
|
"targets": {
|
||||||
@ -26,6 +26,12 @@
|
|||||||
"main": "projects/aca-shared/test.ts",
|
"main": "projects/aca-shared/test.ts",
|
||||||
"tsConfig": "projects/aca-shared/tsconfig.spec.json",
|
"tsConfig": "projects/aca-shared/tsconfig.spec.json",
|
||||||
"karmaConfig": "projects/aca-shared/karma.conf.js",
|
"karmaConfig": "projects/aca-shared/karma.conf.js",
|
||||||
|
"codeCoverageExclude": [
|
||||||
|
"projects/aca-shared/store/src/actions/**",
|
||||||
|
"projects/aca-shared/store/src/models/**",
|
||||||
|
"projects/aca-shared/store/src/selectors/**",
|
||||||
|
"projects/aca-shared/store/src/states/**"
|
||||||
|
],
|
||||||
"stylePreprocessorOptions": {
|
"stylePreprocessorOptions": {
|
||||||
"includePaths": ["node_modules"]
|
"includePaths": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
@ -1424,19 +1424,16 @@ describe('app.evaluators', () => {
|
|||||||
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when user is in libraries or trashcan or details', () => {
|
it('should return false when user is in libraries or trashcan', () => {
|
||||||
context.selection.isEmpty = false;
|
context.selection.isEmpty = false;
|
||||||
context.navigation.url = '/trashcan/test';
|
context.navigation.url = '/trashcan/test';
|
||||||
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
||||||
|
|
||||||
context.navigation.url = '/test/libraries';
|
context.navigation.url = '/test/libraries';
|
||||||
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
||||||
|
|
||||||
context.navigation.url = '/test/details';
|
|
||||||
expect(app.canShowInfoDrawer(context)).toBeFalse();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true when selection exists and user is not in trashcan, libraries or details', () => {
|
it('should return true when selection exists and user is not in trashcan, libraries', () => {
|
||||||
context.navigation.url = '/personal-files/test';
|
context.navigation.url = '/personal-files/test';
|
||||||
context.selection.isEmpty = false;
|
context.selection.isEmpty = false;
|
||||||
expect(app.canShowInfoDrawer(context)).toBeTrue();
|
expect(app.canShowInfoDrawer(context)).toBeTrue();
|
||||||
|
285
projects/aca-shared/store/src/effects/router.effects.spec.ts
Normal file
285
projects/aca-shared/store/src/effects/router.effects.spec.ts
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
/*!
|
||||||
|
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
|
import { CoreTestingModule, SnackbarContentComponent } from '@alfresco/adf-core';
|
||||||
|
import { RouterEffects } from './router.effects';
|
||||||
|
import {
|
||||||
|
AppStore,
|
||||||
|
NavigateRouteAction,
|
||||||
|
NavigateToFolder,
|
||||||
|
NavigateToParentFolder,
|
||||||
|
NavigateToPreviousPage,
|
||||||
|
NavigateUrlAction
|
||||||
|
} from '@alfresco/aca-shared/store';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Location } from '@angular/common';
|
||||||
|
import { Node } from '@alfresco/js-api';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
|
||||||
|
describe('NodeEffects', () => {
|
||||||
|
let store: Store<AppStore>;
|
||||||
|
let router: Router;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [CoreTestingModule, StoreModule.forRoot({}), EffectsModule.forRoot([RouterEffects])]
|
||||||
|
});
|
||||||
|
|
||||||
|
store = TestBed.inject(Store);
|
||||||
|
router = TestBed.inject(Router);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigateUrl$', () => {
|
||||||
|
it('should call navigateByUrl on payload', () => {
|
||||||
|
spyOn(router, 'navigateByUrl');
|
||||||
|
store.dispatch(new NavigateUrlAction('mock-route'));
|
||||||
|
expect(router.navigateByUrl).toHaveBeenCalledWith('mock-route');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigateRoute$', () => {
|
||||||
|
it('should call navigate on payload', () => {
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateRouteAction(['mock-route']));
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['mock-route']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigateToFolder$', () => {
|
||||||
|
it('should navigate to folder in personal files root when path elements are not present', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id'
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to folder inside personal files when path elements are found', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-2',
|
||||||
|
name: 'mock-name-2',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-3',
|
||||||
|
name: 'mock-name-3',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to folder nested libraries when path elements are found and are inside libraries', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-sites-id-2',
|
||||||
|
name: 'Sites',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-3',
|
||||||
|
name: 'mock-name-3',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/libraries', 'mock-id']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to libraries root when parent.name is Site', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-sites-id-2',
|
||||||
|
name: 'Sites',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/libraries', {}]);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigateToParentFolder$', () => {
|
||||||
|
it('should show error message when path elements are not found', fakeAsync(() => {
|
||||||
|
const matSnackBar = TestBed.inject(MatSnackBar);
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id'
|
||||||
|
} as Node;
|
||||||
|
spyOn(matSnackBar, 'openFromComponent');
|
||||||
|
store.dispatch(new NavigateToParentFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(matSnackBar.openFromComponent).toHaveBeenCalledWith(SnackbarContentComponent, {
|
||||||
|
panelClass: 'adf-error-snackbar',
|
||||||
|
data: {
|
||||||
|
actionLabel: undefined,
|
||||||
|
actionIcon: 'close',
|
||||||
|
actionIconAriaLabel: 'CLOSE',
|
||||||
|
message: 'APP.MESSAGES.ERRORS.CANNOT_NAVIGATE_LOCATION',
|
||||||
|
showAction: true,
|
||||||
|
callActionOnIconClick: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to folder inside personal files when path elements are found', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-2',
|
||||||
|
name: 'mock-name-2',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-3',
|
||||||
|
name: 'mock-name-3',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToParentFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'mock-id-3']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to folder nested libraries when path elements are found and are inside libraries', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-sites-id-2',
|
||||||
|
name: 'Sites',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-id-3',
|
||||||
|
name: 'mock-name-3',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToParentFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/libraries', 'mock-id-3']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should navigate to libraries root when parent.name is Site', fakeAsync(() => {
|
||||||
|
const node = {
|
||||||
|
id: 'mock-id',
|
||||||
|
path: {
|
||||||
|
name: 'mock-path-name',
|
||||||
|
elements: [
|
||||||
|
{
|
||||||
|
id: 'mock-id-1',
|
||||||
|
name: 'mock-name-1',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mock-sites-id-2',
|
||||||
|
name: 'Sites',
|
||||||
|
nodeType: 'mock-node-type'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} as Node;
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
store.dispatch(new NavigateToFolder({ entry: node }));
|
||||||
|
tick(10);
|
||||||
|
expect(router.navigate).toHaveBeenCalledWith(['/libraries', {}]);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigateToPreviousPage$', () => {
|
||||||
|
it('should navigate to previous page via location.back', () => {
|
||||||
|
const location = TestBed.inject(Location);
|
||||||
|
spyOn(location, 'back');
|
||||||
|
store.dispatch(new NavigateToPreviousPage());
|
||||||
|
expect(location.back).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,98 @@
|
|||||||
|
/*!
|
||||||
|
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { CoreTestingModule, SnackbarContentComponent } from '@alfresco/adf-core';
|
||||||
|
import { SnackbarEffects } from './snackbar.effects';
|
||||||
|
import { SnackbarErrorAction, SnackbarInfoAction, SnackbarWarningAction } from '../actions/snackbar.actions';
|
||||||
|
import { AppStore } from '@alfresco/aca-shared/store';
|
||||||
|
|
||||||
|
describe('NodeEffects', () => {
|
||||||
|
let store: Store<AppStore>;
|
||||||
|
let matSnackBar: MatSnackBar;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [CoreTestingModule, StoreModule.forRoot({}), EffectsModule.forRoot([SnackbarEffects])]
|
||||||
|
});
|
||||||
|
|
||||||
|
store = TestBed.inject(Store);
|
||||||
|
matSnackBar = TestBed.inject(MatSnackBar);
|
||||||
|
spyOn(matSnackBar, 'openFromComponent');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('infoEffect', () => {
|
||||||
|
it('should open snackbar with adf-info-snackbar panel class', () => {
|
||||||
|
store.dispatch(new SnackbarInfoAction('test-snackbar-message'));
|
||||||
|
expect(matSnackBar.openFromComponent).toHaveBeenCalledWith(SnackbarContentComponent, {
|
||||||
|
panelClass: 'adf-info-snackbar',
|
||||||
|
data: {
|
||||||
|
message: 'test-snackbar-message',
|
||||||
|
actionLabel: null,
|
||||||
|
actionIcon: 'close',
|
||||||
|
actionIconAriaLabel: 'CLOSE',
|
||||||
|
showAction: true,
|
||||||
|
callActionOnIconClick: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('warningEffect', () => {
|
||||||
|
it('should open snackbar with adf-info-snackbar panel class', () => {
|
||||||
|
store.dispatch(new SnackbarWarningAction('test-snackbar-message'));
|
||||||
|
expect(matSnackBar.openFromComponent).toHaveBeenCalledWith(SnackbarContentComponent, {
|
||||||
|
panelClass: 'adf-warning-snackbar',
|
||||||
|
data: {
|
||||||
|
message: 'test-snackbar-message',
|
||||||
|
actionLabel: null,
|
||||||
|
actionIcon: 'close',
|
||||||
|
actionIconAriaLabel: 'CLOSE',
|
||||||
|
showAction: true,
|
||||||
|
callActionOnIconClick: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('errorEffect', () => {
|
||||||
|
it('should open snackbar with adf-info-snackbar panel class', () => {
|
||||||
|
store.dispatch(new SnackbarErrorAction('test-snackbar-message'));
|
||||||
|
expect(matSnackBar.openFromComponent).toHaveBeenCalledWith(SnackbarContentComponent, {
|
||||||
|
panelClass: 'adf-error-snackbar',
|
||||||
|
data: {
|
||||||
|
message: 'test-snackbar-message',
|
||||||
|
actionLabel: null,
|
||||||
|
actionIcon: 'close',
|
||||||
|
actionIconAriaLabel: 'CLOSE',
|
||||||
|
showAction: true,
|
||||||
|
callActionOnIconClick: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user