Skip to content

Commit

Permalink
Merge pull request #2387 from HHS/main
Browse files Browse the repository at this point in the history
[PROD] TTAHUB-3329 Fix view of TR event after restructure
  • Loading branch information
Jones-QuarteyDana authored Sep 30, 2024
2 parents c1a699d + ba65915 commit cb25068
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ parameters:
type: string
dev_git_branch: # change to feature branch to test deployment
description: "Name of github branch that will deploy to dev"
default: "al-ttahub-3196-new-tr-views"
default: "al-ttahub-3329-fix-event-view"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "kw-fix-duplicate-programs"
Expand Down
164 changes: 162 additions & 2 deletions frontend/src/pages/ViewTrainingReport/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const mockEvent = (data = {}) => ({
eventName: 'Health Webinar Series: Oral Health and Dental Care from a Regional and State Perspective',
eventOrganizer: 'Regional PD Event (with National Centers)',
'Full Event Title': 'R03 Health Webinar Series: Oral Health and Dental Care from a Regional and State Perspective',
targetPopulations: ['None'],
targetPopulations: ['Tgt Pop 1'],
'Event Duration/# NC Days of Support': 'Series',
},
updatedAt: '2023-06-27T13:46:29.884Z',
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('ViewTrainingReport', () => {
expect(screen.getByText('Regional PD Event (with National Centers)')).toBeInTheDocument();

// target populations
expect(screen.getByText('None')).toBeInTheDocument();
expect(screen.getByText('Tgt Pop 1')).toBeInTheDocument();

// session 1
expect(screen.getByText('Session 1')).toBeInTheDocument();
Expand Down Expand Up @@ -581,6 +581,166 @@ describe('ViewTrainingReport', () => {
expect(await screen.findByText('USER 2')).toBeInTheDocument();
});

it('displays the is ist visit field and the appropriate participants', async () => {
const e = mockEvent();
e.sessionReports = [{
...e.sessionReports[0],
data: {
...e.sessionReports[0].data,
isIstVisit: 'yes',
regionalOfficeTta: ['Ist Office 1', 'Ist Office 2'],
},
},
{
...e.sessionReports[1],
data: {
...e.sessionReports[1].data,
isIstVisit: 'no',
recipients: [{ label: 'Recipient 1' }, { label: 'Recipient 2' }],
participants: ['Participants 1', 'Participants 2'],
},
}];
fetchMock.getOnce('/api/events/id/1?readOnly=true', e);

fetchMock.getOnce('/api/users/names?ids=1', ['USER 1']);
fetchMock.getOnce('/api/users/names?ids=2', ['USER 2']);

act(() => {
renderTrainingReport();
});

expect(await screen.findByRole('heading', { name: 'Training event report R03-PD-23-1037' })).toBeInTheDocument();

expect(screen.queryAllByText('IST visit').length).toBe(2);
expect(await screen.findByText('Regional Office/TTA')).toBeInTheDocument();
expect(await screen.findByText('Yes')).toBeInTheDocument();
expect(await screen.findByText(/ist office 1, ist office 2/i)).toBeInTheDocument();

expect(await screen.findByText('Recipient participants')).toBeInTheDocument();
expect(await screen.findByText('No')).toBeInTheDocument();
expect(await screen.findByText(/Recipient 1, Recipient 2/i)).toBeInTheDocument();

expect(await screen.findByText('Recipient participants')).toBeInTheDocument();
expect(await screen.findByText(/Participants 1, Participants 2/i)).toBeInTheDocument();
});

it('displays the delivery method field and the appropriate participants attending', async () => {
const e = mockEvent();
e.sessionReports = [{
...e.sessionReports[0],
data: {
...e.sessionReports[0].data,
deliveryMethod: 'in-person',
numberOfParticipants: 10,
},
},
{
...e.sessionReports[1],
data: {
...e.sessionReports[1].data,
deliveryMethod: 'hybrid',
numberOfParticipantsInPerson: 11,
numberOfParticipantsVirtually: 12,
},
}];
fetchMock.getOnce('/api/events/id/1?readOnly=true', e);

fetchMock.getOnce('/api/users/names?ids=1', ['USER 1']);
fetchMock.getOnce('/api/users/names?ids=2', ['USER 2']);

act(() => {
renderTrainingReport();
});

expect(await screen.findByRole('heading', { name: 'Training event report R03-PD-23-1037' })).toBeInTheDocument();

expect(screen.queryAllByText('Delivery method').length).toBe(2);
expect(await screen.findByText('In-person')).toBeInTheDocument();
expect(await screen.findByText('Number of participants')).toBeInTheDocument();
expect(await screen.findByText('10')).toBeInTheDocument();

expect(await screen.findByText('Hybrid')).toBeInTheDocument();
expect(await screen.findByText('Number of participants attending in person')).toBeInTheDocument();
expect(await screen.findByText('11')).toBeInTheDocument();
expect(await screen.findByText('Number of participants attending virtually')).toBeInTheDocument();
expect(await screen.findByText('12')).toBeInTheDocument();
});

it('display the correct value for Is IST visit if the value isIstVisit is not set and we have recipients', async () => {
const e = mockEvent();
e.sessionReports = [{
...e.sessionReports[0],
data: {
...e.sessionReports[0].data,
isIstVisit: null,
},
}];

fetchMock.getOnce('/api/events/id/1?readOnly=true', e);
fetchMock.getOnce('/api/users/names?ids=1', ['USER 1']);
fetchMock.getOnce('/api/users/names?ids=2', ['USER 2']);

act(() => {
renderTrainingReport();
});

expect(await screen.findByRole('heading', { name: 'Training event report R03-PD-23-1037' })).toBeInTheDocument();
expect(await screen.findByText('No')).toBeInTheDocument();

expect(screen.queryAllByText('IST visit').length).toBe(1);
});

it('display the correct value for Is IST visit if the value isIstVisit is not set and we have no recipients', async () => {
const e = mockEvent();
e.sessionReports = [{
...e.sessionReports[0],
data: {
...e.sessionReports[0].data,
isIstVisit: null,
recipients: [],
regionalOfficeTta: ['office 1', 'office 2'],
},
}];

fetchMock.getOnce('/api/events/id/1?readOnly=true', e);
fetchMock.getOnce('/api/users/names?ids=1', ['USER 1']);
fetchMock.getOnce('/api/users/names?ids=2', ['USER 2']);

act(() => {
renderTrainingReport();
});

expect(await screen.findByRole('heading', { name: 'Training event report R03-PD-23-1037' })).toBeInTheDocument();
expect(await screen.findByText('Yes')).toBeInTheDocument();

expect(screen.queryAllByText('IST visit').length).toBe(1);
expect(await screen.findByText(/office 1, office 2/i)).toBeInTheDocument();
});

it('displays none for objectiveResources not set', async () => {
const e = mockEvent();
e.sessionReports = [{
...e.sessionReports[0],
data: {
...e.sessionReports[0].data,
objectiveResources: [{ value: '' }],
courses: [],
files: [],
},
}];

fetchMock.getOnce('/api/events/id/1?readOnly=true', e);
fetchMock.getOnce('/api/users/names?ids=1', ['USER 1']);
fetchMock.getOnce('/api/users/names?ids=2', ['USER 2']);

act(() => {
renderTrainingReport();
});

expect(await screen.findByRole('heading', { name: 'Training event report R03-PD-23-1037' })).toBeInTheDocument();
expect(await screen.queryAllByText('None').length).toBe(3);
});

describe('formatOwnerName', () => {
test('handles an error', () => {
const result = formatOwnerName({ eventReportPilotNationalCenterUsers: 123 });
Expand Down
61 changes: 44 additions & 17 deletions frontend/src/pages/ViewTrainingReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,48 @@ export default function ViewTrainingReport({ match }) {
'Training type': event.data['Event Duration/# NC Days of Support'],
Reasons: event.data.reasons,
'Target populations': event.data.targetPopulations,
},
striped: true,
}, {
heading: 'Vision',
data: {
Vision: event.data.vision,
},
striped: true,
}] : [];

const isIstVisit = (session) => {
if (session.data.isIstVisit === 'yes' || (session.data.regionalOfficeTta && session.data.regionalOfficeTta.length > 0)) {
return true;
}
return false;
};

const generateIstOfficeOrRecipientProperties = (session) => {
if (isIstVisit(session)) {
return {
'Regional Office/TTA': session.data.regionalOfficeTta.join(', '),
};
}

return {
Recipients: session.data.recipients ? session.data.recipients.map((r) => r.label).join(', ') : '',
'Recipient participants': session.data.participants ? session.data.participants.join(', ') : [],
};
};

const generateNumberOfParticipants = (session) => {
// In person or virtual.
if (session.data.deliveryMethod === 'in-person' || session.data.deliveryMethod === 'virtual') {
const numberOfParticipants = session.data.numberOfParticipants ? session.data.numberOfParticipants.toString() : '';
return {
'Number of participants': numberOfParticipants,
};
}
// Hybrid.
const numberOfParticipantsInPerson = session.data.numberOfParticipantsInPerson ? session.data.numberOfParticipantsInPerson.toString() : '';
const numberOfParticipantsVirtually = session.data.numberOfParticipantsVirtually ? session.data.numberOfParticipantsVirtually.toString() : '';
return {
'Number of participants attending in person': numberOfParticipantsInPerson,
'Number of participants attending virtually': numberOfParticipantsVirtually,
};
};

const sessions = event && event.sessionReports ? event.sessionReports.map((session, index) => (
<ReadOnlyContent
key={session.id}
Expand All @@ -244,25 +277,19 @@ export default function ViewTrainingReport({ match }) {
'Session objective': session.data.objective,
Topics: session.data.objectiveTopics,
Trainers: session.data.objectiveTrainers,
'Resource links': session.data.objectiveResources ? session.data.objectiveResources.map((o) => o.value) : [],
'iPD Courses': session.data.courses ? session.data.courses.map((o) => o.name) : [],
'Resource attachments': session.data.files ? session.data.files.map((f) => f.originalFileName) : [],
'Resource links': session.data.objectiveResources && session.data.objectiveResources.filter((r) => r.value).length ? session.data.objectiveResources.map((o) => o.value) : 'None',
'iPD Courses': session.data.courses && session.data.courses.length ? session.data.courses.map((o) => o.name) : 'None',
'Resource attachments': session.data.files && session.data.files.length ? session.data.files.map((f) => f.originalFileName) : 'None',
'Support type': session.data.objectiveSupportType,
},
}, {
heading: 'Participants',
striped: true,
data: {
Recipients: session.data.recipients ? session.data.recipients.map((r) => r.label).join(', ') : '',
'Recipient participants': session.data.participants ? session.data.participants.join(', ') : [],
'Number of participants': String((
session.data.numberOfParticipants || 0
) + (
session.data.numberOfParticipantsVirtually || 0
) + (
session.data.numberOfParticipantsInPerson || 0
)),
'IST visit': isIstVisit(session) ? 'Yes' : 'No',
...generateIstOfficeOrRecipientProperties(session),
'Delivery method': capitalize(session.data.deliveryMethod || ''),
...generateNumberOfParticipants(session),
'Language used': session.data.language ? session.data.language.join(', ') : [],
'TTA provided': session.data.ttaProvided,
},
Expand Down
Loading

0 comments on commit cb25068

Please sign in to comment.