mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
extra unit tests (#1713)
* typing fixes * "canDownloadSelection" tests * fix import * move test to proper block
This commit is contained in:
@@ -24,8 +24,51 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as app from './app.rules';
|
import * as app from './app.rules';
|
||||||
|
import { TestRuleContext } from './test-rule-context';
|
||||||
|
import { NodeEntry } from '@alfresco/js-api';
|
||||||
|
|
||||||
describe('app.evaluators', () => {
|
describe('app.evaluators', () => {
|
||||||
|
describe('canDownloadSelection', () => {
|
||||||
|
it('should return [false] if selection is empty', () => {
|
||||||
|
const context = new TestRuleContext();
|
||||||
|
|
||||||
|
expect(context.selection.isEmpty).toBe(true);
|
||||||
|
expect(app.canDownloadSelection(context)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return [false] for the trashcan entries', () => {
|
||||||
|
const context = new TestRuleContext();
|
||||||
|
context.selection.isEmpty = false;
|
||||||
|
context.navigation = { url: '/trashcan' };
|
||||||
|
|
||||||
|
expect(app.canDownloadSelection(context)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow downloading files', () => {
|
||||||
|
const context = new TestRuleContext();
|
||||||
|
context.selection.isEmpty = false;
|
||||||
|
context.selection.nodes = [{ entry: { isFile: true } } as NodeEntry];
|
||||||
|
|
||||||
|
expect(app.canDownloadSelection(context)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow downloading folders', () => {
|
||||||
|
const context = new TestRuleContext();
|
||||||
|
context.selection.isEmpty = false;
|
||||||
|
context.selection.nodes = [{ entry: { isFolder: true } } as NodeEntry];
|
||||||
|
|
||||||
|
expect(app.canDownloadSelection(context)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should now allow downloading unknown selection', () => {
|
||||||
|
const context = new TestRuleContext();
|
||||||
|
context.selection.isEmpty = false;
|
||||||
|
context.selection.nodes = [{ entry: {} } as NodeEntry];
|
||||||
|
|
||||||
|
expect(app.canDownloadSelection(context)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('isWriteLocked', () => {
|
describe('isWriteLocked', () => {
|
||||||
it('should return [true] if lock type is set', () => {
|
it('should return [true] if lock type is set', () => {
|
||||||
const context: any = {
|
const context: any = {
|
||||||
@@ -123,32 +166,32 @@ describe('app.evaluators', () => {
|
|||||||
|
|
||||||
expect(app.hasLockedFiles(context)).toBe(true);
|
expect(app.hasLockedFiles(context)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should return [true] when one of files has readonly lock', () => {
|
it('should return [true] when one of files has readonly lock', () => {
|
||||||
const context: any = {
|
const context: any = {
|
||||||
selection: {
|
selection: {
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
entry: {
|
entry: {
|
||||||
isFile: true,
|
isFile: true,
|
||||||
isLocked: false
|
isLocked: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entry: {
|
entry: {
|
||||||
isFile: true,
|
isFile: true,
|
||||||
isLocked: false,
|
isLocked: false,
|
||||||
properties: {
|
properties: {
|
||||||
'cm:lockType': 'READ_ONLY_LOCK'
|
'cm:lockType': 'READ_ONLY_LOCK'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
expect(app.hasLockedFiles(context)).toBe(true);
|
expect(app.hasLockedFiles(context)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('canUpdateSelectedNode', () => {
|
describe('canUpdateSelectedNode', () => {
|
||||||
|
46
projects/aca-shared/rules/src/test-rule-context.ts
Normal file
46
projects/aca-shared/rules/src/test-rule-context.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { NavigationState, NodePermissions, ProfileState, RuleContext, RuleEvaluator, SelectionState } from '@alfresco/adf-extensions';
|
||||||
|
import { RepositoryInfo } from '@alfresco/js-api';
|
||||||
|
|
||||||
|
export class TestRuleContext implements RuleContext {
|
||||||
|
auth: any;
|
||||||
|
navigation: NavigationState = {};
|
||||||
|
permissions: NodePermissions;
|
||||||
|
profile: ProfileState;
|
||||||
|
repository: RepositoryInfo;
|
||||||
|
|
||||||
|
selection: SelectionState = {
|
||||||
|
count: 0,
|
||||||
|
nodes: [],
|
||||||
|
libraries: [],
|
||||||
|
isEmpty: true
|
||||||
|
};
|
||||||
|
|
||||||
|
getEvaluator(_key: string): RuleEvaluator {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
@@ -29,6 +29,7 @@ import { ContextMenuComponent } from './context-menu.component';
|
|||||||
import { ContextMenuModule } from './context-menu.module';
|
import { ContextMenuModule } from './context-menu.module';
|
||||||
import { ContextMenuOverlayRef } from './context-menu-overlay';
|
import { ContextMenuOverlayRef } from './context-menu-overlay';
|
||||||
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
|
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
|
||||||
|
import { ContentActionType } from '@alfresco/adf-extensions';
|
||||||
|
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -37,10 +38,11 @@ import { AppExtensionService } from '@alfresco/aca-shared';
|
|||||||
describe('ContextMenuComponent', () => {
|
describe('ContextMenuComponent', () => {
|
||||||
let fixture: ComponentFixture<ContextMenuComponent>;
|
let fixture: ComponentFixture<ContextMenuComponent>;
|
||||||
let component: ContextMenuComponent;
|
let component: ContextMenuComponent;
|
||||||
let contextMenuOverlayRef;
|
let contextMenuOverlayRef: ContextMenuOverlayRef;
|
||||||
let extensionsService;
|
let extensionsService: AppExtensionService;
|
||||||
|
|
||||||
const contextItem = {
|
const contextItem = {
|
||||||
type: 'button',
|
type: ContentActionType.button,
|
||||||
id: 'action-button',
|
id: 'action-button',
|
||||||
title: 'Test Button',
|
title: 'Test Button',
|
||||||
actions: {
|
actions: {
|
||||||
|
Reference in New Issue
Block a user