Untitled
unknown
plain_text
a year ago
4.2 kB
28
Indexable
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProgressBarModalComponent } from './progress-bar-modal.component';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { of, throwError } from 'rxjs';
import { UntypedFormBuilder } from '@angular/forms';
import { InterviewInfoService } from '../services/interview-info.service';
import { UtilsService } from '../services/utils.service';
import { ToasterService } from '../services/toaster.service';
import { SecondaryModalComponent } from '../secondary-modal/secondary-modal.component';
import { TechnologyDashboardModalComponent } from '../technology-dashboard-modal/technology-dashboard-modal.component';
describe('ProgressBarModalComponent', () => {
let component: ProgressBarModalComponent;
let fixture: ComponentFixture<ProgressBarModalComponent>;
let mockMatDialogRef: jasmine.SpyObj<MatDialogRef<SecondaryModalComponent>>;
let mockInterviewInfoService: jasmine.SpyObj<InterviewInfoService>;
let mockUtilsService: jasmine.SpyObj<UtilsService>;
let mockToasterService: jasmine.SpyObj<ToasterService>;
beforeEach(async () => {
mockMatDialogRef = jasmine.createSpyObj('MatDialogRef', ['close']);
mockInterviewInfoService = jasmine.createSpyObj('InterviewInfoService', ['processEinterviewDashboardActivities']);
mockUtilsService = jasmine.createSpyObj('UtilsService', []);
mockToasterService = jasmine.createSpyObj('ToasterService', ['showToaster']);
await TestBed.configureTestingModule({
declarations: [ProgressBarModalComponent],
providers: [
{ provide: MatDialogRef, useValue: mockMatDialogRef },
{ provide: MAT_DIALOG_DATA, useValue: {} },
{ provide: InterviewInfoService, useValue: mockInterviewInfoService },
{ provide: UtilsService, useValue: mockUtilsService },
{ provide: ToasterService, useValue: mockToasterService },
UntypedFormBuilder
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProgressBarModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('ngOnInit', () => {
it('should initialize techObject and buttonOneText', () => {
component.secondaryModalData = { techObject: { policyNo: '123' } };
component.ngOnInit();
expect(component.techObject).toEqual(component.secondaryModalData.techObject);
expect(component.secondaryModalData.buttonOneText).toBe('Ok');
});
});
describe('processTechnicalDashboardActivities', () => {
it('should handle success response correctly', () => {
const mockResponse = { data: { data: { isErrorMessage: false, message: 'Success' } } };
mockInterviewInfoService.processEinterviewDashboardActivities.and.returnValue(of(mockResponse));
component.techObject = { policyNo: '123', underId: '1', serviceName: 'service', policyType: 'policy' };
component.processTechnicalDashboardActivities();
expect(component.showProgressBar).toBeFalse();
expect(mockToasterService.showToaster).toHaveBeenCalledWith('success', 'Success');
});
it('should handle error response correctly', () => {
mockInterviewInfoService.processEinterviewDashboardActivities.and.returnValue(throwError('Error'));
component.processTechnicalDashboardActivities();
expect(component.showProgressBar).toBeFalse();
});
});
describe('onSubmit', () => {
it('should close the modal with event true', () => {
component.onSubmit();
expect(mockMatDialogRef.close).toHaveBeenCalledWith({ event: true });
});
});
describe('onSecondaryModalClose', () => {
it('should close the modal with event false', () => {
component.onSecondaryModalClose();
expect(mockMatDialogRef.close).toHaveBeenCalledWith({ event: false });
});
});
describe('onCancel', () => {
it('should close the modal with event cancel', () => {
component.onCancel();
expect(mockMatDialogRef.close).toHaveBeenCalledWith({ event: 'cancel' });
});
});
});
Editor is loading...
Leave a Comment