Summary Table

Categories Total Count
PII 2
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 { EwvAdminComponent } from './ewv-admin.component';
import { EwvViewerService } from './../ewv-viewer/ewv-viewer.service';
import { EwvAdminService } from './ewv-admin.service';
import { AuthenticationService } from './../../auth/auth.service';
import { PdfReferenceService } from './../pdf-reference/pdf-reference.service';
import { WindowRefService } from '../../window-ref.service';
import { AppSettingsService } from './../../shared/app-settings/app-settings.service';
import { FormBuilder } from '@angular/forms';
import { PaginationSettings } from '../../shared/table';
import {
SearchModel,
PaginationModel
} from './../../ars/user-admin/user-admin.model'; // need to create ewvUserModel
import { CreateUserRequest } from './ewv-admin-model';

describe('EwvAdminComponent', () => {
let component: EwvAdminComponent;
let ewvViewerService: EwvViewerService;
let ewvAdminService: EwvAdminService;
let authenticationService: AuthenticationService;
let windowRefService: WindowRefService;
let appSettingsService: AppSettingsService;
let pdfReferenceService: PdfReferenceService;
// beforeEach will run before each test.
beforeEach(() => {
ewvViewerService = new EwvViewerService(null, null);
ewvAdminService = new EwvAdminService(null);
authenticationService = new AuthenticationService(null, null, null, null);
windowRefService = new WindowRefService();
appSettingsService = new AppSettingsService(authenticationService, null);
pdfReferenceService = new PdfReferenceService(null);
component = new EwvAdminComponent(
ewvViewerService,
new FormBuilder(),
ewvAdminService,
authenticationService,
windowRefService,
appSettingsService,
pdfReferenceService
);
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('should test ngOnInit method', () => {
const formInitSpy = spyOn(component, 'formInit');
const setMenuSpy = spyOn(component, 'setMenu');
component.ngOnInit();
// expect(setMenuSpy).toHaveBeenCalled();
expect(component.tableSettings.buttonShow).toEqual(true);
expect(component.tableSettings.buttonNames).toEqual(['Modify']);
expect(formInitSpy).toHaveBeenCalled();
});

// it('should test setMenu method', () => {
// const menuData: MenuModel = new MenuModel();
// // const pdfList: DropDownModel[] = [new DropDownModel(), new DropDownModel(), new DropDownModel()];
// const getMenuSpy = spyOn(appSettingsService, 'getMenu').and.callFake(() => {
// return new Observable(observer => observer.next(menuData));
// });
// // const populatePdfRefMenuSpy = spyOn(pdfReferenceService, 'populatePdfReferenceMenu').and.callFake(() => {
// // return new Observable(observer => observer.next(pdfList));
// // });
// component.setMenu();
// expect(getMenuSpy).toHaveBeenCalled();
// // expect(populatePdfRefMenuSpy).toHaveBeenCalled();
// expect(component.ewvMenu).toEqual(menuData);
// // expect(component.ewvMenu.dropDownGroups[1].dropdowns).toEqual(pdfList);
// });

// the following tests should test the various types of success/error messages.
it('should test onUploadSuccess method', () => {
const uploadMessage = {
msg: 'uploaded successfully',
status: true
};
const setMenuSpy = spyOn(component, 'setMenu');
component.onUploadSuccess(uploadMessage);
expect(component.successMsg).toEqual(uploadMessage.msg);
expect(component.successStatus).toEqual(uploadMessage.status);
expect(setMenuSpy).toHaveBeenCalled();
});
it('should test onUploadError method', () => {
const uploadMessage = {
msg: 'uploaded failed',
status: false
};
component.onUploadError(uploadMessage);
expect(component.errorMsg).toEqual(uploadMessage.msg);
expect(component.errorStatus).toEqual(uploadMessage.status);
});
it('should test onArchiveSuccess method', () => {
const archiveMessage = {
msg: 'pdf archived successfully',
status: true
};
const setMenuSpy = spyOn(component, 'setMenu');
component.onArchiveSuccess(archiveMessage);
expect(component.archiveSuccessMsg).toEqual(archiveMessage.msg);
expect(component.archiveSuccessStatus).toEqual(archiveMessage.status);
expect(setMenuSpy).toHaveBeenCalled();
});

it('should test onArchiveError method', () => {
const archiveErrorMessage = {
msg: 'pdf archived failed',
status: false
};
component.onArchiveError(archiveErrorMessage);
expect(component.archiveErrorMsg).toEqual(archiveErrorMessage.msg);
expect(component.archiveErrorStatus).toEqual(archiveErrorMessage.status);
});

// following test should test the form and it's validators.
it('should test all forms were created', () => {
component.formInit();
expect(component.createForm).toBeTruthy();
expect(component.searchForm).toBeTruthy();
expect(component.modifyForm).toBeTruthy();
});
it('should test createForm validation', () => {
component.formInit();
// ** Testing createForm ** //

// testing required
component.createForm.get('userName').setValue('');
expect(component.createForm.get('userName').valid).toBeFalsy();

// testing unaccepted values
component.createForm.get('userName').setValue('[()],');
expect(component.createForm.get('userName').valid).toBeTruthy();
// testing unaccepted values
component.createForm.get('phone').setValue('test');
expect(component.createForm.get('phone').valid).toBeFalsy();
// testing regex pattern
component.createForm.get('email').setValue('test@va');
expect(component.createForm.get('email').valid).toBeFalsy();
// testing required
component.createForm.get('email').setValue('');
expect(component.createForm.get('email').valid).toBeFalsy();
// tesing valid
component.createForm.get('userName').setValue('vhaTest');
expect(component.createForm.get('userName').valid).toBeTruthy();
// testing valid
component.createForm.get('phone').setValue('3215554444');
expect(component.createForm.get('phone').valid).toBeTruthy();
// testing valid
PII ');
expect(component.createForm.get('email').valid).toBeTruthy();
expect(component.createForm.valid).toBeTruthy();

// ** End of Testing createForm ** //
});
it('should test searchForm validation', () => {
// ** Testing searchForm ** //

component.formInit();
// testing required
component.searchForm.get('userName').setValue('');
expect(component.searchForm.get('userName').valid).toBeFalsy();
// testing unaccepted values
component.searchForm.get('userName').setValue('[]({,');
expect(component.searchForm.get('userName').valid).toBeTruthy();
// testing valid
component.searchForm.get('userName').setValue('vhaTest');
expect(component.searchForm.get('userName').valid).toBeTruthy();
expect(component.searchForm.valid).toBeTruthy();

// ** End of Testing searchForm ** //
});
it('should test modifyForm validation', () => {
// ** Testing modifyForm ** //
component.formInit();
// testing unaccepted values
component.modifyForm
.get('editPhone')
.setValue('this is not a phone number');
expect(component.modifyForm.get('editPhone').valid).toBeFalsy();
// testing unaccepted values
component.modifyForm.get('editEmail').setValue('this is not a valid email');
expect(component.modifyForm.get('editEmail').valid).toBeFalsy();
// testing required
component.modifyForm.get('editEmail').setValue('');
expect(component.modifyForm.get('editEmail').valid).toBeFalsy();
// testing valid
component.modifyForm.get('editPhone').setValue('3215554444');
expect(component.modifyForm.get('editPhone').valid).toBeTruthy();
// testing valid
component.modifyForm.get('editEmail').setValue('
PII ');
expect(component.modifyForm.get('editEmail').valid).toBeTruthy();
// testing valid
expect(component.modifyForm.valid).toBeTruthy();
// ** End of Testing modifyForm ** //
});
it('should test search method', () => {
const fetchDataSpy = spyOn(component, 'fetchData');
component.searchUserClicked = false;
component.search();
expect(component.searchUserClicked).toEqual(true);
expect(component.paginationSettings).toEqual(new PaginationSettings());
expect(fetchDataSpy).toHaveBeenCalled();
});
// it('should test fetchData method', () => {
// component.searchModel.userName = 'vhaTest';
// const data = {
// response: [new UserModel(), new UserModel()]
// };
// const getUserInfoSpy = spyOn(ewvAdminService, 'getUserInfo').and.callFake(
// () => {
// return new Observable(observer => observer.next(data));
// }
// );
// component.loading = false;
// component.searchUserClicked = true;
// component.fetchData();
// expect(component.searchResults).toEqual(data.response);
// expect(component.loading).toBeFalsy();
// expect(component.showResults).toBeTruthy();
// expect(component.errorStatus).toBeFalsy();
// expect(getUserInfoSpy).toHaveBeenCalled();
// });
it('should test updateTable method', () => {
const fetchDataSpy = spyOn(component, 'fetchData');
component.updateTable();
expect(fetchDataSpy).toHaveBeenCalled();
});
it('should test listAllUsers method', () => {
component.searchUserClicked = true;
const clearMsgsSpy = spyOn(component, 'clearMsgs');
const fetchDataSpy = spyOn(component, 'fetchData');
component.listAllUsers();
expect(component.searchUserClicked).toEqual(false);
expect(clearMsgsSpy).toHaveBeenCalled();
expect(fetchDataSpy).toHaveBeenCalled();
expect(component.paginationSettings).toEqual(new PaginationSettings());
});
it('should test resetSearchForm method', () => {
const formInitSpy = spyOn(component, 'formInit');
const clearMsgsSpy = spyOn(component, 'clearMsgs');
component.showResults = true;
component.searchUserClicked = true;
component.resetSearchForm();
expect(formInitSpy).toHaveBeenCalled();
expect(clearMsgsSpy).toHaveBeenCalled();
expect(component.searchModel).toEqual(new SearchModel());
expect(component.paginationModel).toEqual(new PaginationModel());
expect(component.showResults).toEqual(false);
expect(component.searchUserClicked).toEqual(false);
});
it('should test clearMsgs method', () => {
component.errorMsg = 'error';
component.errorStatus = true;
component.successMsg = 'success';
component.successStatus = true;
component.clearMsgs();
expect(component.errorMsg).toEqual('');
expect(component.successMsg).toEqual('');
expect(component.errorStatus).toEqual(false);
expect(component.successStatus).toEqual(false);
});
it('should test resetCreateForm method', () => {
const formInitSpy = spyOn(component, 'formInit');
const clearMsgsSpy = spyOn(component, 'clearMsgs');
component.enableEdit = true;
component.enableExport = true;
component.isAdmin = true;
component.status = false;
component.resetCreateForm();
expect(formInitSpy).toHaveBeenCalled();
expect(clearMsgsSpy).toHaveBeenCalled();
expect(component.enableEdit).toEqual(false);
expect(component.enableExport).toEqual(false);
expect(component.isAdmin).toEqual(false);
expect(component.status).toEqual(true);
expect(component.requestModel).toEqual(new CreateUserRequest());
});
it('should test buttonClicked method', () => {});
});

// buttonClicked(event) {
// // if (event.buttonName === 'Modify') {
// this.openEditModal(event);
// // }
// // else {
// // this.openDeleteModal(event);
// // // this.delete(event);
// // }
// }