TSK-1349: Added unit test for classification-types-selector component
This commit is contained in:
parent
008c1aec20
commit
e0a99bc9a9
|
@ -186,7 +186,7 @@ describe('AccessItemsManagementComponent', () => {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should display a dialog in when access is revoked', async(() => {
|
it('should display a dialog when access is revoked', async(() => {
|
||||||
app.accessIdSelected = '';
|
app.accessIdSelected = '';
|
||||||
const notificationService = TestBed.inject(NotificationService);
|
const notificationService = TestBed.inject(NotificationService);
|
||||||
const showDialogSpy = jest.spyOn(notificationService, 'showDialog').mockImplementation();
|
const showDialogSpy = jest.spyOn(notificationService, 'showDialog').mockImplementation();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="dropdown clearfix btn-group">
|
<div class="dropdown clearfix btn-group">
|
||||||
<button type="button" class="btn btn-default"> {{classificationTypeSelected$ | async}}</button>
|
<button type="button" class="btn btn-default selected-type"> {{classificationTypeSelected$ | async}}</button>
|
||||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
|
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
|
||||||
aria-expanded="false">
|
aria-expanded="false">
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
|
@ -7,9 +7,11 @@
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu dropdown-menu-right popup" aria-labelledby="sortingDropdown">
|
<div class="dropdown-menu dropdown-menu-right popup" aria-labelledby="sortingDropdown">
|
||||||
<mat-radio-group name="classificationTypeSelector" color="accent" class="radio-group">
|
<mat-radio-group name="classificationTypeSelector" color="accent" class="radio-group">
|
||||||
<mat-radio-button *ngFor="let classificationType of classificationTypes$ | async"
|
<mat-radio-button class="classification-types" *ngFor="let classificationType of classificationTypes$ | async"
|
||||||
name="classificationTypeSelector" id="select-{{classificationType}}" [checked]="classificationType === (classificationTypeSelected$ | async)"
|
name="classificationTypeSelector" id="select-{{classificationType}}" [checked]="classificationType === (classificationTypeSelected$ | async)"
|
||||||
(change)="select(classificationType)" [value]="classificationType">{{classificationType}}</mat-radio-button>
|
(change)="select(classificationType)" [value]="classificationType">
|
||||||
|
{{classificationType}}
|
||||||
|
</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { ClassificationTypesSelectorComponent } from './classification-types-selector.component';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { DebugElement } from '@angular/core';
|
||||||
|
import { NgxsModule, Store } from '@ngxs/store';
|
||||||
|
import { ClassificationState } from '../../../shared/store/classification-store/classification.state';
|
||||||
|
import { MatRadioButton, MatRadioGroup } from '@angular/material/radio';
|
||||||
|
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 { MatRippleModule } from '@angular/material/core';
|
||||||
|
|
||||||
|
export const classificationInitState = {
|
||||||
|
selectedClassificationType: 'Document',
|
||||||
|
classificationTypes: {
|
||||||
|
TASK: [],
|
||||||
|
DOCUMENT: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const classificationServiceSpy = jest.fn();
|
||||||
|
const classificationCategoriesServiceSpy = jest.fn();
|
||||||
|
const domainServiceSpy = jest.fn();
|
||||||
|
|
||||||
|
describe('ClassificationTypesSelectorComponent', () => {
|
||||||
|
let fixture: ComponentFixture<ClassificationTypesSelectorComponent>;
|
||||||
|
let debugElement: DebugElement;
|
||||||
|
let app: ClassificationTypesSelectorComponent;
|
||||||
|
let store: Store;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [NgxsModule.forRoot([ClassificationState]), MatRippleModule],
|
||||||
|
declarations: [ClassificationTypesSelectorComponent, MatRadioButton, MatRadioGroup],
|
||||||
|
providers: [
|
||||||
|
{ provide: ClassificationsService, useClass: classificationServiceSpy },
|
||||||
|
{ provide: ClassificationCategoriesService, useClass: classificationCategoriesServiceSpy },
|
||||||
|
{ provide: DomainService, useClass: domainServiceSpy }
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(ClassificationTypesSelectorComponent);
|
||||||
|
debugElement = fixture.debugElement;
|
||||||
|
app = fixture.debugElement.componentInstance;
|
||||||
|
store = TestBed.inject(Store);
|
||||||
|
store.reset({
|
||||||
|
...store.snapshot(),
|
||||||
|
classification: classificationInitState
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the app', () => {
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display selected classification type', () => {
|
||||||
|
const button = fixture.debugElement.nativeElement.getElementsByClassName('selected-type');
|
||||||
|
expect(button[0].textContent.trim()).toBe('Document');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display list of classification types', () => {
|
||||||
|
const radioButtons = fixture.debugElement.nativeElement.getElementsByClassName('classification-types');
|
||||||
|
expect(radioButtons.length).toBe(2);
|
||||||
|
expect(radioButtons[0].textContent.trim()).toBe('TASK');
|
||||||
|
expect(radioButtons[1].textContent.trim()).toBe('DOCUMENT');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue