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 { FormBuilder } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
import { RfaiSearch277Component } from './rfai-search277.component';
import { RfaiSearch277Service } from './rfai-search277.service';
import { AuthenticationService } from '../../auth/auth.service';
import { AppSettingsService } from './../../shared/app-settings/app-settings.service';

describe('RfaiSearch277Component', () => {
let component: RfaiSearch277Component;
let rfaiSearch277Service: RfaiSearch277Service;
let authenticationService: AuthenticationService;
let appSettingsService: AppSettingsService;
const fb = new FormBuilder();
beforeEach(() => {
authenticationService = new AuthenticationService(null, null, null, null);
appSettingsService = new AppSettingsService(authenticationService, null);
rfaiSearch277Service = new RfaiSearch277Service(null);
component = new RfaiSearch277Component(
fb,
rfaiSearch277Service,
null,
authenticationService,
appSettingsService,
null
);
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('should check if primaryForm has been initialized', () => {
component.formInit();
expect(component.primaryForm).toBeDefined();
});
it('should check if advancedForm has been initialized', () => {
component.formInit();
expect(component.advancedForm).toBeDefined();
});
it('should check component initialization', () => {
component.primaryRadioButton = { nativeElement: { focus: true } };
const appSettingsServiceSpy = spyOn(
appSettingsService,
'getMenu'
).and.callFake(() => new Observable(observer => observer.next('')));
const getUserDataSpy = spyOn(component, 'getUserData');
component.ngOnInit();
expect(appSettingsServiceSpy).toHaveBeenCalled();
});
it('should check primarySearch method', () => {
component.formInit();
component.primaryForm.get('primarySearchParam').setValue('123456');
const primarySearchSpy = spyOn(
rfaiSearch277Service,
'quickSearch'
).and.callFake(() => {
return new Observable(observer =>
observer.next({
response: [
{
pdiClaimId: component.primaryForm.get('primarySearchParam').value
}
]
})
);
});
component.primarySearch();
expect(component.searchResults[0].pdiClaimId).toContain('123456');
});
it('should clear primary search', () => {
component.formInit();
component.primaryForm.get('primarySearchParam').setValue('123456');
component.clearPrimary();
expect(component.primaryForm.get('primarySearchParam').value).toBeFalsy();
});
it('should check advancedSearch method', () => {
component.formInit();
component.advancedForm.get('pdiClaimId').setValue(12345);
const advancedSearchSpy = spyOn(
rfaiSearch277Service,
'advancedSearch'
).and.callFake(() => {
return new Observable(observer =>
observer.next({
response: [
{
pdiClaimId: component.advancedForm.get('pdiClaimId').value
}
]
})
);
});
component.advancedSearch();
expect(component.searchResults[0].pdiClaimId).toBe(12345);
});
it('should clear advanced search', () => {
component.formInit();
component.advancedForm.get('pdiClaimId').setValue(12345);
component.clearAdvancedForm();
expect(component.advancedForm.get('pdiClaimId').value).toBeFalsy();
});
// test validators on advanced search form.
it('should validate pdiClaimId', () => {
component.formInit();
component.advancedForm.get('pdiClaimId').setValue(123);
expect(component.advancedForm.get('pdiClaimId').valid).toBeTruthy();
});
it('should validate providerNpi', () => {
component.formInit();
component.advancedForm.get('providerNpi').setValue(1234567890);
expect(component.advancedForm.get('providerNpi').valid).toBeTruthy();
});

it('on empty string ""', () => {
// configure test
const valueU = ''; // user entered value
const validX = true; // .valid expected
// initialize form
component.formInit();
// access form element of interest
const elem = component.advancedForm.get('providerTin');
// Do something with elem
elem.setValue(valueU);
// Check results
expect(elem.value).toBe(valueU);
expect(elem.valid).toBe(validX);
});

// Simple, happy cases: 9-digit number strings
it('on "123456789", "314159265"', () => {
// We could put the null string into this list, but I thought it better
// to have a nice simple test (above) before getting fancy.
const happy = ['123456789', '314159265']; // all should be valid values!
happy.forEach((val, idx, arr) => {
// configure test
const valueU = val; // user entered value
const validX = true; // .valid expected true for all happy values
// reset component.advancedForm
component.advancedForm = null; // this is because of the forEach
component.formInit(); // initialize form advancedForm
expect(component.advancedForm).toBeTruthy();
// access form element of interest
const elem = component.advancedForm.get('providerTin');
// Do something with elem
elem.setValue(valueU);
// Check results
expect(elem.value).toBe(valueU);
// Test providerTin element Validators.pattern()
// we don't assume the pattern regex, here. That's what we're testing.
expect(elem.valid).toBe(validX);
});
});

it('on possible bad pattern matching ddddddddd', () => {
// Validators.pattern('\d{9}') looks like it would work, but it doesn't!
// The '\d' matches a literal 'd', not the named pattern /\d/.
// The correct pattern would be, either
// Validators.pattern(/\d{9}/) using regular expression literal sytax
// Validators.pattern('\\d{9}')
// The regular expression syntax has a chance of being faster, because it will be precompiled.
// However, a smart compiler can recognize the special case of passing a constant string into
// a context wanting a regular expression. So it could all be optimized away.
// Personally, I like the Validators.pattern(/\d{9}/) syntax.
component.formInit();
component.advancedForm.get('providerTin').setValue('ddddddddd');
expect(component.advancedForm.get('providerTin').valid).toBeFalsy(
`Pattern '\d{9}' is in error!`
);
expect(component.advancedForm.get('providerTin').value).toBe('ddddddddd'); // it really was set

// configure test
const valueU = 'ddddddddd'; // user entered value
const validX = false; // .valid expected to be false!
// initialize form
component.formInit();
// access form element of interest
const elem = component.advancedForm.get('providerTin');
// Do something with elem
elem.setValue(valueU);
// Check results
expect(elem.value).toBe(valueU);
expect(elem.valid).toBe(
validX,
`Possibly an erroneous pattern string,'\d{9}', this is an error!`
);
});

it('on digits length from 0 to 20', () => {
const digits = '12345678901234567890';
for (let index = 0; index <= digits.length; index++) {
// configure test
const valueU = digits.slice(0, index);
const validX: boolean = index === 0 || index === 9; // only 0 and 9 are valid
const validF = validX && valueU.length > 0; // advancedForm.valid needs atleastone(Validators.required), too!

// reset component.advancedForm
component.advancedForm = null; // this is because of the for()
component.formInit(); // initialize form advancedForm
expect(component.advancedForm).toBeTruthy();
// Test overall form Validator
expect(component.advancedForm.valid).toBe(
false,
'Empty Form is not valid'
);
// access form element of interest
const elem = component.advancedForm.get('providerTin');
expect(elem).toBeTruthy('Where is advancedForm providerTin element?');
// Do something with elem
elem.setValue(valueU);
// Check results
// Careful! valueU may be '', and an Empty Form is not valid
expect(component.advancedForm.valid).toBe(
validF,
`advancedForm.valid FAIL: ${valueU} => ${validF}`
);
expect(elem.value).toBe(
valueU,
`providerTin.value: ${elem.value} FAIL: ${valueU}`
);
// Test providerTin element Validators.pattern()
// we don't assume the pattern regex, here. That's what we're testing.
expect(elem.valid).toBe(validX);
}
});
// Extra testing to see what numbers do
// In the app, only strings are entered into the values. So this is extra.
// Simple, happy cases: 9-digit number strings

it('on Number.parseInt(digits of length from 0 to 20)', () => {
const digits = '12345678901234567890';
for (let index = 0; index <= digits.length; index++) {
// configure test
const valueU = Number.parseInt(digits.slice(0, index)); // Convert to a number

// Recall: All Javascript numbers are 64-bin floating point numbers
// even the results from Number.parseInt()!
// The maximum representable integer value is ???
// we do know that Number.parseInt('123456789012') returns NaN
const validX: boolean = index === 9; // normally 0 and 9 are valid, but 0 gives NaN

// Strings parsing to NaN won't be valid anyway.
// But it may be tricky to test that NaN was set,
// I think expect(NaN).toBe(NaN) fails. That is why there's a special function: expect(NaN).toBeNaN();
const validF = validX && valueU.toString().length > 0; // advancedForm.valid needs atleastone(Validators.required), too!

// reset component.advancedForm
component.advancedForm = null; // this is because of the for()
component.formInit(); // initialize form advancedForm
expect(component.advancedForm).toBeTruthy();
// Test overall form Validator
expect(component.advancedForm.valid).toBe(
false,
'Empty Form is not valid'
);
// access form element of interest
const elem = component.advancedForm.get('providerTin');
expect(elem).toBeTruthy('Where is advancedForm providerTin element?');
// Do something with elem
elem.setValue(valueU);
// Check results
// Careful! valueU may be '', and an Empty Form is not valid
// Actually, you cannot get an empty form element by setting a number
expect(valueU.toString().length > 0).toBe(true); // always true, Therefore...
expect(component.advancedForm.valid).toBe(validF); // ... so is form with single providerTin
if (isNaN(valueU)) {
expect(elem.value).toBeNaN();
} else {
expect(elem.value).toBe(valueU);
}
// Test providerTin element Validators.pattern()
// we don't assume the pattern regex, here. That's what we're testing.
expect(elem.valid).toBe(validX);
}
});

// Simple, happy cases: 9-digit number strings
it('on happy numbers 123456789, 314159265, etc', () => {
// Notice that 0 is not a happy value!
const happy = [
0x75bcd15, // hex literal === 123456789,
0xfffffff, // hex literal === 268435455,
123456789,
314159265,
987654321,
999999999,
888888888,
777777777,
666666666,
555555555,
444444444,
333333333,
222222222,
111111111
]; // all should be valid values!
happy.forEach((val, idx, arr) => {
// configure test
const valueU = val; // user entered value
const validX = true; // .valid expected true for all happy values
// reset component.advancedForm
component.advancedForm = null; // this is because of the forEach
component.formInit(); // initialize form advancedForm
expect(component.advancedForm).toBeTruthy();
// access form element of interest
const elem = component.advancedForm.get('providerTin');
// Do something with elem
elem.setValue(valueU);
// Check results
expect(elem.value).toBe(valueU);
// Test providerTin element Validators.pattern()
// we don't assume the pattern regex, here. That's what we're testing.
expect(elem.valid).toBe(validX);
});
});

// Simple, zappy cases: 9-digit number strings
it('on zappy numbers 1,23,456,7890, etc', () => {
// Notice that 0 is zappy (not happy)!
const zappy = [
1,
23,
456,
7890,
0,
0x00000000, // hex literal === 0, Length only appears to be 10
0o000000000, // octal literal === 0
// 0123456712, // 7+2 = 9, but it's really octal! Not allowed in strict mode
0xffffffff, // hex literal === 0, Length only appears to be 10
129876543210, // zappy!
19876543210, // zappy!
9876543210, // zappy!
// 987654321, // happy, not zappy!
87654321,
7654321,
654321,
54321,
4321,
321,
21,
1
]; // all should be non-valid values!
zappy.forEach((val, idx, arr) => {
// configure test
const valueU = val; // user entered value
const validX = false; // .valid expected false for all zappy values
// reset component.advancedForm
component.advancedForm = null; // this is because of the forEach
component.formInit(); // initialize form advancedForm
expect(component.advancedForm).toBeTruthy();
// access form element of interest
const elem = component.advancedForm.get('providerTin');
// Do something with elem
elem.setValue(valueU);
// Check results
expect(elem.value).toBe(valueU);
// Test providerTin element Validators.pattern()
// we don't assume the pattern regex, here. That's what we're testing.
expect(elem.valid).toBe(validX);
});
});

it('should validate patientIdentifier', () => {
component.formInit();
component.advancedForm.get('patientIdentifier').setValue(123);
expect(component.advancedForm.get('patientIdentifier').valid).toBeTruthy();
});
it('should validate patientcontrolNumber', () => {
component.formInit();
component.advancedForm.get('patientcontrolNumber').setValue(123);
expect(
component.advancedForm.get('patientcontrolNumber').valid
).toBeTruthy();
});
it('should validate medicalRecordNumber', () => {
component.formInit();
component.advancedForm.get('medicalRecordNumber').setValue(123);
expect(
component.advancedForm.get('medicalRecordNumber').valid
).toBeTruthy();
});
// it('should validate lineItemControlNumber', () => {
// component.formInit();
// component.advancedForm.get('lineItemControlNumber').setValue(123);
// expect(
// component.advancedForm.get('lineItemControlNumber').valid
// ).toBeTruthy();
// });
it('should validate serviceStartDate', () => {
component.formInit();
component.advancedForm.get('serviceStartDate').setValue('12/12/2017');
expect(component.advancedForm.get('serviceStartDate').valid).toBeTruthy();
});
it('should validate serviceEndDate', () => {
component.formInit();
component.advancedForm.get('serviceEndDate').setValue('12/12/2017');
expect(component.advancedForm.get('serviceEndDate').valid).toBeTruthy();
});
// test to clear forms if user toggles between quick/advanced search. // method not working****
it('should clear primary search if user toggles to advanced search', () => {
component.formInit();
component.primaryForm.get('primarySearchParam').setValue('123456');
// component.primaryDiv.nativeElement = { style: { display: 'block' } };
// component.advancedDiv.nativeElement = { style: { display: 'block' } };
component.showAdvanced();
expect(component.primaryForm.get('primarySearchParam').value).toBeFalsy();
});
it('should clear advanced search if user toggles to quick search', () => {
component.formInit();
component.advancedForm.get('pdiClaimId').setValue(12345);
// component.primaryDiv.nativeElement = { style: { display: 'block' } };
// component.advancedDiv.nativeElement = { style: { display: 'block' } };
component.showPrimary();
expect(component.advancedForm.get('pdiClaimId').value).toBeFalsy();
});
// test validation on date range
it('should test for valid date ranges', () => {
component.formInit();
component.advancedForm.get('serviceStartDate').setValue('10/10/2011');
component.advancedForm.get('serviceEndDate').setValue('10/10/2012');
component.datesValidator();

expect(component.dateRangeError).toBeFalsy();
});
// test update table method
it('should test updateTable with primarySearch being called', () => {
component.typeOfSearch = 'P';
const primarySearchSpy = spyOn(component, 'primarySearch');
component.updateTable();
expect(primarySearchSpy).toHaveBeenCalled();
});
it('should test updateTable with advancedSearch being called', () => {
component.typeOfSearch = 'A';
const advancedSearchSpy = spyOn(component, 'advancedSearch');
component.updateTable();
expect(advancedSearchSpy).toHaveBeenCalled();
});
});