From d56bb41c6c75ff4c11c9139f402e737d23b49dd6 Mon Sep 17 00:00:00 2001 From: wafimohamed <158514667+wafimohamed@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:30:52 -0500 Subject: [PATCH] Vebt 847 unit tests (#33759) * added unit test for form 22-10215 * vebt-847 added more unit test for 22-10215 --- .../edu-benefits/10215/config/form.js | 2 +- .../edu-benefits/10215/config/transform.js | 9 ++- .../edu-benefits/10215/pages/index.js | 10 ++- .../10215/pages/program-summary.js | 2 +- .../10215/tests/config/form.unit.spec.js | 42 ++++++++++ .../10215/tests/config/transform.unit.spec.js | 58 +++++++++++++ .../10215/tests/form.unit.spec.jsx | 2 - .../10215/tests/helper.unit.spec.js | 60 ++++++++++++++ .../10215/tests/pages/calcs.unit.spec.js | 81 +++++++++++++++++++ .../tests/pages/program-info.unit.spec.js | 71 ++++++++++++++++ .../tests/pages/program-summary.unit.spec.js | 32 ++++++++ 11 files changed, 359 insertions(+), 10 deletions(-) create mode 100644 src/applications/edu-benefits/10215/tests/config/form.unit.spec.js create mode 100644 src/applications/edu-benefits/10215/tests/config/transform.unit.spec.js create mode 100644 src/applications/edu-benefits/10215/tests/helper.unit.spec.js create mode 100644 src/applications/edu-benefits/10215/tests/pages/calcs.unit.spec.js create mode 100644 src/applications/edu-benefits/10215/tests/pages/program-info.unit.spec.js create mode 100644 src/applications/edu-benefits/10215/tests/pages/program-summary.unit.spec.js diff --git a/src/applications/edu-benefits/10215/config/form.js b/src/applications/edu-benefits/10215/config/form.js index dd8209d2558a..beb310342e23 100644 --- a/src/applications/edu-benefits/10215/config/form.js +++ b/src/applications/edu-benefits/10215/config/form.js @@ -16,7 +16,7 @@ import { ProgramSummary, } from '../pages'; -const arrayBuilderOptions = { +export const arrayBuilderOptions = { arrayPath: 'programs', nounSingular: 'program', nounPlural: 'programs', diff --git a/src/applications/edu-benefits/10215/config/transform.js b/src/applications/edu-benefits/10215/config/transform.js index 3134d0c64786..f09453e03384 100644 --- a/src/applications/edu-benefits/10215/config/transform.js +++ b/src/applications/edu-benefits/10215/config/transform.js @@ -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; }); diff --git a/src/applications/edu-benefits/10215/pages/index.js b/src/applications/edu-benefits/10215/pages/index.js index 860e5e3f6018..19e894694a93 100644 --- a/src/applications/edu-benefits/10215/pages/index.js +++ b/src/applications/edu-benefits/10215/pages/index.js @@ -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, +}; diff --git a/src/applications/edu-benefits/10215/pages/program-summary.js b/src/applications/edu-benefits/10215/pages/program-summary.js index 29162c3f5145..676218068f88 100644 --- a/src/applications/edu-benefits/10215/pages/program-summary.js +++ b/src/applications/edu-benefits/10215/pages/program-summary.js @@ -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', diff --git a/src/applications/edu-benefits/10215/tests/config/form.unit.spec.js b/src/applications/edu-benefits/10215/tests/config/form.unit.spec.js new file mode 100644 index 000000000000..629cd656397e --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/config/form.unit.spec.js @@ -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; + }); +}); diff --git a/src/applications/edu-benefits/10215/tests/config/transform.unit.spec.js b/src/applications/edu-benefits/10215/tests/config/transform.unit.spec.js new file mode 100644 index 000000000000..39f248dd6628 --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/config/transform.unit.spec.js @@ -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; + }); +}); diff --git a/src/applications/edu-benefits/10215/tests/form.unit.spec.jsx b/src/applications/edu-benefits/10215/tests/form.unit.spec.jsx index f27ad5882daa..7c35fa338d9a 100644 --- a/src/applications/edu-benefits/10215/tests/form.unit.spec.jsx +++ b/src/applications/edu-benefits/10215/tests/form.unit.spec.jsx @@ -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 }); diff --git a/src/applications/edu-benefits/10215/tests/helper.unit.spec.js b/src/applications/edu-benefits/10215/tests/helper.unit.spec.js new file mode 100644 index 000000000000..ff37873554eb --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/helper.unit.spec.js @@ -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, + }); + }); +}); diff --git a/src/applications/edu-benefits/10215/tests/pages/calcs.unit.spec.js b/src/applications/edu-benefits/10215/tests/pages/calcs.unit.spec.js new file mode 100644 index 000000000000..f837cf73031a --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/pages/calcs.unit.spec.js @@ -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('', () => { + 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( + + + , + ); + + 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( + + + , + ); + + expect( + wrapper + .find('span') + .at(0) + .text(), + ).to.equal('--'); + expect( + wrapper + .find('span') + .at(1) + .text(), + ).to.equal('--%'); + wrapper.unmount(); + }); +}); diff --git a/src/applications/edu-benefits/10215/tests/pages/program-info.unit.spec.js b/src/applications/edu-benefits/10215/tests/pages/program-info.unit.spec.js new file mode 100644 index 000000000000..53c4d4336eec --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/pages/program-info.unit.spec.js @@ -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', + ]); + }); + }); +}); diff --git a/src/applications/edu-benefits/10215/tests/pages/program-summary.unit.spec.js b/src/applications/edu-benefits/10215/tests/pages/program-summary.unit.spec.js new file mode 100644 index 000000000000..909c4ac429c8 --- /dev/null +++ b/src/applications/edu-benefits/10215/tests/pages/program-summary.unit.spec.js @@ -0,0 +1,32 @@ +import React from 'react'; +import { expect } from 'chai'; +import { shallow } from 'enzyme'; +import { ProgramSummary, arrayBuilderOptions } from '../../pages'; + +const MockProgramSummary = () =>
; + +describe('ProgramSummary', () => { + it('should have the correct uiSchema', () => { + const wrapper = shallow(); + expect(ProgramSummary.uiSchema).to.have.property('view:programsSummary'); + const uiSchemaView = ProgramSummary.uiSchema['view:programsSummary']; + expect(uiSchemaView).to.have.property( + 'ui:title', + 'Do you have another program to add?', + ); + wrapper.unmount(); + }); + it('should have the correct schema', () => { + expect(ProgramSummary.schema).to.have.property('type', 'object'); + expect(ProgramSummary.schema).to.have.property('properties'); + expect(ProgramSummary.schema.properties).to.have.property( + 'view:programsSummary', + ); + }); + it('should return the correct item name from getItemName', () => { + const testItem = { programName: 'My Awesome Program' }; + const name = arrayBuilderOptions.text.getItemName(testItem); + + expect(name).to.equal('My Awesome Program'); + }); +});