From 840ee5185280d29eb69399771c14d8d735ae6f79 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Fri, 2 Feb 2018 11:16:02 +0000 Subject: [PATCH] [ADF-2163] fixed test and added enum for target actions --- .../app/components/files/files.component.html | 12 ++-- .../content-action.component.spec.ts | 70 ++++++++----------- .../content-action.component.ts | 14 ++-- .../models/content-action.model.ts | 6 ++ 4 files changed, 48 insertions(+), 54 deletions(-) diff --git a/demo-shell/src/app/components/files/files.component.html b/demo-shell/src/app/components/files/files.component.html index 78be33c5a3..37960fafe6 100644 --- a/demo-shell/src/app/components/files/files.component.html +++ b/demo-shell/src/app/components/files/files.component.html @@ -195,10 +195,10 @@ - + @@ -233,14 +233,14 @@ diff --git a/lib/content-services/document-list/components/content-action/content-action.component.spec.ts b/lib/content-services/document-list/components/content-action/content-action.component.spec.ts index 4c5feaa17c..f6214eeaa1 100644 --- a/lib/content-services/document-list/components/content-action/content-action.component.spec.ts +++ b/lib/content-services/document-list/components/content-action/content-action.component.spec.ts @@ -21,7 +21,7 @@ import { async, TestBed } from '@angular/core/testing'; import { ContentService } from '@alfresco/adf-core'; import { DataTableModule } from '@alfresco/adf-core'; import { MaterialModule } from '../../../material.module'; - +import { FileNode } from '../../../mock'; import { DocumentListService } from '../../services/document-list.service'; import { ContentActionHandler } from './../../models/content-action.model'; import { DocumentActionsService } from './../../services/document-actions.service'; @@ -30,6 +30,7 @@ import { NodeActionsService } from './../../services/node-actions.service'; import { DocumentListComponent } from './../document-list.component'; import { ContentActionListComponent } from './content-action-list.component'; import { ContentActionComponent } from './content-action.component'; +import { ContentActionModel } from './../../models/content-action.model'; describe('ContentAction', () => { @@ -212,20 +213,6 @@ describe('ContentAction', () => { model.execute(''); }); - // it('should sync localizable fields with model', () => { - - // let action = new ContentActionComponent(actionList, null, null); - // action.title = 'title1'; - // action.ngOnInit(); - - // expect(action.model.title).toBe(action.title); - - // action.title = 'title2'; - // action.ngOnChanges(null); - - // expect(action.model.title).toBe('title2'); - // }); - it('should not find document action handler with missing service', () => { let action = new ContentActionComponent(actionList, null, null); expect(action.getSystemHandler('document', 'name')).toBeNull(); @@ -264,32 +251,32 @@ describe('ContentAction', () => { }); - // it('should wire model with custom event handler', (done) => { - // let action = new ContentActionComponent(actionList, documentActions, folderActions); - // let file = new FileNode(); + it('should wire model with custom event handler', async(() => { + let action = new ContentActionComponent(actionList, documentActions, folderActions); + let file = new FileNode(); - // let handler = new EventEmitter(); - // handler.subscribe((e) => { - // expect(e.value).toBe(file); - // done(); - // }); + let handler = new EventEmitter(); + handler.subscribe((e) => { + expect(e.value).toBe(file); + }); - // action.execute = handler; + action.execute = handler; - // action.ngOnInit(); - // action.model.execute(file); - // }); + action.ngOnInit(); + documentList.actions[0].execute(file); + })); - // it('should allow registering model without handler', () => { - // let action = new ContentActionComponent(actionList, documentActions, folderActions); + it('should allow registering model without handler', () => { + let action = new ContentActionComponent(actionList, documentActions, folderActions); - // spyOn(actionList, 'registerAction').and.callThrough(); - // action.execute = null; - // action.ngOnInit(); + spyOn(actionList, 'registerAction').and.callThrough(); + action.execute = null; + action.handler = null; + action.target = 'document'; + action.ngOnInit(); - // expect(action.model.handler).toBeUndefined(); - // expect(actionList.registerAction).toHaveBeenCalledWith(action.model); - // }); + expect(actionList.registerAction).toHaveBeenCalledWith(documentList.actions[0]); + }); it('should register on init', () => { let action = new ContentActionComponent(actionList, null, null); @@ -299,11 +286,12 @@ describe('ContentAction', () => { expect(action.register).toHaveBeenCalled(); }); - // it('should require action list to register action with', () => { - // let action = new ContentActionComponent(actionList, null, null); - // expect(action.register()).toBeTruthy(); + it('should require action list to register action with', () => { + const fakeModel = new ContentActionModel(); + let action = new ContentActionComponent(actionList, null, null); + expect(action.register(fakeModel)).toBeTruthy(); - // action = new ContentActionComponent(null, null, null); - // expect(action.register()).toBeFalsy(); - // }); + action = new ContentActionComponent(null, null, null); + expect(action.register(fakeModel)).toBeFalsy(); + }); }); diff --git a/lib/content-services/document-list/components/content-action/content-action.component.ts b/lib/content-services/document-list/components/content-action/content-action.component.ts index d3edea6980..ed7becc777 100644 --- a/lib/content-services/document-list/components/content-action/content-action.component.ts +++ b/lib/content-services/document-list/components/content-action/content-action.component.ts @@ -22,7 +22,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ContentActionHandler } from '../../models/content-action.model'; import { DocumentActionsService } from '../../services/document-actions.service'; import { FolderActionsService } from '../../services/folder-actions.service'; -import { ContentActionModel } from './../../models/content-action.model'; +import { ContentActionModel, ContentActionTarget } from './../../models/content-action.model'; import { ContentActionListComponent } from './content-action-list.component'; @Component({ @@ -49,7 +49,7 @@ export class ContentActionComponent implements OnInit { /** Type of item that the action appies to. Can be "document" or "folder" */ @Input() - target: string = 'all'; + target: string = ContentActionTarget.All; /** The permission type. */ @Input() @@ -90,9 +90,9 @@ export class ContentActionComponent implements OnInit { } ngOnInit() { - if (this.target === 'all') { - this.generateAction('folder'); - this.generateAction('document'); + if (this.target === ContentActionTarget.All) { + this.generateAction(ContentActionTarget.Folder); + this.generateAction(ContentActionTarget.Document); } else { this.generateAction(this.target); } @@ -131,7 +131,7 @@ export class ContentActionComponent implements OnInit { if (target) { let ltarget = target.toLowerCase(); - if (ltarget === 'document') { + if (ltarget === ContentActionTarget.Document) { if (this.documentActions) { this.documentActions.permissionEvent.subscribe((permission) => { this.permissionEvent.emit(permission); @@ -150,7 +150,7 @@ export class ContentActionComponent implements OnInit { return null; } - if (ltarget === 'folder') { + if (ltarget === ContentActionTarget.Folder) { if (this.folderActions) { this.folderActions.permissionEvent.subscribe((permission) => { this.permissionEvent.emit(permission); diff --git a/lib/content-services/document-list/models/content-action.model.ts b/lib/content-services/document-list/models/content-action.model.ts index 57938a1abb..54e113a306 100644 --- a/lib/content-services/document-list/models/content-action.model.ts +++ b/lib/content-services/document-list/models/content-action.model.ts @@ -39,6 +39,12 @@ export class ContentActionModel { } } +export enum ContentActionTarget { + Document = 'document', + Folder = 'folder', + All = 'all' +} + export type ContentActionHandler = (obj: any, target?: any, permission?: string) => any; export class DocumentActionModel extends ContentActionModel {