mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Merge pull request #670 from Alfresco/dev-eromano-testDocImprove
improve test coverage document-list.service
This commit is contained in:
commit
3d7a137427
@ -4,7 +4,7 @@ module.exports = function (config) {
|
||||
var configuration = {
|
||||
basePath: '.',
|
||||
|
||||
frameworks: [/*'jasmine-ajax',*/ 'jasmine'],
|
||||
frameworks: ['jasmine-ajax', 'jasmine'],
|
||||
|
||||
files: [
|
||||
// paths loaded by Karma
|
||||
@ -65,7 +65,7 @@ module.exports = function (config) {
|
||||
plugins: [
|
||||
'karma-jasmine',
|
||||
'karma-coverage',
|
||||
//'karma-jasmine-ajax',
|
||||
'karma-jasmine-ajax',
|
||||
'karma-chrome-launcher',
|
||||
'karma-mocha-reporter',
|
||||
'karma-jasmine-html-reporter'
|
||||
|
@ -88,8 +88,9 @@
|
||||
"karma-coverage": "1.0.0",
|
||||
"karma-coveralls": "1.1.2",
|
||||
"karma-jasmine": "1.0.2",
|
||||
"karma-mocha-reporter": "2.0.3",
|
||||
"karma-jasmine-ajax": "^0.1.13",
|
||||
"karma-jasmine-html-reporter": "0.2.0",
|
||||
"karma-mocha-reporter": "2.0.3",
|
||||
"license-check": "1.1.5",
|
||||
"remap-istanbul": "0.6.3",
|
||||
"rimraf": "2.5.2",
|
||||
|
@ -15,21 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
it,
|
||||
describe,
|
||||
expect,
|
||||
beforeEach
|
||||
} from '@angular/core/testing';
|
||||
import { it, describe, expect, beforeEach } from '@angular/core/testing';
|
||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import { DocumentActionsService } from './document-actions.service';
|
||||
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
import {
|
||||
FileNode,
|
||||
FolderNode
|
||||
} from '../assets/document-library.model.mock';
|
||||
import { FileNode, FolderNode } from '../assets/document-library.model.mock';
|
||||
|
||||
describe('DocumentActionsService', () => {
|
||||
|
||||
|
@ -15,23 +15,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
it,
|
||||
describe,
|
||||
expect,
|
||||
beforeEach
|
||||
} from '@angular/core/testing';
|
||||
import {
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoAuthenticationService,
|
||||
AlfrescoContentService,
|
||||
AlfrescoApiService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { it, describe, expect, beforeEach, afterEach } from '@angular/core/testing';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoContentService , AlfrescoApiService} from 'ng2-alfresco-core';
|
||||
import { FileNode } from '../assets/document-library.model.mock';
|
||||
import { ReflectiveInjector } from '@angular/core';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('DocumentListService', () => {
|
||||
|
||||
let injector;
|
||||
@ -52,6 +44,11 @@ describe('DocumentListService', () => {
|
||||
authService = injector.get(AlfrescoAuthenticationService);
|
||||
contentService = new AlfrescoContentService(authService);
|
||||
service = new DocumentListService(authService, contentService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should require node to get thumbnail url', () => {
|
||||
@ -86,4 +83,59 @@ describe('DocumentListService', () => {
|
||||
expect(service.getMimeTypeIcon('missing/type')).toBe(DocumentListService.DEFAULT_MIME_TYPE_ICON);
|
||||
});
|
||||
|
||||
it('Delete node should perform request against the server', (done) => {
|
||||
service.deleteNode('fake-node-id').subscribe(e => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url)
|
||||
.toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id');
|
||||
expect(jasmine.Ajax.requests.mostRecent().method)
|
||||
.toBe('DELETE');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200
|
||||
});
|
||||
});
|
||||
|
||||
it('Get folder should perform request against the server', (done) => {
|
||||
service.getFolder('fake-node-id').subscribe(e => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url)
|
||||
.toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/' +
|
||||
'children?include=path&relativePath=fake-node-id');
|
||||
expect(jasmine.Ajax.requests.mostRecent().method)
|
||||
.toBe('GET');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200
|
||||
});
|
||||
});
|
||||
|
||||
it('Get folder should perform request against the server with options', (done) => {
|
||||
service.getFolder('fake-node-id', {maxItems: 10}).subscribe(e => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url)
|
||||
.toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/' +
|
||||
'children?maxItems=10&include=path&relativePath=fake-node-id');
|
||||
expect(jasmine.Ajax.requests.mostRecent().method)
|
||||
.toBe('GET');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200
|
||||
});
|
||||
});
|
||||
|
||||
it('Get folder should perform error catch', (done) => {
|
||||
service.getFolder('fake-node-id', {maxItems: 10}).subscribe(() => {
|
||||
},
|
||||
() => {
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 403
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -58,10 +58,7 @@ export class DocumentListService {
|
||||
'application/vnd.apple.numbers': 'ft_ic_spreadsheet.svg'
|
||||
};
|
||||
|
||||
constructor(
|
||||
private authService: AlfrescoAuthenticationService,
|
||||
private contentService: AlfrescoContentService
|
||||
) {
|
||||
constructor(private authService: AlfrescoAuthenticationService, private contentService: AlfrescoContentService) {
|
||||
}
|
||||
|
||||
private getAlfrescoApi(): AlfrescoJsApi {
|
||||
|
@ -15,18 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
it,
|
||||
describe,
|
||||
expect,
|
||||
beforeEach
|
||||
} from '@angular/core/testing';
|
||||
import { it, describe, expect, beforeEach } from '@angular/core/testing';
|
||||
import { FolderActionsService } from './folder-actions.service';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import {
|
||||
FileNode,
|
||||
FolderNode
|
||||
} from '../assets/document-library.model.mock';
|
||||
import { FileNode, FolderNode } from '../assets/document-library.model.mock';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||
|
||||
@ -41,7 +33,8 @@ describe('FolderActionsService', () => {
|
||||
});
|
||||
|
||||
it('should register custom action handler', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
service.setHandler('<key>', handler);
|
||||
expect(service.getHandler('<key>')).toBe(handler);
|
||||
});
|
||||
@ -51,7 +44,8 @@ describe('FolderActionsService', () => {
|
||||
});
|
||||
|
||||
it('should be case insensitive for keys', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
service.setHandler('<key>', handler);
|
||||
expect(service.getHandler('<KEY>')).toBe(handler);
|
||||
});
|
||||
@ -76,7 +70,8 @@ describe('FolderActionsService', () => {
|
||||
});
|
||||
|
||||
it('should set new handler only by key', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
expect(service.setHandler(null, handler)).toBeFalsy();
|
||||
expect(service.setHandler('', handler)).toBeFalsy();
|
||||
expect(service.setHandler('my-handler', handler)).toBeTruthy();
|
||||
@ -145,5 +140,4 @@ describe('FolderActionsService', () => {
|
||||
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||
expect(target.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user