extra unit tests (#1713)

* typing fixes

* "canDownloadSelection" tests

* fix import

* move test to proper block
This commit is contained in:
Denys Vuika
2020-10-06 11:13:05 +01:00
committed by GitHub
parent 1eb85a198d
commit 8803b3ccee
3 changed files with 116 additions and 25 deletions

View File

@@ -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,7 +166,6 @@ 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 = {
@@ -150,6 +192,7 @@ describe('app.evaluators', () => {
expect(app.hasLockedFiles(context)).toBe(true); expect(app.hasLockedFiles(context)).toBe(true);
}); });
});
describe('canUpdateSelectedNode', () => { describe('canUpdateSelectedNode', () => {
it('should return [false] if selection not preset', () => { it('should return [false] if selection not preset', () => {

View 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;
}
}

View File

@@ -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: {