Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { EwvViewerComponent } from './ewv-viewer.component';
// import { Router } from '@angular/router';
import { FormBuilder } from '@angular/forms';
// import { ElementRef } from '@angular/core';
import { EwvViewerService } from './ewv-viewer.service';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/throw';
import { Observable } from 'rxjs/Observable';
import { AttachmentViewerService } from '../../shared/attachment-viewer/attachment-viewer.service';
import { EwvHighlightService } from './ewv-highlight.service';
import { PdfReferenceService } from './../pdf-reference/pdf-reference.service';
import { AuthenticationService } from './../../auth/auth.service';
import { BillingInfoService } from '../ewv-components/billing-info/billing-info.service';
import { AppSettingsService } from './../../shared/app-settings/app-settings.service';
describe('EwvViewerComponent', () => {
let component: EwvViewerComponent;
let ewvViewerService: EwvViewerService;
let ewvHighlightService: EwvHighlightService;
let formBuilder: FormBuilder;
let router;
let _window;
let document;
let viewerService: AttachmentViewerService;
let pdfReferenceService: PdfReferenceService;
let authenticationService: AuthenticationService;
let billingInfoService: BillingInfoService;
let appSettingsService: AppSettingsService;
beforeEach(() => {
ewvViewerService = new EwvViewerService(null, null);
ewvHighlightService = new EwvHighlightService(
null,
null,
null,
null,
null,
null
);
billingInfoService = new BillingInfoService();
router = { navigate: () => true };
formBuilder = new FormBuilder();
// _window = new WindowRefService();
_window = {
nativeWindow: {
print: () => true,
scrollTo: () => true,
open: () => true,
URL: {
createObjectURL: () => true
}
}
};
viewerService = new AttachmentViewerService(null);
document = { body: { style: { overflow: 'hidden' } } };
pdfReferenceService = new PdfReferenceService(null);
authenticationService = new AuthenticationService(null, null, null, null);
appSettingsService = new AppSettingsService(authenticationService, null);
component = new EwvViewerComponent(
ewvViewerService,
ewvHighlightService,
router,
formBuilder,
_window,
document,
viewerService,
pdfReferenceService,
authenticationService,
appSettingsService,
billingInfoService
);
jasmine.clock().install();
});
afterEach(function() {
jasmine.clock().uninstall();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('test ngAfterViewInit method (no ticks): "component.loadingSpinnerClosed" is false', () => {
component.loadingSpinnerClosed = false;
spyOn(component, 'setMenu');
spyOn(component, 'closeloadingSpinnerModal');
component.ngAfterViewInit();
expect(component.setMenu).not.toHaveBeenCalled();
expect(component.closeloadingSpinnerModal).not.toHaveBeenCalled();
});
it('test ngOnInit method', () => {
const loadingSpinnerSpy = spyOn(component, 'openloadingSpinnerModal');
const authenticationSpy = spyOn(
authenticationService,
'getDecodedUserInfo'
).and.callFake(() => {
return new Observable(observer => observer.next(''));
});
const getPdiNumberSpy = spyOn(component, 'getPdiNumber').and.callFake(
() => '201700192000001'
);
const onSearchSpy = spyOn(component, 'onSearch');
const getStyleSpy = spyOn(component, 'getStyle');
const formInitSpy = spyOn(component, 'formInit');
component.ngOnInit();
expect(loadingSpinnerSpy).toHaveBeenCalled();
expect(authenticationSpy).toHaveBeenCalled();
expect(getPdiNumberSpy).toHaveBeenCalled();
expect(onSearchSpy).toHaveBeenCalled();
expect(getStyleSpy).toHaveBeenCalled();
expect(formInitSpy).toHaveBeenCalled();
});
it('test getPdfFile method', () => {
_window.nativeWindow['navigator'] = {
msSaveOrOpenBlob: () => true
};
const pdfFileData = {
blob: () => true,
headers: {
get: () => true
}
};
spyOn(ewvViewerService, 'getPdfFile').and.returnValue(
Observable.of(pdfFileData)
);
// const expectedPdfBlob = new Blob([pdfFileData.blob()], {
// type: 'application/pdf'
// });
// Generates an error:
// Type 'boolean' is not assignable to type 'BlobPart'.
// That is, pdfFileData.blob() is boolean.
// In component.getPdfFile,
// const pdfBlob = new Blob([data.blob()], { type: 'application/pdf' });
// "works" because it doesn't really know the type of data.blob().
// So we fool it here with "as any"
const expectedPdfBlob = new Blob([pdfFileData.blob() as any], {
type: 'application/pdf'
});
const expectedPdfUrl = 'Expected PDF URL';
spyOn(_window.nativeWindow.URL, 'createObjectURL').and.returnValue(
expectedPdfUrl
);
const contentDispositionValue = 'CONTENT_DISPOSITION_FILE_NAME_VALUE';
spyOn(pdfFileData.headers, 'get').and.returnValue(contentDispositionValue);
spyOn(_window.nativeWindow.navigator, 'msSaveOrOpenBlob');
spyOn(_window.nativeWindow, 'open');
component.getPdfFile(1017);
expect(ewvViewerService.getPdfFile).toHaveBeenCalled();
expect(_window.nativeWindow.URL.createObjectURL).toHaveBeenCalled();
expect(_window.nativeWindow.URL.createObjectURL).toHaveBeenCalledWith(
expectedPdfBlob
);
expect(_window.nativeWindow.open).not.toHaveBeenCalled();
expect(_window.nativeWindow.open).not.toHaveBeenCalledWith(expectedPdfUrl);
expect(_window.nativeWindow.navigator.msSaveOrOpenBlob).toHaveBeenCalled();
expect(
_window.nativeWindow.navigator.msSaveOrOpenBlob
).toHaveBeenCalledWith(expectedPdfBlob, contentDispositionValue);
expect(pdfFileData.headers.get).toHaveBeenCalled();
expect(pdfFileData.headers.get).toHaveBeenCalledWith('Content-Disposition');
});
it('test getStyle method: pageSelector not equal to "INSTITUTIONAL", "PROFESSIONAL", nor "DENTAL"', () => {
component.pageSelector = 'NOTHING';
const returnedValue = component.getStyle();
expect(returnedValue).toEqual('inst');
});
it('test collapseFunctions method: state set to true', () => {
component.collapseState = false;
component.collapseFunctions(true);
expect(component.collapseState).toEqual(true);
});
it('test collapseFunctions method: state set to false', () => {
component.collapseState = true;
component.collapseFunctions(false);
expect(component.collapseState).toEqual(false);
});
it('test collapseAll method', () => {
spyOn(ewvViewerService, 'setCollapseState');
component.collapseAll();
expect(ewvViewerService.setCollapseState).toHaveBeenCalled();
expect(ewvViewerService.setCollapseState).toHaveBeenCalledWith(false);
});
it('test expandAll method', () => {
spyOn(ewvViewerService, 'setCollapseState');
component.expandAll();
expect(ewvViewerService.setCollapseState).toHaveBeenCalled();
expect(ewvViewerService.setCollapseState).toHaveBeenCalledWith(true);
});
it('test print method', () => {
spyOn(_window.nativeWindow, 'print');
component.print();
expect(_window.nativeWindow.print).toHaveBeenCalled();
});
it('test scrollToTop method', () => {
spyOn(_window.nativeWindow, 'scrollTo');
component.scrollToTop();
expect(_window.nativeWindow.scrollTo).toHaveBeenCalled();
expect(_window.nativeWindow.scrollTo).toHaveBeenCalledWith({
top: 0,
behavior: 'smooth'
});
});
it('test onSearch method', () => {
spyOn(ewvViewerService, 'searchClaim').and.returnValue(
Observable.throw({})
);
spyOn(component, 'getStyle');
spyOn(ewvViewerService, 'setClaimData');
spyOn(ewvViewerService, 'setClaimData2');
spyOn(ewvViewerService, 'setPdi');
spyOn(ewvViewerService, 'setPdi2');
spyOn(component, 'checkIfClaimIsOriginalOrCurrent');
spyOn(component, 'expandAll');
spyOn(component, 'scrollToTop');
spyOn(component, 'openloadingSpinnerModal');
spyOn(component, 'closeloadingSpinnerModal');
expect(ewvViewerService.claimData).toEqual(undefined);
expect(component.data).toEqual(undefined);
component.show = undefined;
component.tabType = undefined;
component.noDataToCompare = undefined;
component.compareData = undefined;
component.loadedRight = undefined;
component.containerClassWidth = undefined;
component.pageSelector = undefined;
component.ewvMsg = undefined;
component.isSplitView = false;
component.onSearch('12345', true);
expect(component.errorMsg).toEqual('Error occured while searching the PDI');
expect(component.errorStatus).toEqual(true);
expect(ewvViewerService.searchClaim).toHaveBeenCalled();
expect(ewvViewerService.searchClaim).toHaveBeenCalledWith('12345');
expect(component.getStyle).not.toHaveBeenCalled();
expect(ewvViewerService.setClaimData).not.toHaveBeenCalled();
expect(ewvViewerService.setClaimData2).not.toHaveBeenCalled();
expect(ewvViewerService.setPdi).not.toHaveBeenCalled();
expect(ewvViewerService.setPdi2).not.toHaveBeenCalled();
expect(component.checkIfClaimIsOriginalOrCurrent).not.toHaveBeenCalled();
expect(component.expandAll).not.toHaveBeenCalled();
expect(component.scrollToTop).toHaveBeenCalled();
expect(component.openloadingSpinnerModal).toHaveBeenCalled();
expect(component.closeloadingSpinnerModal).toHaveBeenCalled();
expect(component.data).toEqual(undefined);
expect(component.show).toEqual(true);
expect(component.tabType).toEqual(undefined);
expect(component.noDataToCompare).toEqual(false);
expect(component.compareData).toEqual(undefined);
expect(component.loadedRight).toEqual(undefined);
expect(component.containerClassWidth).toEqual(undefined);
expect(component.pageSelector).toEqual(undefined);
expect(component.ewvMsg).toEqual('');
});
it('test getPdiNumber method', () => {
ewvViewerService.pdiNumber = '123456';
const returnedValue = component.getPdiNumber();
expect(returnedValue).toEqual('123456');
});
it('test getPdiNumber2 method', () => {
ewvViewerService.pdiNumber2 = '123456';
const returnedValue = component.getPdiNumber2();
expect(returnedValue).toEqual('123456');
});
it('test formInit method: valid form if pdiSearchParam value has all numbers and number of characters is 15', () => {
component.formInit();
component.form.get('pdiSearchParam').setValue('123456789012345');
expect(component.form.get('pdiSearchParam').valid).toEqual(true);
expect(component.form.valid).toEqual(true);
});
it('test formInit method: valid form if pdiSearchParam value has all numbers and number of characters is greater than 15', () => {
component.formInit();
component.form.get('pdiSearchParam').setValue('12345678901234567');
expect(component.form.get('pdiSearchParam').valid).toEqual(true);
expect(component.form.valid).toEqual(true);
});
it('test onViewChange method', () => {
expect(component.tabType).toEqual('c');
component.onViewChange('k');
expect(component.tabType).toEqual('k');
});
it('test switchView method', () => {
spyOn(ewvViewerService, 'switchView');
spyOn(component, 'onSearch');
component.containerClassWidth = 5000;
component.pdiSearchParam = '12345';
component.formInit();
component.form.get('pdiSearchParam').setValue('123456789012345');
expect(component.form.valid).toEqual(true);
component.switchView('split');
expect(component.containerClassWidth).toEqual(5000);
expect(ewvViewerService.switchView).toHaveBeenCalled();
expect(ewvViewerService.switchView).toHaveBeenCalledWith('split');
expect(component.onSearch).toHaveBeenCalled();
expect(component.onSearch).toHaveBeenCalledWith('12345', true);
});
it('test resetMsgs method', () => {
component.successStatus = undefined;
component.errorStatus = undefined;
component.successMsg = undefined;
component.errorMsg = undefined;
component.archiveErrorMsg = undefined;
component.archiveSuccessMsg = undefined;
component.archiveSuccessStatus = undefined;
component.archiveErrorStatus = undefined;
component.ewvMsg = undefined;
component.resetMsgs();
expect(component.successStatus).toEqual(false);
expect(component.errorStatus).toEqual(false);
expect(component.successMsg).toEqual('');
expect(component.errorMsg).toEqual('');
expect(component.archiveErrorMsg).toEqual('');
expect(component.archiveSuccessMsg).toEqual('');
expect(component.archiveSuccessStatus).toEqual(false);
expect(component.archiveErrorStatus).toEqual(false);
expect(component.ewvMsg).toEqual('');
});
it('test closeloadingSpinnerModal method', () => {
component.loadingSpinnerClosed = undefined;
component.closeloadingSpinnerModal();
expect(component.loadingSpinnerClosed).toEqual(true);
});
it('test openloadingSpinnerModal method', () => {
component.loadingSpinnerClosed = undefined;
component.openloadingSpinnerModal();
expect(component.loadingSpinnerClosed).toEqual(false);
});
it('test focusMenuBarElements method', () => {
document.onclick = undefined;
component.pdfReferencesFocused = undefined;
component.hotKeysFocused = undefined;
component.focusMenuBarElements('');
expect(component.pdfReferencesFocused).toEqual(false);
expect(component.hotKeysFocused).toEqual(false);
expect(document.onclick).toBeDefined();
expect(document.onclick).not.toEqual(null);
component.pdfReferencesFocused = undefined;
component.hotKeysFocused = undefined;
document.onclick();
expect(component.pdfReferencesFocused).toEqual(false);
expect(component.hotKeysFocused).toEqual(false);
});
it('test clickElementOnEnter method', () => {
const event = {
srcElement: {
firstElementChild: {
click: () => true
}
}
};
spyOn(event.srcElement.firstElementChild, 'click');
component.clickElementOnEnter(event);
expect(event.srcElement.firstElementChild.click).toHaveBeenCalled();
});
});