Skip to content

Commit

Permalink
Merge pull request #6440 from NMDSdevopsServiceAdm/fix/funding-no-sta…
Browse files Browse the repository at this point in the history
…ff-records-link

Fix: Set links for staff records tab correctly for no staff records message
  • Loading branch information
duncanc19 authored Dec 5, 2024
2 parents 7c44627 + a42ef5a commit a677f6c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { WdfModule } from '../wdf.module';
import { WdfStaffSummaryComponent } from './wdf-staff-summary.component';

describe('WdfStaffSummaryComponent', () => {
const setup = async (overrides: { componentProperties?: any; report?: any } = {}) => {
const setup = async (overrides: any = {}) => {
const establishment = establishmentBuilder() as Establishment;
const workers = [workerBuilder(), workerBuilder(), workerBuilder()] as Worker[];

Expand All @@ -50,7 +50,7 @@ describe('WdfStaffSummaryComponent', () => {
queryParamMap: {
get: sinon.fake(),
},
params: {
params: overrides?.params ?? {
establishmentuid: establishment.uid,
},
},
Expand All @@ -60,7 +60,6 @@ describe('WdfStaffSummaryComponent', () => {
],
componentProperties: {
workplace: establishment,
wdfView: true,
workers: workers,
workerCount: workers.length,
...overrides?.componentProperties,
Expand All @@ -70,6 +69,7 @@ describe('WdfStaffSummaryComponent', () => {

const injector = getTestBed();
const router = injector.inject(Router) as Router;
const routerSpy = spyOn(router, 'navigate').and.returnValue(null);
const workerService = injector.inject(WorkerService) as WorkerService;

const getAllWorkersSpy = spyOn(workerService, 'getAllWorkers').and.returnValue(
Expand All @@ -79,7 +79,7 @@ describe('WdfStaffSummaryComponent', () => {
return {
...setupTools,
component,
router,
routerSpy,
getAllWorkersSpy,
};
};
Expand Down Expand Up @@ -167,8 +167,10 @@ describe('WdfStaffSummaryComponent', () => {
userEvent.type(getByLabelText('Search by name or ID number for staff records'), 'search term here{enter}');
expect(getAllWorkersSpy.calls.mostRecent().args[1].pageIndex).toEqual(0);
});
});

it('should display the message when there is no staff', async () => {
describe('No staff records message', () => {
it('should display the message when there are no staff records', async () => {
const overrides = {
componentProperties: {
workers: [],
Expand All @@ -185,6 +187,44 @@ describe('WdfStaffSummaryComponent', () => {
expect(noRecordsTestId).toBeTruthy();
expect(noRecordsTestId.textContent).toContain(message);
});

it('should navigate to staff records tab when is not parent user viewing sub workplace (no uid in params)', async () => {
const overrides = {
componentProperties: {
workers: [],
workerCount: 0,
},
params: {},
};

const { getByText, routerSpy } = await setup(overrides);

const staffRecordsLink = getByText('add some staff records');
userEvent.click(staffRecordsLink);

expect(routerSpy).toHaveBeenCalledWith(['dashboard'], { fragment: 'staff-records' });
});

it('should navigate to subsidiary staff records tab when parent user viewing sub workplace (uid in params)', async () => {
const workplace = establishmentBuilder();
workplace.uid = 'a123koj3213233';

const overrides = {
componentProperties: {
workers: [],
workerCount: 0,
workplace,
},
params: { establishmentuid: workplace.uid },
};

const { getByText, routerSpy } = await setup(overrides);

const staffRecordsLink = getByText('add some staff records');
userEvent.click(staffRecordsLink);

expect(routerSpy).toHaveBeenCalledWith(['/subsidiary', workplace.uid, 'staff-records']);
});
});

describe('Eligibility icons for staff', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { orderBy } from 'lodash';
})
export class WdfStaffSummaryComponent extends StaffSummaryDirective {
public workplaceUid: string;
public primaryWorkplaceUid: string;
public overallWdfEligibility: boolean;
public wdfView = true;

constructor(
protected permissionsService: PermissionsService,
Expand Down Expand Up @@ -70,6 +68,10 @@ export class WdfStaffSummaryComponent extends StaffSummaryDirective {

public navigateToStaffRecords(event: Event): void {
event.preventDefault();
this.tabsService.selectedTab = 'staff-records';
if (this.route.snapshot.params.establishmentuid) {
this.router.navigate(['/subsidiary', this.workplace.uid, 'staff-records']);
} else {
this.router.navigate(['dashboard'], { fragment: 'staff-records' });
}
}
}

0 comments on commit a677f6c

Please sign in to comment.