Skip to content

Commit

Permalink
Vebt 847 unit tests (#33759)
Browse files Browse the repository at this point in the history
* added unit test for form 22-10215

* vebt-847 added more unit test for 22-10215
  • Loading branch information
wafimohamed authored Dec 24, 2024
1 parent 62bb22d commit d56bb41
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/applications/edu-benefits/10215/config/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ProgramSummary,
} from '../pages';

const arrayBuilderOptions = {
export const arrayBuilderOptions = {
arrayPath: 'programs',
nounSingular: 'program',
nounPlural: 'programs',
Expand Down
9 changes: 5 additions & 4 deletions src/applications/edu-benefits/10215/config/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export default function transform(formConfig, form) {
//
// Include total enrolled FTE And supported student percentage FTE if 10+ supported students enrolled
//
formData.data.programs = formData.data.programs.map(program => {
formData.data.programs = formData.data?.programs?.map(program => {
const programWithCalcs = program;
if (!Number(program.supportedStudents) < 10 && program.fte) {
const { total, supportedFTEPercent } = getFTECalcs(program);
programWithCalcs.fte.totalFTE = total;
programWithCalcs.fte.supportedPercentageFTE = supportedFTEPercent;
const fteCalcs = getFTECalcs(program);
programWithCalcs.fte.totalFTE = fteCalcs?.total;
programWithCalcs.fte.supportedPercentageFTE =
fteCalcs?.supportedFTEPercent;
}
return programWithCalcs;
});
Expand Down
10 changes: 8 additions & 2 deletions src/applications/edu-benefits/10215/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as institutionDetails from './institutionDetails';
import { ProgramIntro } from './program-intro';
import { programInfo } from './program-info';
import { ProgramSummary } from './program-summary';
import { ProgramSummary, arrayBuilderOptions } from './program-summary';

export { institutionDetails, ProgramIntro, programInfo, ProgramSummary };
export {
institutionDetails,
ProgramIntro,
programInfo,
ProgramSummary,
arrayBuilderOptions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
arrayBuilderYesNoUI,
} from '~/platform/forms-system/src/js/web-component-patterns';

const arrayBuilderOptions = {
export const arrayBuilderOptions = {
arrayPath: 'programs',
nounSingular: 'program',
nounPlural: 'programs',
Expand Down
42 changes: 42 additions & 0 deletions src/applications/edu-benefits/10215/tests/config/form.unit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { render } from '@testing-library/react';
import formConfig, { arrayBuilderOptions } from '../../config/form';
import manifest from '../../manifest.json';

describe('22-10215 Form Config', () => {
it('should render', () => {
expect(formConfig).to.be.an('object');
});
it('should have a required properties', () => {
expect(formConfig.rootUrl).to.contain(manifest.rootUrl);
expect(formConfig.title).to.contain('Report 85/15 Rule enrollment ratio');
const { getByText } = render(formConfig.subTitle()); // Render the subTitle component
expect(
getByText(
'Statement of Assurance of Compliance with 85% Enrollment Ratios (VA Form 22-10215)',
),
).of.exist;
expect(formConfig).to.have.property('chapters');
});
it('should return the correct item name', () => {
const item = { programName: 'Test Program' };
expect(arrayBuilderOptions.text.getItemName(item)).to.equal('Test Program');
});

it('should return the correct card description', () => {
const item = {
programName: 'Test Program',
supportedFTEPercent: 50,
};
const mockGetFTECalcs = sinon.stub().returns({ supportedFTEPercent: 50 });
global.getFTECalcs = mockGetFTECalcs;
const description = arrayBuilderOptions.text.cardDescription(item);
expect(description).to.not.equal('50 supported student FTE');

mockGetFTECalcs.returns({ supportedFTEPercent: null });
expect(arrayBuilderOptions.text.cardDescription(item)).to.be.null;

delete global.getFTECalcs;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect } from 'chai';
import sinon from 'sinon';
import * as helpers from '../../helpers';
import transform from '../../config/transform';

describe('transform utility function', () => {
let formConfig;
let form;
let getFTECalcsStub;

beforeEach(() => {
formConfig = {};
form = {
data: {
programs: [
{
programName: 'Program A',
supportedStudents: '10',
fte: {
totalFTE: 0,
supportedPercentageFTE: 0,
},
},
{
programName: 'Program B',
supportedStudents: '9',
fte: {
totalFTE: 0,
supportedPercentageFTE: 0,
},
},
],
},
};
getFTECalcsStub = sinon.stub(helpers, 'getFTECalcs');
});

afterEach(() => {
getFTECalcsStub.restore();
});
it('should not modify FTE fields if the program has fewer than 10 supported students', () => {
form.data.programs = [
{
programName: 'Program C',
supportedStudents: '8',
fte: {
totalFTE: 0,
supportedPercentageFTE: 0,
},
},
];

const resultString = transform(formConfig, form);
const resultObject = JSON.parse(resultString);
expect(resultObject.educationBenefitsClaim).to.exist;
expect(resultObject.educationBenefitsClaim.form).to.exist;
});
});
2 changes: 0 additions & 2 deletions src/applications/edu-benefits/10215/tests/form.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ describe('22-10215 - Form Config', () => {
expect(formConfig).to.have.property('submit');
expect(formConfig).to.have.property('saveInProgress');
});

// Introduction and Get Help components to be added
});
60 changes: 60 additions & 0 deletions src/applications/edu-benefits/10215/tests/helper.unit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// src/applications/edu-benefits/10215/helpers.test.js
import { expect } from 'chai';
import { getFTECalcs } from '../helpers';

describe('getFTECalcs', () => {
it('should return correct FTE calculations for supported and non-supported values', () => {
const program = { fte: { supported: 5, nonSupported: 15 } };
const result = getFTECalcs(program);
expect(result).to.deep.equal({
supported: 5,
nonSupported: 15,
total: 20,
supportedFTEPercent: '25%',
});
});

it('should handle zero supported and non-supported values', () => {
const program = { fte: { supported: 0, nonSupported: 0 } };
const result = getFTECalcs(program);
expect(result).to.deep.equal({
supported: 0,
nonSupported: 0,
total: 0,
supportedFTEPercent: null,
});
});

it('should handle only supported values', () => {
const program = { fte: { supported: 10, nonSupported: 0 } };
const result = getFTECalcs(program);
expect(result).to.deep.equal({
supported: 10,
nonSupported: 0,
total: 10,
supportedFTEPercent: '100%',
});
});

it('should handle only non-supported values', () => {
const program = { fte: { supported: 0, nonSupported: 10 } };
const result = getFTECalcs(program);
expect(result).to.deep.equal({
supported: 0,
nonSupported: 10,
total: 10,
supportedFTEPercent: null,
});
});

it('should return null for supportedFTEPercent when total is NaN', () => {
const program = { fte: { supported: null, nonSupported: null } };
const result = getFTECalcs(program);
expect(result).to.deep.equal({
supported: 0,
nonSupported: 0,
total: 0,
supportedFTEPercent: null,
});
});
});
81 changes: 81 additions & 0 deletions src/applications/edu-benefits/10215/tests/pages/calcs.unit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// src/applications/edu-benefits/10215/pages/calcs.test.js
import React from 'react';
import { mount } from 'enzyme';
import { expect } from 'chai';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import Calcs from '../../pages/calcs';

const mockStore = configureStore();

describe('<Calcs />', () => {
const mockData = {
programs: [
{
supported: true,
nonSupported: false,
total: 10,
supportedFTEPercent: 100,
},
],
};

it('should render correctly with given props', () => {
const store = mockStore({ form: { data: mockData } });
const wrapper = mount(
<Provider store={store}>
<Calcs data={mockData} />
</Provider>,
);

expect(
wrapper
.find('label')
.at(0)
.text(),
).to.equal('Total Enrolled FTE');
expect(
wrapper
.find('span')
.at(0)
.text(),
).to.equal('--');
expect(
wrapper
.find('label')
.at(1)
.text(),
).to.equal('Supported student percentage FTE');
expect(
wrapper
.find('span')
.at(1)
.text(),
).to.equal('--%');
wrapper.unmount();
});

it('should render "--" when no data is available', () => {
const emptyData = { programs: [] };
const store = mockStore({ form: { data: emptyData } });
const wrapper = mount(
<Provider store={store}>
<Calcs data={emptyData} />
</Provider>,
);

expect(
wrapper
.find('span')
.at(0)
.text(),
).to.equal('--');
expect(
wrapper
.find('span')
.at(1)
.text(),
).to.equal('--%');
wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { expect } from 'chai';
import { programInfo } from '../../pages';

describe('programInfo configuration', () => {
describe('uiSchema', () => {
it('should have the expected top-level fields', () => {
const { uiSchema } = programInfo;

expect(uiSchema).to.have.property('programName');
expect(uiSchema).to.have.property('studentsEnrolled');
expect(uiSchema).to.have.property('supportedStudents');
expect(uiSchema).to.have.property('fte');
expect(uiSchema).to.have.property('view:calcs');
});

it('should have a valid ui:description in uiSchema', () => {
const description = programInfo.uiSchema['ui:description'];
expect(description).to.be.a('object');
expect(description.props).to.have.property('href');
expect(description.props).to.have.property('text');
});

it('should require fte.supported and fte.nonSupported only when supportedStudents >= 10', () => {
const { uiSchema } = programInfo;

// For "supported"
const supportedRequiredFn = uiSchema.fte.supported['ui:required'];
expect(supportedRequiredFn).to.be.a('function');

// For "nonSupported"
const nonSupportedRequiredFn = uiSchema.fte.nonSupported['ui:required'];
expect(nonSupportedRequiredFn).to.be.a('function');

let formData = {
programs: [{ supportedStudents: 15 }],
};
expect(supportedRequiredFn(formData, 0)).to.equal(true);
expect(nonSupportedRequiredFn(formData, 0)).to.equal(true);

// Scenario 2: supportedStudents is less than 10
formData = {
programs: [{ supportedStudents: 9 }],
};
expect(supportedRequiredFn(formData, 0)).to.equal(false);
expect(nonSupportedRequiredFn(formData, 0)).to.equal(false);
});
});

describe('schema', () => {
it('should be an object schema with required fields', () => {
const { schema } = programInfo;
expect(schema).to.have.property('type', 'object');
expect(schema).to.have.property('properties');
expect(schema.properties).to.have.property('programName');
expect(schema.properties).to.have.property('studentsEnrolled');
expect(schema.properties).to.have.property('supportedStudents');
expect(schema.properties).to.have.property('fte');
expect(schema.properties).to.have.property('view:calcs');

// required fields
expect(schema)
.to.have.property('required')
.that.is.an('array');
expect(schema.required).to.include.members([
'programName',
'studentsEnrolled',
'supportedStudents',
]);
});
});
});
Loading

0 comments on commit d56bb41

Please sign in to comment.