Skip to content

Commit

Permalink
edm-433 format and text update (#34086)
Browse files Browse the repository at this point in the history
  • Loading branch information
flex2016 authored Jan 14, 2025
1 parent fd7c151 commit cb546d5
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 29 deletions.
8 changes: 3 additions & 5 deletions src/applications/gi/containers/NationalExamDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const NationalExamDetails = () => {
data-e2e-id="alert-box"
>
<h2 slot="headline">
We can’t load the National exam details right now
We can’t load the national exam details right now
</h2>
<p>
We’re sorry. There’s a problem with our system. Try again later.
Expand All @@ -112,7 +112,7 @@ const NationalExamDetails = () => {
<div className="row vads-u-margin-bottom--8 vads-u-padding--1p5 mobile-lg:vads-u-padding--0">
<va-loading-indicator
label="Loading"
message="Loading your National exam details..."
message="Loading your national exam details..."
/>
</div>
);
Expand Down Expand Up @@ -144,10 +144,8 @@ const NationalExamDetails = () => {
{institution?.physicalAddress?.address1}
<br />
{institution.physicalAddress?.city},
{institution.physicalAddress?.state}
{institution.physicalAddress?.state}{' '}
{institution.physicalAddress?.zip}
<br />
{institution.physicalAddress?.country}
</p>
</div>

Expand Down
19 changes: 12 additions & 7 deletions src/applications/gi/containers/NationalExamsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
VaLink,
} from '@department-of-veterans-affairs/component-library/dist/react-bindings';
import { fetchNationalExams } from '../actions';
import { formatNationalExamName } from '../utils/helpers';

const NationalExamsList = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -83,7 +84,7 @@ const NationalExamsList = () => {
data-e2e-id="alert-box"
>
<h2 slot="headline">
We can’t load the National exams list right now
We can’t load the national exams list right now
</h2>
<p>
We’re sorry. There’s a problem with our system. Try again later.
Expand All @@ -98,7 +99,7 @@ const NationalExamsList = () => {
<NationalExamsInfo />
<va-loading-indicator
label="Loading"
message="Loading your National exams..."
message="Loading your national exams..."
/>
</div>
);
Expand All @@ -122,14 +123,18 @@ const NationalExamsList = () => {
{currentExams.map(exam => (
<li key={exam.enrichedId} className="vads-u-margin-bottom--2p5">
<VaCard background>
<h3 className="vads-u-margin--0">{exam.name}</h3>
<h3 className="vads-u-margin--0">
{formatNationalExamName(exam.name)}
</h3>
<VaLinkAction
href={`national-exams/${exam.enrichedId}`}
text={`View test amount details for ${exam.name}`}
text={`View test amount details for ${formatNationalExamName(
exam.name,
)}`}
type="secondary"
message-aria-describedby={`View test amount details for ${
exam.name
}`}
message-aria-describedby={`View test amount details for ${formatNationalExamName(
exam.name,
)}`}
onClick={handleRouteChange(exam.enrichedId)}
/>
</VaCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('NationalExamDetails', () => {
const wrapper = mountComponent();
expect(wrapper.find('va-loading-indicator').exists()).to.be.true;
expect(wrapper.find('va-loading-indicator').prop('message')).to.equal(
'Loading your National exam details...',
'Loading your national exam details...',
);
wrapper.unmount();
});
Expand All @@ -80,7 +80,7 @@ describe('NationalExamDetails', () => {
expect(alert.exists()).to.be.true;
expect(alert.prop('status')).to.equal('error');
expect(alert.find('h2[slot="headline"]').text()).to.equal(
'We can’t load the National exam details right now',
'We can’t load the national exam details right now',
);
expect(alert.find('p').text()).to.include(
'We’re sorry. There’s a problem with our system. Try again later.',
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('NationalExamDetails', () => {
expect(institutionSpan.exists()).to.be.true;
const addressBlock = wrapper.find('.va-address-block');
expect(addressBlock.text()).to.contain('123 Main St');
expect(addressBlock.text()).to.contain('Anytown,VA12345');
expect(addressBlock.text()).to.contain('Anytown,VA 12345');
const formLink = wrapper.find(
'va-link[href="https://www.va.gov/find-forms/about-form-22-0810/"]',
);
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('NationalExamDetails', () => {
const wrapper = mountComponent();
expect(wrapper.find('va-loading-indicator').exists()).to.be.true;
expect(wrapper.find('va-loading-indicator').prop('message')).to.equal(
'Loading your National exam details...',
'Loading your national exam details...',
);
wrapper.unmount();
});
Expand Down
21 changes: 8 additions & 13 deletions src/applications/gi/tests/containers/NationalExams.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import { VaPagination } from '@department-of-veterans-affairs/component-library/dist/react-bindings';
import NationalExamsList from '../../containers/NationalExamsList';
import { formatNationalExamName } from '../../utils/helpers';

const mockExams = [
{
Expand Down Expand Up @@ -167,28 +168,22 @@ describe('NationalExamsList', () => {
const newPage = 2;
const itemsPerPage = 10;

// Trigger a page change to the second page
wrapper.find('VaPagination').prop('onPageSelect')({
detail: { page: newPage },
});
wrapper.update();

// Wait a tick for asynchronous updates
await new Promise(resolve => setTimeout(resolve, 0));

// Determine which exam names we expect on page 2
const expectedItems = initialState.nationalExams.nationalExams
.slice((newPage - 1) * itemsPerPage, newPage * itemsPerPage)
.map(exam => exam.name);

// Grab the displayed exam names from the UI
const expectedItemsFormatted = expectedItems.map(name =>
formatNationalExamName(name),
);
const displayedItems = wrapper.find('li h3').map(node => node.text());

// Confirm that the displayed items match what we expect
expect(displayedItems).to.deep.equal(expectedItems);

expect(displayedItems).to.deep.equal(expectedItemsFormatted);
wrapper.unmount();
});

it('displays the loading indicator when loading is true', () => {
// Mount the component with loading state set to true
store = mockStore({
Expand All @@ -210,7 +205,7 @@ describe('NationalExamsList', () => {
expect(loadingIndicator.exists()).to.be.true;
expect(loadingIndicator.prop('label')).to.equal('Loading');
expect(loadingIndicator.prop('message')).to.equal(
'Loading your National exams...',
'Loading your national exams...',
);
wrapper.unmount();
});
Expand Down Expand Up @@ -264,7 +259,7 @@ describe('NationalExamsList', () => {
expect(alert.exists()).to.be.true;
expect(alert.prop('status')).to.equal('error');
expect(alert.find('h2[slot="headline"]').text()).to.equal(
'We can’t load the National exams list right now',
'We can’t load the national exams list right now',
);
expect(alert.find('p').text()).to.include(
'We’re sorry. There’s a problem with our system. Try again later.',
Expand Down
64 changes: 64 additions & 0 deletions src/applications/gi/tests/utils/helpers.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
deriveEligibleStudents,
capitalizeFirstLetter,
getAbbreviationsAsArray,
formatNationalExamName,
} from '../../utils/helpers';

describe('GIBCT helpers:', () => {
Expand Down Expand Up @@ -712,4 +713,67 @@ describe('GIBCT helpers:', () => {
expect(getAbbreviationsAsArray('XYZ')).to.deep.equal([]);
});
});

describe('formatNationalExamName', () => {
it('should return an empty string when name is null', () => {
expect(formatNationalExamName(null)).to.equal('');
});

it('should return an empty string when name is undefined', () => {
expect(formatNationalExamName(undefined)).to.equal('');
});

it('should return an empty string when name is an empty string', () => {
expect(formatNationalExamName('')).to.equal('');
});

it('should return an empty string when name is only whitespace', () => {
expect(formatNationalExamName(' ')).to.equal('');
});

it('should return "DSST-DANTES" unchanged', () => {
expect(formatNationalExamName('DSST-DANTES')).to.equal('DSST-DANTES');
});

it('should format "MAT-MILLER ANALOGIES TEST" to "MAT-MILLER analogies test"', () => {
expect(formatNationalExamName('MAT-MILLER ANALOGIES TEST')).to.equal(
'MAT-MILLER analogies test',
);
});

it('should return "ECE (4 hours)" unchanged', () => {
expect(formatNationalExamName('ECE (4 hours)')).to.equal('ECE (4 hours)');
});

it('should return "ECE (6 hours)" unchanged', () => {
expect(formatNationalExamName('ECE (6 hours)')).to.equal('ECE (6 hours)');
});

it('should format "ECE 8 HOURS NURSING" to "ECE (8 hours) nursing"', () => {
expect(formatNationalExamName('ECE 8 HOURS NURSING')).to.equal(
'ECE (8 hours) nursing',
);
});

it('should format "DANTES SPONSORED CLEP EXAMS" to "DANTES sponsored clep exams"', () => {
expect(formatNationalExamName('DANTES SPONSORED CLEP EXAMS')).to.equal(
'DANTES sponsored clep exams',
);
});

it('should properly split on dash and lowercase the right side', () => {
expect(formatNationalExamName('AP-ADVANCED PLACEMENT EXAMS')).to.equal(
'AP-advanced placement exams',
);
expect(
formatNationalExamName('CLEP-COLLEGE LEVEL EXAMINATION PROGRAM'),
).to.equal('CLEP-college level examination program');
});

it('should return the original name if no other condition is met', () => {
expect(formatNationalExamName('ACT')).to.equal('ACT');
expect(formatNationalExamName('MCAT')).to.equal('MCAT');
expect(formatNationalExamName('TOEFL')).to.equal('TOEFL');
});
});
});
35 changes: 35 additions & 0 deletions src/applications/gi/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,38 @@ export const getAbbreviationsAsArray = value => {

return items.map(item => `${item.abbreviation}: ${item.description}`);
};

export const formatNationalExamName = name => {
if (!name || !name.trim()) {
return '';
}

if (name === 'DSST-DANTES') {
return name;
}

if (name === 'MAT-MILLER ANALOGIES TEST') {
return 'MAT-MILLER analogies test';
}

if (name === 'ECE (4 hours)' || name === 'ECE (6 hours)') {
return name;
}

const eceNursingMatch = name.match(/^ECE\s+(\d+)\s+HOURS\s+NURSING$/i);
if (eceNursingMatch) {
const hours = eceNursingMatch[1];
return `ECE (${hours} hours) nursing`;
}

if (name === 'DANTES SPONSORED CLEP EXAMS') {
return 'DANTES sponsored clep exams';
}

if (name.includes('-')) {
const [left, right] = name.split('-', 2);
return `${left}-${right.toLowerCase()}`;
}

return name;
};

0 comments on commit cb546d5

Please sign in to comment.