diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts
index 0c22cfd6f..42aba8837 100644
--- a/projects/aca-shared/rules/src/app.rules.spec.ts
+++ b/projects/aca-shared/rules/src/app.rules.spec.ts
@@ -24,8 +24,51 @@
*/
import * as app from './app.rules';
+import { TestRuleContext } from './test-rule-context';
+import { NodeEntry } from '@alfresco/js-api';
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', () => {
it('should return [true] if lock type is set', () => {
const context: any = {
@@ -123,32 +166,32 @@ describe('app.evaluators', () => {
expect(app.hasLockedFiles(context)).toBe(true);
});
- });
- it('should return [true] when one of files has readonly lock', () => {
- const context: any = {
- selection: {
- nodes: [
- {
- entry: {
- isFile: true,
- isLocked: false
- }
- },
- {
- entry: {
- isFile: true,
- isLocked: false,
- properties: {
- 'cm:lockType': 'READ_ONLY_LOCK'
+ it('should return [true] when one of files has readonly lock', () => {
+ const context: any = {
+ selection: {
+ nodes: [
+ {
+ entry: {
+ isFile: true,
+ isLocked: false
+ }
+ },
+ {
+ entry: {
+ isFile: true,
+ isLocked: false,
+ properties: {
+ 'cm:lockType': 'READ_ONLY_LOCK'
+ }
}
}
- }
- ]
- }
- };
+ ]
+ }
+ };
- expect(app.hasLockedFiles(context)).toBe(true);
+ expect(app.hasLockedFiles(context)).toBe(true);
+ });
});
describe('canUpdateSelectedNode', () => {
diff --git a/projects/aca-shared/rules/src/test-rule-context.ts b/projects/aca-shared/rules/src/test-rule-context.ts
new file mode 100644
index 000000000..125952114
--- /dev/null
+++ b/projects/aca-shared/rules/src/test-rule-context.ts
@@ -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 .
+ */
+
+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;
+ }
+}
diff --git a/src/app/components/context-menu/context-menu.component.spec.ts b/src/app/components/context-menu/context-menu.component.spec.ts
index b0e43b695..3861c0c4c 100644
--- a/src/app/components/context-menu/context-menu.component.spec.ts
+++ b/src/app/components/context-menu/context-menu.component.spec.ts
@@ -29,6 +29,7 @@ import { ContextMenuComponent } from './context-menu.component';
import { ContextMenuModule } from './context-menu.module';
import { ContextMenuOverlayRef } from './context-menu-overlay';
import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
+import { ContentActionType } from '@alfresco/adf-extensions';
import { of } from 'rxjs';
import { Store } from '@ngrx/store';
@@ -37,10 +38,11 @@ import { AppExtensionService } from '@alfresco/aca-shared';
describe('ContextMenuComponent', () => {
let fixture: ComponentFixture;
let component: ContextMenuComponent;
- let contextMenuOverlayRef;
- let extensionsService;
+ let contextMenuOverlayRef: ContextMenuOverlayRef;
+ let extensionsService: AppExtensionService;
+
const contextItem = {
- type: 'button',
+ type: ContentActionType.button,
id: 'action-button',
title: 'Test Button',
actions: {