mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Improve test cases
This commit is contained in:
parent
5a354c783d
commit
c1d50a1c7d
@ -32,10 +32,6 @@ export class AlfrescoSettingsServiceMock {
|
|||||||
return this._host;
|
return this._host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set host(value: string) {
|
|
||||||
this._host = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
getApiBaseUrl(): string {
|
getApiBaseUrl(): string {
|
||||||
return this._host + this._contextPath + this._apiBasePath;
|
return this._host + this._contextPath + this._apiBasePath;
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,11 @@ export class UploadServiceMock extends UploadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addToQueue(files: any[]): FileModel[] {
|
addToQueue(files: any[]): FileModel[] {
|
||||||
|
let result = super.addToQueue(files);
|
||||||
this.filesUpload$ = new Observable(observer => {
|
this.filesUpload$ = new Observable(observer => {
|
||||||
observer.next(files);
|
observer.next(files);
|
||||||
});
|
});
|
||||||
return files;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
createFolder(relativePath: string, name: string) {
|
createFolder(relativePath: string, name: string) {
|
||||||
@ -46,8 +47,10 @@ export class UploadServiceMock extends UploadService {
|
|||||||
promise = new Promise(function (resolve, reject) {
|
promise = new Promise(function (resolve, reject) {
|
||||||
resolve({
|
resolve({
|
||||||
entry: {
|
entry: {
|
||||||
userId: 'fake-username',
|
isFile: false,
|
||||||
id: 'fake-post-token'
|
isFolder: true,
|
||||||
|
name: name,
|
||||||
|
nodeType: 'cm:folder'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -105,4 +105,93 @@ describe('AlfrescoUploadDragArea', () => {
|
|||||||
expect(component._showUndoNotificationBar).toHaveBeenCalled();
|
expect(component._showUndoNotificationBar).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should upload a file when dropped', done => {
|
||||||
|
let component = componentFixture.componentInstance;
|
||||||
|
component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
|
||||||
|
component.onSuccess = null;
|
||||||
|
|
||||||
|
componentFixture.detectChanges();
|
||||||
|
spyOn(component._uploaderService, 'uploadFilesInTheQueue');
|
||||||
|
spyOn(component, '_showUndoNotificationBar').and.callFake( () => {
|
||||||
|
expect(component._showUndoNotificationBar).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
let itemEntity = {
|
||||||
|
fullPath: '/folder-fake/file-fake.png',
|
||||||
|
isDirectory: false,
|
||||||
|
isFile: true,
|
||||||
|
name: 'file-fake.png',
|
||||||
|
file: (callbackFile) => {
|
||||||
|
let fileFake = new File(['fakefake'], 'file-fake.png', {type: 'image/png'});
|
||||||
|
callbackFile(fileFake);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFilesEntityDropped(itemEntity);
|
||||||
|
expect(component._uploaderService.uploadFilesInTheQueue)
|
||||||
|
.toHaveBeenCalledWith('/root-fake-/sites-fake/document-library-fake/folder-fake/', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throws an exception and show it in the notification bar when the folder already exist', done => {
|
||||||
|
let component = componentFixture.componentInstance;
|
||||||
|
component.currentFolderPath = '/root-fake-/sites-fake/folder-fake';
|
||||||
|
component.showUdoNotificationBar = true;
|
||||||
|
|
||||||
|
componentFixture.detectChanges();
|
||||||
|
spyOn(component, '_showErrorNotificationBar').and.callFake( () => {
|
||||||
|
expect(component._showErrorNotificationBar).toHaveBeenCalledWith('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
let folderEntry = {
|
||||||
|
fullPath: '/folder-duplicate-fake',
|
||||||
|
isDirectory: true,
|
||||||
|
isFile: false,
|
||||||
|
name: 'folder-duplicate-fake'
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFolderEntityDropped(folderEntry);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a folder and call onFilesEntityDropped with the file inside the folder', done => {
|
||||||
|
let component = componentFixture.componentInstance;
|
||||||
|
component.currentFolderPath = '/root-fake-/sites-fake/document-library-fake';
|
||||||
|
component.onSuccess = null;
|
||||||
|
|
||||||
|
componentFixture.detectChanges();
|
||||||
|
|
||||||
|
let itemEntity = {
|
||||||
|
fullPath: '/folder-fake/file-fake.png',
|
||||||
|
isDirectory: false,
|
||||||
|
isFile: true,
|
||||||
|
name: 'file-fake.png',
|
||||||
|
file: (callbackFile) => {
|
||||||
|
let fileFake = new File(['fakefake'], 'file-fake.png', {type: 'image/png'});
|
||||||
|
callbackFile(fileFake);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(component, 'onFilesEntityDropped').and.callFake( () => {
|
||||||
|
expect(component.onFilesEntityDropped).toHaveBeenCalledWith(itemEntity);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
let folderEntry = {
|
||||||
|
fullPath: '/folder-fake',
|
||||||
|
isDirectory: true,
|
||||||
|
isFile: false,
|
||||||
|
name: 'folder-fake',
|
||||||
|
createReader: () => {
|
||||||
|
return {
|
||||||
|
readEntries: (callback) => {
|
||||||
|
let entries = [itemEntity, itemEntity];
|
||||||
|
callback(entries);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFolderEntityDropped(folderEntry);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,110 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { describe, expect, beforeEach, it } from '@angular/core/testing';
|
||||||
|
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||||
|
|
||||||
|
describe('AlfrescoDirectiveFileDraggable', () => {
|
||||||
|
|
||||||
|
let component;
|
||||||
|
|
||||||
|
beforeEach( () => {
|
||||||
|
component = new FileDraggableDirective();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit onFolderEntityDropped event when a folder is dragged with Chrome' , (done) => {
|
||||||
|
|
||||||
|
let itemEntity = {
|
||||||
|
fullPath: '/folder-fake',
|
||||||
|
isDirectory: true,
|
||||||
|
isFile: false,
|
||||||
|
name: 'folder-fake'
|
||||||
|
};
|
||||||
|
let fakeEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
items: [{
|
||||||
|
webkitGetAsEntry: () => {
|
||||||
|
return itemEntity;
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
stopPropagation: jasmine.createSpy('stopPropagation'),
|
||||||
|
preventDefault: jasmine.createSpy('preventDefault')
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFolderEntityDropped.subscribe(files => {
|
||||||
|
expect(files).toEqual(itemEntity);
|
||||||
|
expect(component.getInputFocus()).toBe(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component._onDropFiles(fakeEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit onFilesDropped event when a file is dragged not with Chrome' , (done) => {
|
||||||
|
let file = {name: 'fake-name-1', size: 10, webkitRelativePath: 'fake-folder1/fake-name-1.json'};
|
||||||
|
let fakeEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
files: [file]
|
||||||
|
},
|
||||||
|
stopPropagation: jasmine.createSpy('stopPropagation'),
|
||||||
|
preventDefault: jasmine.createSpy('preventDefault')
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFilesDropped.subscribe(files => {
|
||||||
|
expect(files).toEqual([file]);
|
||||||
|
expect(component.getInputFocus()).toBe(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component._onDropFiles(fakeEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit onFilesDropped event when a file is dragged with Chrome', (done) => {
|
||||||
|
let file = {name: 'fake-name-2', size: 10, webkitRelativePath: 'fake-folder1/fake-name-2.json'};
|
||||||
|
let fakeEvent = {
|
||||||
|
dataTransfer: {
|
||||||
|
items: [''],
|
||||||
|
files: [file]
|
||||||
|
},
|
||||||
|
stopPropagation: jasmine.createSpy('stopPropagation'),
|
||||||
|
preventDefault: jasmine.createSpy('preventDefault')
|
||||||
|
};
|
||||||
|
|
||||||
|
component.onFilesDropped.subscribe(files => {
|
||||||
|
expect(files).toEqual([file]);
|
||||||
|
expect(component.getInputFocus()).toBe(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component._onDropFiles(fakeEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should take the focus when the drag enter is called', () => {
|
||||||
|
let mockEvent = new Event('dragstart');
|
||||||
|
spyOn(mockEvent, 'preventDefault');
|
||||||
|
|
||||||
|
expect(component.getInputFocus()).toBe(false);
|
||||||
|
component._onDragEnter(mockEvent);
|
||||||
|
expect(component.getInputFocus()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Directive, ElementRef, EventEmitter, Output } from '@angular/core';
|
import { Directive, EventEmitter, Output } from '@angular/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [file-draggable]
|
* [file-draggable]
|
||||||
@ -53,8 +53,7 @@ export class FileDraggableDirective {
|
|||||||
|
|
||||||
private _inputFocusClass: boolean = false;
|
private _inputFocusClass: boolean = false;
|
||||||
|
|
||||||
constructor(public el: ElementRef) {
|
constructor() {
|
||||||
console.log('FileDraggableComponent constructor', el);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,12 +67,13 @@ export class FileDraggableDirective {
|
|||||||
let items = $event.dataTransfer.items;
|
let items = $event.dataTransfer.items;
|
||||||
if (items) {
|
if (items) {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
let item = items[i].webkitGetAsEntry();
|
if (typeof items[i].webkitGetAsEntry !== 'undefined') {
|
||||||
if (item) {
|
let item = items[i].webkitGetAsEntry();
|
||||||
this._traverseFileTree(item);
|
if (item) {
|
||||||
|
this._traverseFileTree(item);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let dt = $event.dataTransfer;
|
let files = $event.dataTransfer.files;
|
||||||
let files = dt.files;
|
|
||||||
this.onFilesDropped.emit(files);
|
this.onFilesDropped.emit(files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,4 +144,13 @@ export class FileDraggableDirective {
|
|||||||
$event.stopPropagation();
|
$event.stopPropagation();
|
||||||
$event.preventDefault();
|
$event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the value of input focus class
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
getInputFocus () {
|
||||||
|
return this._inputFocusClass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user