TSK-1349: Added unit test for classification-overview
This commit is contained in:
parent
338fedf49f
commit
5665ae2241
|
@ -9,7 +9,7 @@
|
|||
<ng-template #showEmptyPage>
|
||||
<div class="hidden-xs hidden-sm col-md-8 container-no-items">
|
||||
<div class="center-block no-detail">
|
||||
<h3 class="grey">Select a classification</h3>
|
||||
<h3 class="grey select-classification">Select a classification</h3>
|
||||
<svg-icon class="img-responsive empty-icon" src="./assets/icons/classification-empty.svg"></svg-icon>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Component, DebugElement } from '@angular/core';
|
||||
import { Actions, NgxsModule, ofActionDispatched, Store } from '@ngxs/store';
|
||||
import { ClassificationState } from '../../../shared/store/classification-store/classification.state';
|
||||
import { ClassificationOverviewComponent } from './classification-overview.component';
|
||||
import { ClassificationsService } from '../../../shared/services/classifications/classifications.service';
|
||||
import { ClassificationCategoriesService } from '../../../shared/services/classification-categories/classification-categories.service';
|
||||
import { DomainService } from '../../../shared/services/domain/domain.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import {
|
||||
CreateClassification,
|
||||
SelectClassification
|
||||
} from '../../../shared/store/classification-store/classification.actions';
|
||||
import { classificationStateMock } from '../../../shared/store/mock-data/mock-store';
|
||||
|
||||
@Component({ selector: 'taskana-administration-classification-list', template: '' })
|
||||
class ClassificationListStub {}
|
||||
|
||||
@Component({ selector: 'taskana-administration-classification-details', template: '' })
|
||||
class ClassificationDetailsStub {}
|
||||
|
||||
@Component({ selector: 'svg-icon', template: '' })
|
||||
class SvgIconStub {}
|
||||
|
||||
const routeParamsMock = { id: 'new-classification' };
|
||||
const activatedRouteMock = {
|
||||
firstChild: {
|
||||
params: of(routeParamsMock)
|
||||
}
|
||||
};
|
||||
|
||||
const classificationCategoriesServiceSpy = jest.fn();
|
||||
const classificationServiceSpy = jest.fn().mockImplementation(
|
||||
(): Partial<ClassificationsService> => ({
|
||||
getClassification: jest.fn().mockReturnValue(of()),
|
||||
getClassifications: jest.fn().mockReturnValue(of())
|
||||
})
|
||||
);
|
||||
const domainServiceSpy = jest.fn().mockImplementation(
|
||||
(): Partial<DomainService> => ({
|
||||
getSelectedDomainValue: jest.fn().mockReturnValue(of())
|
||||
})
|
||||
);
|
||||
|
||||
describe('ClassificationOverviewComponent', () => {
|
||||
let fixture: ComponentFixture<ClassificationOverviewComponent>;
|
||||
let debugElement: DebugElement;
|
||||
let component: ClassificationOverviewComponent;
|
||||
let store: Store;
|
||||
let actions$: Observable<any>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NgxsModule.forRoot([ClassificationState])],
|
||||
declarations: [ClassificationOverviewComponent, ClassificationDetailsStub, ClassificationListStub, SvgIconStub],
|
||||
providers: [
|
||||
{ provide: ClassificationsService, useClass: classificationServiceSpy },
|
||||
{ provide: ClassificationCategoriesService, useClass: classificationCategoriesServiceSpy },
|
||||
{ provide: DomainService, useClass: domainServiceSpy },
|
||||
{ provide: ActivatedRoute, useValue: activatedRouteMock }
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ClassificationOverviewComponent);
|
||||
debugElement = fixture.debugElement;
|
||||
component = fixture.debugElement.componentInstance;
|
||||
store = TestBed.inject(Store);
|
||||
actions$ = TestBed.inject(Actions);
|
||||
store.reset({
|
||||
...store.snapshot(),
|
||||
classification: classificationStateMock
|
||||
});
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create component', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should always display classification list', () => {
|
||||
expect(debugElement.nativeElement.querySelector('taskana-administration-classification-list')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display classification details when showDetail is true', () => {
|
||||
component.showDetail = true;
|
||||
fixture.detectChanges();
|
||||
expect(debugElement.nativeElement.querySelector('taskana-administration-classification-details')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should show empty page with icon and text when showDetail is false', () => {
|
||||
component.showDetail = false;
|
||||
fixture.detectChanges();
|
||||
const emptyPage = fixture.debugElement.nativeElement.querySelector('.select-classification');
|
||||
expect(emptyPage.textContent).toBe('Select a classification');
|
||||
expect(debugElement.nativeElement.querySelector('svg-icon')).toBeTruthy();
|
||||
expect(debugElement.nativeElement.querySelector('taskana-administration-classification-details')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should set routerParams property when firstChild of route exists', () => {
|
||||
expect(component.routerParams).toBe(routeParamsMock);
|
||||
});
|
||||
|
||||
it('should dispatch SelectClassification action when routerParams id exists', async () => {
|
||||
let isActionDispatched = false;
|
||||
actions$.pipe(ofActionDispatched(SelectClassification)).subscribe(() => (isActionDispatched = true));
|
||||
component.ngOnInit();
|
||||
expect(isActionDispatched).toBe(true);
|
||||
});
|
||||
|
||||
it('should dispatch CreateClassification action when routerParams id contains new-classification', async () => {
|
||||
let isActionDispatched = false;
|
||||
actions$.pipe(ofActionDispatched(CreateClassification)).subscribe(() => (isActionDispatched = true));
|
||||
component.ngOnInit();
|
||||
expect(isActionDispatched).toBe(true);
|
||||
});
|
||||
});
|
|
@ -8,14 +8,7 @@ import { ClassificationsService } from '../../../shared/services/classifications
|
|||
import { ClassificationCategoriesService } from '../../../shared/services/classification-categories/classification-categories.service';
|
||||
import { DomainService } from '../../../shared/services/domain/domain.service';
|
||||
import { MatRippleModule } from '@angular/material/core';
|
||||
|
||||
export const classificationInitState = {
|
||||
selectedClassificationType: 'Document',
|
||||
classificationTypes: {
|
||||
TASK: [],
|
||||
DOCUMENT: []
|
||||
}
|
||||
};
|
||||
import { classificationStateMock } from '../../../shared/store/mock-data/mock-store';
|
||||
|
||||
const classificationServiceSpy = jest.fn();
|
||||
const classificationCategoriesServiceSpy = jest.fn();
|
||||
|
@ -44,7 +37,7 @@ describe('ClassificationTypesSelectorComponent', () => {
|
|||
store = TestBed.inject(Store);
|
||||
store.reset({
|
||||
...store.snapshot(),
|
||||
classification: classificationInitState
|
||||
classification: classificationStateMock
|
||||
});
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
@ -55,7 +48,7 @@ describe('ClassificationTypesSelectorComponent', () => {
|
|||
|
||||
it('should display selected classification type', () => {
|
||||
const button = fixture.debugElement.nativeElement.getElementsByClassName('selected-type');
|
||||
expect(button[0].textContent.trim()).toBe('Document');
|
||||
expect(button[0].textContent.trim()).toBe('DOCUMENT');
|
||||
});
|
||||
|
||||
it('should display list of classification types', () => {
|
||||
|
|
|
@ -2,6 +2,14 @@ import { Workbasket } from '../../models/workbasket';
|
|||
import { ICONTYPES } from '../../models/icon-types';
|
||||
import { ACTION } from '../../models/action';
|
||||
|
||||
export const classificationStateMock = {
|
||||
selectedClassificationType: 'DOCUMENT',
|
||||
classificationTypes: {
|
||||
TASK: [],
|
||||
DOCUMENT: []
|
||||
}
|
||||
};
|
||||
|
||||
export const engineConfigurationMock = {
|
||||
customisation: {
|
||||
EN: {
|
||||
|
|
Loading…
Reference in New Issue