Skip to content

Commit

Permalink
5490 test coverage (#32763)
Browse files Browse the repository at this point in the history
* fix form submit transform issue

* tests to bump coverage

* ermove ssn field from submit field

* wip: adding tests

* Adds unit test for confirmation page container

* name validation tests

* name validation tests

* add action specs'

* adds prop types to intro page and unit tests for conditional rendering save in progress

* remove code that wouldn't get hit and add more tests

* more specs

* Adds specs for obfuscate Review field component

* more validation specs

* adds specs to submit-transfrom for unchecked functions

* Adds tests for presubmit info component

---------

Co-authored-by: Brad Bergeron <[email protected]>
Co-authored-by: Brad Bergeron <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent e9de3a6 commit 8728258
Show file tree
Hide file tree
Showing 25 changed files with 4,134 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,3 @@ export function fetchClaimStatus(selectedChapter) {
});
};
}

// export function fetchDirectDeposit() {
// const ddEndpoint = LIGHTHOUSE_DIRECT_DEPOSIT_ENDPOINT;

// return async dispatch => {
// dispatch({ type: FETCH_DIRECT_DEPOSIT });

// return apiRequest(ddEndpoint)
// .then(response => {
// dispatch({
// type: FETCH_DIRECT_DEPOSIT_SUCCESS,
// response,
// });
// })
// .catch(errors => {
// dispatch({
// type: FETCH_DIRECT_DEPOSIT_FAILED,
// errors,
// });
// });
// };
// }
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const mapStateToProps = state => {
duplicateEmail: state?.data?.duplicateEmail,
mobilePhone:
state?.form?.data['view:phoneNumbers']?.mobilePhoneNumber?.phone,
showMebEnhancements08: state?.featureToggles?.showMebEnhancements08,
formData: state?.form?.data,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ const formConfig = {
errors.addError('Please enter your first name');
} else if (field.length > 20) {
errors.addError('Must be 20 characters or less');
} else if (field[0] === ' ' || field[0] === "'") {
errors.addError(
'First character must be a letter with no leading space.',
);
}
} else if (!isValidName(field)) {
errors.addError(
Expand All @@ -214,11 +210,7 @@ const formConfig = {
'ui:validations': [
(errors, field) => {
if (isValidName(field)) {
if (field[0] === ' ' || field[0] === "'") {
errors.addError(
'First character must be a letter with no leading space.',
);
} else if (field.length > 20) {
if (field.length > 20) {
errors.addError('Must be 20 characters or less');
}
} else if (!isValidName(field)) {
Expand All @@ -240,14 +232,6 @@ const formConfig = {
errors.addError('Must be 2 characters or more');
} else if (field.length > 26) {
errors.addError('Must be 26 characters or less');
} else if (
field[0] === ' ' ||
field[0] === "'" ||
field[0] === '-'
) {
errors.addError(
'First character must be a letter with no leading space.',
);
}
} else if (!isValidName(field)) {
errors.addError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { getIntroState } from 'platform/forms/save-in-progress/selectors';
Expand Down Expand Up @@ -169,12 +170,26 @@ export const IntroductionPage = ({
);
};

IntroductionPage.propTypes = {
route: PropTypes.shape({
formConfig: PropTypes.shape({
prefillEnabled: PropTypes.bool,
savedFormMessages: PropTypes.arrayOf(PropTypes.string),
}),
pageList: PropTypes.arrayOf(PropTypes.object),
}).isRequired,
isLOA3: PropTypes.bool,
isLoggedIn: PropTypes.bool,
isPersonalInfoFetchFailed: PropTypes.bool,
showMeb5490EMaintenanceAlert: PropTypes.bool,
};

const mapStateToProps = state => ({
...getIntroState(state),
...getAppData(state),
isPersonalInfoFetchFailed: state.data.isPersonalInfoFetchFailed || false,
isPersonalInfoFetchFailed: state.data?.isPersonalInfoFetchFailed || false,
showMeb5490EMaintenanceAlert:
state.featureToggles.showMeb5490EMaintenanceAlert,
state.featureToggles?.showMeb5490EMaintenanceAlert,
});

export default connect(mapStateToProps)(IntroductionPage);
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import { render } from '@testing-library/react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { expect } from 'chai';

import { $ } from '@department-of-veterans-affairs/platform-forms-system/ui';
import CustomPhoneNumberField from '../../../components/CustomPhoneNumberField';
import CustomPhoneNumberField from '../../components/CustomPhoneNumberField';

const initialData = {
const initialState = {
user: {
profile: {
userFullName: {
Expand Down Expand Up @@ -42,18 +39,24 @@ const initialData = {
},
},
},
schema: {
type: 'number',
},
options: {
inputType: 'number',
},
};

describe('CustomPhoneNumberField', () => {
const middleware = [thunk];
const mockStore = configureStore(middleware);
const mockStore = configureStore();
const store = mockStore(initialState);

xit('should render with data', () => {
const { container } = render(
<Provider store={mockStore(initialData)}>
const wrapper = mount(
<Provider store={store}>
<CustomPhoneNumberField />
</Provider>,
);
expect($('.personal-info-header', container)).to.exist;
expect(wrapper.text()).to.include('John M Doe');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import DirectDepositViewField from '../../components/DirectDepositViewField';

describe('DirectDepositViewField component', () => {
const initialState = {
bankAccount: {
accountType: 'checking',
accountNumber: '123123123',
routingNumber: '321321321',
},
};

it('renders the DirectDepositViewField footer', () => {
expect(<DirectDepositViewField />);
});

it('should render obfuscated checking account information', () => {
const wrapper = mount(<DirectDepositViewField formData={initialState} />);
expect(wrapper.text()).to.include('Checking account');
expect(wrapper.text()).to.include('●●●●●1321');
expect(wrapper.text()).to.include('●●●●●3123');
wrapper.unmount();
});

it('should render account information when no account type is provided', () => {
initialState.bankAccount.accountType = '';

const wrapper = mount(<DirectDepositViewField formData={initialState} />);
expect(wrapper.text()).to.include('Account');
expect(wrapper.text()).to.include('●●●●●1321');
expect(wrapper.text()).to.include('●●●●●3123');
wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';

import DuplicateContactInfoModal from '../../components/DuplicateContactInfoModal';

const initialState = {
form: {
data: {
email: {
email: '[email protected]',
},
},
},
data: {
duplicateEmail: [{ dupe: true, acknowledged: undefined }],
duplicatePhone: [],
openModal: true,
},
};

describe('DuplicateContactInfoModal', () => {
const mockStore = configureStore();

const store = mockStore(initialState);

it('should render with data', () => {
const wrapper = mount(
<Provider store={store}>
<DuplicateContactInfoModal />
</Provider>,
);

expect(wrapper.text()).to.include('This will impact how we:');

wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import EmailReviewField from '../../components/EmailReviewField';

describe('EmailReviewField component', () => {
it('renders the EmailReviewField footer', () => {
const wrapper = mount(
<EmailReviewField>
<div formData="[email protected]" />
</EmailReviewField>,
);
expect(wrapper.text()).to.include('test');

wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import FormFooter from '../../components/FormFooter';

describe('FormFooter component', () => {
it('renders the FormFooter footer', () => {
const wrapper = mount(<FormFooter />);

expect(wrapper.text()).to.include(
'If you need help with your application or have questions about',
);
wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import MailingAddressViewField from '../../components/MailingAddressViewField';

describe('MailingAddressViewField component', () => {
const initialState = {
address: {
street: '123 true st',
street2: '#1',
city: 'Fairfax',
state: 'VA',
postalCode: '22042',
},
};

it('should render the mailing address', () => {
const wrapper = mount(<MailingAddressViewField formData={initialState} />);
expect(wrapper.text()).to.include('123 true st');
expect(wrapper.text()).to.include('#1');
expect(wrapper.text()).to.include('Fairfax');
expect(wrapper.text()).to.include('VA');
expect(wrapper.text()).to.include('22042');
wrapper.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import ObfuscateReviewField from '../../components/ObfuscateReviewField';

describe('ObfuscateReviewField component', () => {
it('renders without crashing', () => {
const uiSchema = { 'ui:title': 'Obfuscated Title' };
const formData = 'Sensitive Information';

const wrapper = mount(
<ObfuscateReviewField uiSchema={uiSchema}>
<span formData={formData} />
</ObfuscateReviewField>,
);

expect(wrapper.exists()).to.be.true;
wrapper.unmount();
});

it('displays the title from uiSchema', () => {
const uiSchema = { 'ui:title': 'Obfuscated Title' };
const formData = 'Sensitive Information';

const wrapper = mount(
<ObfuscateReviewField uiSchema={uiSchema}>
<span formData={formData} />
</ObfuscateReviewField>,
);

expect(wrapper.find('dt').text()).to.equal('Obfuscated Title');
wrapper.unmount();
});

it('obfuscates the formData content', () => {
const uiSchema = { 'ui:title': 'Obfuscated Title' };
const formData = 'Sensitive Information';

const wrapper = mount(
<ObfuscateReviewField uiSchema={uiSchema}>
<span formData={formData} />
</ObfuscateReviewField>,
);

const obfuscatedText = wrapper.find('dd').text();

// Adjusted expectation to check for `●` characters
expect(obfuscatedText).to.not.equal(formData);
expect(obfuscatedText).to.match(/●+/); // Checks if the obfuscation contains `●` characters
wrapper.unmount();
});
});
Loading

0 comments on commit 8728258

Please sign in to comment.