Skip to content

Commit

Permalink
[CYB-201] [UI][COMPONENT] Fixed Karma Unit tests.
Browse files Browse the repository at this point in the history
* Fixed some test and lint problems.
  • Loading branch information
vpavlenko-cv committed Apr 1, 2024
1 parent 1abeec2 commit bd3998f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {LiveViewResultComponent} from "./live-view-result/live-view-result.compo
import {LiveViewConsts} from "./live-view.consts";
import {NzFormModule} from "ng-zorro-antd/form";
import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from "@angular/core";
import {ChainDetailsModel} from "../../chain-page.models";


describe('LiveViewComponent', () => {
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('LiveViewComponent', () => {

fixture = TestBed.createComponent(LiveViewComponent);
component = fixture.componentInstance;
component.chainConfig$ = new Subject<unknown>();
component.chainConfig$ = new Subject<ChainDetailsModel>();
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,31 @@ describe('live-view.effects', () => {
];

const actions$ = new Subject<Action>();
let liveViewEffects: LiveViewEffects;
let fakeLiveViewService: LiveViewService;
let fakeMessageService: NzMessageService;
let liveViewEffects: jasmine.SpyObj<LiveViewEffects>;
let fakeLiveViewService: jasmine.SpyObj<LiveViewService>;
let fakeMessageService: jasmine.SpyObj<NzMessageService>;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
LiveViewEffects,
{ provide: LiveViewService, useValue: jasmine.createSpyObj('LiveViewService', ['execute']) },
{ provide: LiveViewService, useValue: jasmine.createSpyObj('LiveViewService', {
execute: of({results: testResult})
}) },
{ provide: NzMessageService, useValue: jasmine.createSpyObj('NzMessageService', ['create']) },

provideMockActions(() => actions$)],
});

liveViewEffects = TestBed.inject(LiveViewEffects);
fakeLiveViewService = TestBed.inject(LiveViewService);
fakeMessageService = TestBed.inject(NzMessageService);
liveViewEffects = TestBed.inject(LiveViewEffects) as jasmine.SpyObj<LiveViewEffects>;
fakeLiveViewService = TestBed.inject(LiveViewService) as jasmine.SpyObj<LiveViewService>;
fakeMessageService = TestBed.inject(NzMessageService) as jasmine.SpyObj<NzMessageService>;
});

it('should call liveViewService.execute on executionTriggered', () => {
const testSubscriber = jasmine.createSpy('executionTriggeredSpy');
liveViewEffects.execute$.subscribe(testSubscriber);

spyOn(fakeLiveViewService, 'execute').and.returnValue(
of({results: testResult})
);

actions$.next(executionTriggered({ ...testPayload }));

expect(fakeLiveViewService.execute).toHaveBeenCalledWith(testPayload.sampleData, testPayload.chainConfig);
Expand All @@ -91,10 +89,6 @@ describe('live-view.effects', () => {
const testSubscriber = jasmine.createSpy('executionTriggeredSpy');
liveViewEffects.execute$.subscribe(testSubscriber);

spyOn(fakeLiveViewService, 'execute').and.returnValue(
of({results: testResult})
);

actions$.next(executionTriggered({ ...testPayload }));

expect(testSubscriber).toHaveBeenCalledWith({
Expand All @@ -109,7 +103,7 @@ describe('live-view.effects', () => {
const testSubscriber = jasmine.createSpy('executionTriggeredSpy');
liveViewEffects.execute$.subscribe(testSubscriber);

spyOn(fakeLiveViewService, 'execute').and.returnValue(throwError({ message: 'something went wrong' }));
fakeLiveViewService.execute.and.returnValue(throwError({ message: 'something went wrong' }));

actions$.next(executionTriggered({ ...testPayload }));

Expand All @@ -122,8 +116,7 @@ describe('live-view.effects', () => {
});

it('should show error message if liveViewService execution fail', () => {
spyOn(fakeLiveViewService, 'execute').and.returnValue(throwError({ message: 'something went wrong' }));
spyOn(fakeMessageService, 'create');
fakeLiveViewService.execute.and.returnValue(throwError({ message: 'something went wrong' }));

liveViewEffects.execute$.subscribe();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h4>
</nz-timeline-item>
</nz-timeline>
<div *ngIf="!parserResults">
<nz-result nzStatus="warning" [nzTitle]="compileErrorDescription">
<nz-result nzStatus="warning" [nzTitle]="errorDescriptor">
<div nz-result-content>
<div class="desc">
<h4 nz-title>Error Message:</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ describe('ParserByParserComponent', () => {
const emptyMessage = fixture.debugElement.query(By.css('.ant-result-title'));
const logMessage = fixture.debugElement.query(By.css('[data-qe-id="logMessage"'));

expect(emptyMessage.nativeElement.textContent).toContain(component.ERROR_DESCRIPTOR);
expect(emptyMessage.nativeElement.textContent).toContain(ParserByParserComponent.ERROR_DESCRIPTOR);

component.parserResults = [];
fixture.detectChanges();

expect(emptyMessage.nativeElement.textContent).toContain(component.ERROR_DESCRIPTOR);
expect(emptyMessage.nativeElement.textContent).toContain(ParserByParserComponent.ERROR_DESCRIPTOR);
expect(logMessage.nativeElement.textContent).toContain(component.logMessage);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export class ParserByParserComponent implements OnInit {
'There was an error that prevented your parser chain from being constructed. Please review your configuration settings.';
@Output() investigateParser = new EventEmitter<string>();
@Input() logMessage: string;


errorDescriptor = ParserByParserComponent.ERROR_DESCRIPTOR;
protected readonly parserFieldStatus = ParserFieldStatus;
protected readonly console = console;
private _diffOnly = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('LiveViewService', () => {
);

expect(http.post).toHaveBeenCalledWith(
service.SAMPLE_PARSER_URL,
LiveViewService.SAMPLE_PARSER_URL,
{
sampleData: { type: SampleDataType.MANUAL, source: ['test sample input'] },
chainConfig: { id: '456', name: 'gdf', parsers: [] }
Expand Down

0 comments on commit bd3998f

Please sign in to comment.