department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
284 stars 206 forks source link

Move unit tests adjacent to the source of the system under testing #95023

Closed JunTaoLuo closed 4 weeks ago

JunTaoLuo commented 1 month ago

As part of the effort to improve our unit tests, we've decided to move unit tests to the same directory as the source file of the system under testing.

For example:

src\applications\vaos\
- components\subdirectoryA
  \- SubcomponentA.jsx
   - SubcomponentA.unit.spec.js
 - Component1.jsx
 - Component1.unit.spec
- test\
 \- testUtility.js 

Primarily, this provides the benefit of making it easier to find the associated test file for each component and to identify which source files is missing associated tests.

Note that naming of the unit tests should:

We'll likely do this in smaller steps, note that some of these tests will have been removed as part of the remove obsolete components work.

./src/applications/vaos/tests/new-appointment/components/ClinicChoicePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ClosestCityStatePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/CommunityCareLanguagePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/CommunityCareProviderSelectionPage/ProviderSortVariant.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/CommunityCareProviderSelectionPage/index.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ConfirmationPage/ConfirmationDirectScheduleInfoV2.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ContactInfoPage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/DateTimeRequestPage/index.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/DateTimeSelectPage/index.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/PreferredDatePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReasonForAppointmentPage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReviewPage/ContactDetailSection.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReviewPage/index.cc-request.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReviewPage/index.direct.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReviewPage/index.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ReviewPage/index.va-request.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/ScheduleCernerPage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/TypeOfAudiologyCare.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/TypeOfEyeCarePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/TypeOfFacilityPage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/TypeOfSleepCarePage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/TypeOfVisitPage.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/VAFacilityPage/index.eligibility.unit.spec.js ./src/applications/vaos/tests/new-appointment/components/VAFacilityPage/index.unit.spec.js ./src/applications/vaos/tests/new-appointment/newAppointmentFlow.unit.spec.js ./src/applications/vaos/tests/new-appointment/redux/actions.unit.spec.js ./src/applications/vaos/tests/new-appointment/redux/helpers/formSubmitTransformers.unit.spec.js ./src/applications/vaos/tests/new-appointment/redux/helpers/formSubmitTransformers.v2.unit.spec.js ./src/applications/vaos/appointment-list/components/PastAppointmentsList/tests/PastAppointmentsDateDropdown.unit.spec.js ./src/applications/vaos/services/appointment/tests/transformers.unit.spec.js


- [x] 3. 

./src/applications/vaos/tests/covid-19-vaccine/components/ClinicChoicePage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ConfirmationPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ConfirmationPageV2.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ContactFacilitiesPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ContactInfoPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/NewBookingPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/PlanAheadPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ReceivedDoseScreenerPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/ReviewPage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/SecondDosePage.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/SelectDate1Page.unit.spec.js ./src/applications/vaos/tests/covid-19-vaccine/components/VAFacilityPage/index.unit.spec.js ./src/applications/vaos/tests/referral-appointments/ChooseDateAndTime.unit.spec.js ./src/applications/vaos/tests/referral-appointments/components/ReferralReview.unit.spec.js ./src/applications/vaos/tests/services/appointment/index.unit.spec.js ./src/applications/vaos/tests/services/healthcare-service/index.unit.spec.js ./src/applications/vaos/tests/services/location/index.unit.spec.js ./src/applications/vaos/tests/services/mocks/index.unit.spec.js ./src/applications/vaos/tests/services/slot/index.unit.spec.js ./src/applications/vaos/tests/services/utils.unit.spec.js ./src/applications/vaos/tests/services/vaos/index.unit.spec.js ./src/applications/vaos/tests/utils/appointment.unit.spec.js ./src/applications/vaos/tests/utils/error.unit.spec.js ./src/applications/vaos/tests/utils/formatters.unit.spec.js ./src/applications/vaos/tests/utils/timezone.unit.spec.js


- [x] 4. 

./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/AtlasLocation.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/CCInstructions.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/CancelLink.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/DetailsVA.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/DetailsVA.util.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/NoOnlineCancelAlert.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/PrintButton.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/PrintLink.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/ProviderName.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/StatusAlert.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/TypeHeader.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/VAInstructions.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/VideoInstructionsLink.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/VideoLink.unit.spec.js ./src/applications/vaos/appointment-list/components/ConfirmedAppointmentDetailsPage/tests/VideoVisitInstructions.unit.spec.js ./src/applications/vaos/appointment-list/components/PastAppointmentsList/tests/PastAppointmentsDateDropdown.unit.spec.js ./src/applications/vaos/appointment-list/components/tests/AppointmentColumn.unit.spec.js ./src/applications/vaos/appointment-list/components/tests/AppointmentRow.unit.spec.js ./src/applications/vaos/appointment-list/components/tests/NoAppointments.unit.spec.js ./src/applications/vaos/appointment-list/hooks/tests/use-handle-click.unit.spec.js ./src/applications/vaos/appointment-list/hooks/tests/use-handle-key-down.unit.spec.js ./src/applications/vaos/appointment-list/redux/tests/selectors.unit.spec.js ./src/applications/vaos/appointment-list/tests/index.unit.spec.js


- [x] 5. 

./src/applications/vaos/components/tests/AfterVisitSummary.unit.spec.js ./src/applications/vaos/components/tests/AppointmentCard.unit.spec.js ./src/applications/vaos/components/tests/AppointmentCardIcon.unit.spec.js ./src/applications/vaos/components/tests/CCLayout.unit.spec.js ./src/applications/vaos/components/tests/CCRequestLayout.unit.spec.js ./src/applications/vaos/components/tests/ClaimExamLayout.unit.spec.js ./src/applications/vaos/components/tests/InPersonLayout.unit.spec.js ./src/applications/vaos/components/tests/PhoneLayout.unit.spec.js ./src/applications/vaos/components/tests/VARequestLayout.unit.spec.js ./src/applications/vaos/components/tests/VideoInstructions.unit.spec.js ./src/applications/vaos/components/tests/VideoLayout.unit.spec.js ./src/applications/vaos/components/tests/VideoLayoutAtlas.unit.spec.js ./src/applications/vaos/components/tests/VideoLayoutVA.unit.spec.js ./src/applications/vaos/components/tests/VideoLink.unit.spec.js ./src/applications/vaos/services/appointment/tests/transformers.unit.spec.js


- [ ] 6. Decided that this will be moved as part of https://github.com/department-of-veterans-affairs/va.gov-team/issues/95332. 

./src/applications/vaos/tests/new-appointment/components/TypeOfCarePage.unit.spec.js



## Definition of Done
- [x] All unit existing tests are moved to match the specifications in the description above
- [x] All unit tests are recognized by the test runner and pass (locally and on CI)
- [x] Coverage metrics remain constant before and after the change
JunTaoLuo commented 1 month ago

One open question is where should the test utilities (e.g. mocks, helpers) be located? If it is placed in the same directory as the source and unit test files, it becomes a little more difficult to differentiate between source files and test utilities. We need to test this out to ensure the coverage tool recognizes test utilities correctly.

Update: we decided to keep test utilities in the top level test directory.

cc @simiadebowale @vbahinwillit

Bren22va commented 1 month ago

Hey team! Please add your planning poker estimate with Zenhub @cferris32 @jenniemc @JunTaoLuo @ryanshaw @simiadebowale @vbahinwillit

JunTaoLuo commented 4 weeks ago

All tests are passing locally and on the CI. The coverage remained the same as well:

Image

The only remaining item is to move one last test which will be completed in https://github.com/department-of-veterans-affairs/va.gov-team/issues/95332.

Since this is a test only change, there's no further validation needed.