improve test datatable

This commit is contained in:
Eugenio Romano 2016-11-10 15:18:04 +00:00
parent be3174d6e3
commit ce6f89d47d
6 changed files with 126 additions and 3 deletions

View File

@ -96,7 +96,7 @@ module.exports = function (config) {
// Source files that you wanna generate coverage for. // Source files that you wanna generate coverage for.
// Do not include tests or libraries (these files will be instrumented by Istanbul) // Do not include tests or libraries (these files will be instrumented by Istanbul)
preprocessors: { preprocessors: {
'dist/**/!(*spec|index|*mock|*model).js': 'coverage' 'dist/**/!(*spec|index|*mock|*model|*interface).js': 'coverage'
}, },
coverageReporter: { coverageReporter: {

View File

@ -0,0 +1,41 @@
/*!
* @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 { NoContentTemplateComponent } from '../datatable/no-content-template.component';
import { Injector } from '@angular/core';
import { getTestBed, TestBed } from '@angular/core/testing';
import { DataTableComponent } from './datatable.component';
describe('NoContentTemplateComponent', () => {
let injector: Injector;
let noContentTemplateComponent: NoContentTemplateComponent;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
NoContentTemplateComponent,
DataTableComponent
]
});
injector = getTestBed();
noContentTemplateComponent = injector.get(NoContentTemplateComponent);
});
it('is defined', () => {
expect(noContentTemplateComponent).toBeDefined();
});
});

View File

@ -15,5 +15,5 @@
* limitations under the License. * limitations under the License.
*/ */
export * from './pagination-provider'; export * from './paginationProvider.interface';
export * from './pagination.component'; export * from './pagination.component';

View File

@ -0,0 +1,82 @@
/*!
* @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 { PaginationComponent } from '../pagination/pagination.component';
import { PaginationProvider, DataLoadedEventEmitter} from '../pagination/paginationProvider.interface';
import { Injector } from '@angular/core';
import { getTestBed, TestBed} from '@angular/core/testing';
class CustomPaginationProvider implements PaginationProvider {
skipCount: number = 0;
dataLoaded: DataLoadedEventEmitter;
count: number = 200;
hasMoreItems: boolean = false;
maxItems: number = 20;
}
describe('PaginationComponent', () => {
let injector: Injector;
let paginationComponent: PaginationComponent;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
PaginationComponent
]
});
injector = getTestBed();
paginationComponent = injector.get(PaginationComponent);
paginationComponent.provider = new CustomPaginationProvider();
});
it('is defined', () => {
expect(paginationComponent).toBeDefined();
});
it('page size', () => {
expect(paginationComponent.pageSize).toBe(20);
});
it('set page size', () => {
paginationComponent.pageSize = 100;
expect(paginationComponent.pageSize).toBe(100);
});
it('prevPageAvail', () => {
expect(paginationComponent.prevPageAvail).toBe(false);
});
it('nextPageAvail', () => {
expect(paginationComponent.nextPageAvail).toBe(false);
});
it('showNextPage', () => {
expect(paginationComponent.provider.skipCount).toBe(0);
paginationComponent.showNextPage();
expect(paginationComponent.provider.skipCount).toBe(20);
});
it('showPrevPage', () => {
paginationComponent.provider.skipCount = 100;
paginationComponent.showPrevPage();
expect(paginationComponent.provider.skipCount).toBe(80);
});
it('PaginationProvider', () => {
expect(paginationComponent.provider instanceof CustomPaginationProvider).toBeTruthy();
});
});

View File

@ -16,7 +16,7 @@
*/ */
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { PaginationProvider } from './pagination-provider'; import { PaginationProvider } from './paginationProvider.interface';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,