Skip to content

Commit

Permalink
update test set up
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaed Parkar committed Oct 16, 2023
1 parent 3d7a67b commit 0fefa5b
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { PopupModule } from 'src/app/popups/popup.module';
import { TestingModule } from 'src/app/testing/testing.module';
import { By } from '@angular/platform-browser';
import { HearingRoles } from '../../common/model/hearing-roles.model';
import { FeatureFlagService } from '../../services/feature-flag.service';
import { FeatureFlags, LaunchDarklyService } from 'src/app/services/launch-darkly.service';

let component: AddParticipantComponent;
Expand Down Expand Up @@ -259,12 +258,11 @@ videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>([
]);
let bookingServiceSpy: jasmine.SpyObj<BookingService>;
let searchServiceSpy: jasmine.SpyObj<SearchService>;
let featureFlagServiceSpy: jasmine.SpyObj<FeatureFlagService>;
const launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
let launchDarklyServiceSpy: jasmine.SpyObj<LaunchDarklyService>;

const configServiceSpy = jasmine.createSpyObj<ConfigService>('ConfigService', ['getClientSettings']);

featureFlagServiceSpy = jasmine.createSpyObj<FeatureFlagService>('FeatureToggleService', ['getFeatureFlagByName']);
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
const loggerSpy = jasmine.createSpyObj<Logger>('Logger', ['error', 'debug', 'warn']);
let participantServiceSpy = jasmine.createSpyObj<ParticipantService>('ParticipantService', [
'checkDuplication',
Expand Down Expand Up @@ -292,7 +290,6 @@ describe('AddParticipantComponent', () => {
'removeParticipant',
'mapParticipantHearingRoles'
]);
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));
participantServiceSpy.mapParticipantsRoles.and.returnValue(partyList);
Expand Down Expand Up @@ -323,7 +320,7 @@ describe('AddParticipantComponent', () => {
loggerSpy
);

component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, featureFlagServiceSpy);
component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, launchDarklyServiceSpy);
component.participantsListComponent = new ParticipantListComponent(loggerSpy, videoHearingsServiceSpy);

component.ngOnInit();
Expand Down Expand Up @@ -1065,7 +1062,6 @@ describe('AddParticipantComponent edit mode', () => {
'getHearingRoles'
]);
bookingServiceSpy = jasmine.createSpyObj<BookingService>(['isEditMode', 'getParticipantEmail', 'resetEditMode']);
featureFlagServiceSpy = jasmine.createSpyObj<FeatureFlagService>('FeatureToggleService', ['getFeatureFlagByName']);

TestBed.configureTestingModule({
imports: [SharedModule, RouterModule.forChild([]), BookingModule, PopupModule, TestingModule],
Expand All @@ -1076,13 +1072,11 @@ describe('AddParticipantComponent edit mode', () => {
{ provide: ParticipantService, useValue: participantServiceSpy },
{ provide: BookingService, useValue: bookingServiceSpy },
{ provide: Logger, useValue: loggerSpy },
{ provide: FeatureFlagService, useValue: featureFlagServiceSpy },
{ provide: ConfigService, useValue: configServiceSpy },
{ provide: LaunchDarklyService, useValue: launchDarklyServiceSpy }
]
}).compileComponents();

featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

Expand Down Expand Up @@ -1214,7 +1208,7 @@ describe('AddParticipantComponent edit mode', () => {
});

it('should set edit mode and populate participant data', fakeAsync(async () => {
component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, featureFlagServiceSpy);
component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, launchDarklyServiceSpy);
component.searchEmail.email = '[email protected]';

component.ngOnInit();
Expand Down Expand Up @@ -1495,7 +1489,7 @@ describe('AddParticipantComponent edit mode no participants added', () => {
'isHearingAboutToStart',
'getHearingRoles'
]);
featureFlagServiceSpy = jasmine.createSpyObj<FeatureFlagService>('FeatureToggleService', ['getFeatureFlagByName']);
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
videoHearingsServiceSpy.getParticipantRoles.and.returnValue(Promise.resolve(roleList));
videoHearingsServiceSpy.getCurrentRequest.and.returnValue(hearing);
videoHearingsServiceSpy.getHearingRoles.and.returnValue(Promise.resolve(flatRoleList));
Expand All @@ -1504,7 +1498,6 @@ describe('AddParticipantComponent edit mode no participants added', () => {
bookingServiceSpy = jasmine.createSpyObj<BookingService>(['getParticipantEmail', 'isEditMode', 'setEditMode', 'resetEditMode']);
bookingServiceSpy.isEditMode.and.returnValue(true);
bookingServiceSpy.getParticipantEmail.and.returnValue('');
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(false));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(false));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

Expand All @@ -1517,7 +1510,6 @@ describe('AddParticipantComponent edit mode no participants added', () => {
{ provide: ParticipantService, useValue: participantServiceSpy },
{ provide: BookingService, useValue: bookingServiceSpy },
{ provide: Logger, useValue: loggerSpy },
{ provide: FeatureFlagService, useValue: featureFlagServiceSpy },
{ provide: LaunchDarklyService, useValue: launchDarklyServiceSpy },
{ provide: ConfigService, useValue: configServiceSpy }
]
Expand All @@ -1526,7 +1518,7 @@ describe('AddParticipantComponent edit mode no participants added', () => {
fixture = TestBed.createComponent(AddParticipantComponent);
component = fixture.componentInstance;
component.participantsListComponent = new ParticipantListComponent(loggerSpy, videoHearingsServiceSpy);
component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, featureFlagServiceSpy);
component.searchEmail = new SearchEmailComponent(searchService, configServiceSpy, loggerSpy, launchDarklyServiceSpy);
component.editMode = true;
component.ngOnInit();

Expand Down Expand Up @@ -1741,7 +1733,6 @@ describe('AddParticipantComponent set representer', () => {
participantServiceSpy.mapParticipantHearingRoles.and.returnValue(mappedHearingRoles);
bookingServiceSpy.isEditMode.and.returnValue(true);
bookingServiceSpy.getParticipantEmail.and.returnValue('');
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.referenceData).and.returnValue(of(false));

Expand All @@ -1756,7 +1747,7 @@ describe('AddParticipantComponent set representer', () => {
launchDarklyServiceSpy,
loggerSpy
);
component.searchEmail = new SearchEmailComponent(searchServiceStab, configServiceSpy, loggerSpy, featureFlagServiceSpy);
component.searchEmail = new SearchEmailComponent(searchServiceStab, configServiceSpy, loggerSpy, launchDarklyServiceSpy);

component.ngOnInit();

Expand Down Expand Up @@ -1820,7 +1811,7 @@ describe('AddParticipantComponent set representer', () => {
jasmine.createSpyObj<SearchService>(['participantSearch']),
configServiceSpy,
loggerSpy,
featureFlagServiceSpy
launchDarklyServiceSpy
);
component.participantDetails = participants[0];
component.ngAfterContentInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ParticipantModel } from '../../common/model/participant.model';
import { CancelPopupComponent } from '../../popups/cancel-popup/cancel-popup.component';
import { DiscardConfirmPopupComponent } from '../../popups/discard-confirm-popup/discard-confirm-popup.component';
import { BookingService } from '../../services/booking.service';
import { BHClient, ClientSettingsResponse } from '../../services/clients/api-client';
import { ClientSettingsResponse } from '../../services/clients/api-client';
import { Logger } from '../../services/logger';
import { RecordingGuardService } from '../../services/recording-guard.service';
import { VideoHearingsService } from '../../services/video-hearings.service';
Expand Down Expand Up @@ -75,7 +75,6 @@ let videoHearingsServiceSpy: jasmine.SpyObj<VideoHearingsService>;
let judgeDataServiceSpy: jasmine.SpyObj<JudgeDataService>;
let routerSpy: jasmine.SpyObj<Router>;
let bookingServiseSpy: jasmine.SpyObj<BookingService>;
let clientApiSpy: jasmine.SpyObj<BHClient>;
const launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
let loggerSpy: jasmine.SpyObj<Logger>;
let emailValidationServiceSpy: jasmine.SpyObj<EmailValidationService>;
Expand All @@ -87,7 +86,6 @@ let configServiceSpy: jasmine.SpyObj<ConfigService>;
describe('AssignJudgeComponent', () => {
beforeEach(waitForAsync(() => {
const newHearing = initHearingRequest();
clientApiSpy = jasmine.createSpyObj<BHClient>('BHClient', ['getFeatureFlag']);
loggerSpy = jasmine.createSpyObj<Logger>('Logger', ['error', 'debug', 'warn']);
configServiceSpy = jasmine.createSpyObj<ConfigService>('ConfigService', ['getClientSettings']);
emailValidationServiceSpy = jasmine.createSpyObj<EmailValidationService>('EmailValidationService', [
Expand Down Expand Up @@ -115,7 +113,6 @@ describe('AssignJudgeComponent', () => {
judgeDataServiceSpy.getJudges.and.returnValue(of(MockValues.Judges));
configServiceSpy = jasmine.createSpyObj<ConfigService>('CongigService', ['getClientSettings']);
configServiceSpy.getClientSettings.and.returnValue(of(configSettings));
clientApiSpy.getFeatureFlag.and.returnValue(of(true));

TestBed.configureTestingModule({
imports: [SharedModule, RouterTestingModule],
Expand All @@ -125,7 +122,6 @@ describe('AssignJudgeComponent', () => {
{ provide: EmailValidationService, useValue: emailValidationServiceSpy },
{ provide: ConfigService, useValue: configServiceSpy },
{ provide: LaunchDarklyService, useValue: launchDarklyServiceSpy },
{ provide: BHClient, useValue: clientApiSpy },
{
provide: Router,
useValue: {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import { Router } from '@angular/router';
import { VideoHearingsService } from '../../services/video-hearings.service';
import { BreadcrumbComponent } from './breadcrumb.component';
import { BreadcrumbItemModel } from './breadcrumbItem.model';
import { FeatureFlagService } from '../../services/feature-flag.service';
import { of } from 'rxjs';
import { PageUrls } from '../../shared/page-url.constants';
import { BreadcrumbItems } from './breadcrumbItems';
import { FeatureFlags, LaunchDarklyService } from 'src/app/services/launch-darkly.service';
describe('BreadcrumbComponent', () => {
const videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>([
'validCurrentRequest',
'isConferenceClosed',
'isHearingAboutToStart'
]);
let featureFlagServiceSpy: jasmine.SpyObj<FeatureFlagService>;
let launchDarklyServiceSpy: jasmine.SpyObj<LaunchDarklyService>;
let component: BreadcrumbComponent;
const router = {
url: '/hearing-schedule',
...jasmine.createSpyObj<Router>(['navigate'])
} as jasmine.SpyObj<Router>;
beforeEach(async () => {
featureFlagServiceSpy = jasmine.createSpyObj<FeatureFlagService>('FeatureToggleService', ['getFeatureFlagByName']);
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(true));
component = new BreadcrumbComponent(router, videoHearingsServiceSpy, featureFlagServiceSpy);
launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
component = new BreadcrumbComponent(router, videoHearingsServiceSpy, launchDarklyServiceSpy);
component.breadcrumbItems = BreadcrumbItems.slice();
component.canNavigate = true;
await component.ngOnInit();
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('BreadcrumbComponent', () => {
});

it('should set the breadcrumb name for assign-judge as Judge when staff member feature is OFF', () => {
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(false));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(false));
component.ngOnInit();
expect(component.breadcrumbItems.find(b => b.Url === PageUrls.AssignJudge).Name).toBe('Judge');
});
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('BreadcrumbComponent', () => {
});

it('when ejud feature flag is off, assign judge should NOT be marked as active', async () => {
featureFlagServiceSpy.getFeatureFlagByName.and.returnValue(of(false));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(false));
await component.ngOnInit();
const assignJudgeCrumb = breadCrumbs.find(e => e.Url === '/assign-judge');
expect(assignJudgeCrumb.Active).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
async ngOnInit() {
this.currentRouter = this.router.url;
this.featureService
.getFlag<boolean>(FeatureFlags.eJudFeature, false)
.getFlag<boolean>(FeatureFlags.eJudFeature)
.pipe(takeUntil(this.destroyed$))
.subscribe(result => {
this.ejudFeatureFlag = result;
Expand Down
Loading

0 comments on commit 0fefa5b

Please sign in to comment.