-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Feature
Create and test a HarvestUnitSelector component and associated component tests. The HarvestUnitSelector provides a select element allowing the user to select one of the harvest units for a specific crop and should look similar to the mock up shown here:
Add component tests for the HarvestUnitSelector.
Once the HarvestUnitSelector component has been created, use it in the Harvest form as the input for the harvest units.
Rationale
In FarmData2 all of the UI components used in the forms are custom Vue components. By creating these as custom Vue components we can encapsulate all of the logic for fetching, displaying, and validating the data in the component and returned by the component. This ensures that the UI component looks and behaves the same in all locations where it appears and eliminates duplicate code. In addition, the component can be tested in isolation, making it easier to test and eliminating duplicate test code that would be necessary if a primitive component were used directly.
Additional context
To add the HarvestUnitComponent:
- Review the information about creating and testing custom Vue Components in the FarmData2 documentation.
i. Start the documentation server.
ii. Find the "Contributing" section in the Index of the FarmData2 Documentation
iii. Read the "Components Guide" - Use the
addComponent.bashscript to create the starter code for theHavestUnitComponentand its tests.
i. Study the comments in the newly createdHarvestUnitComponent.vuefile and the*.comp.cy.jsfiles.
ii. Visit the component's example page in "FD2 Examples" in farmOS. - Study the
CropSelectorcomponent.
i. TheHarvestUnitComponentwill be similar to theCropSelectorin many ways. But these two components will also be different in some ways. So understanding theCropSelectorcomponent will help with implementing theHarvestUnitComponent, but you'll have to adapt things as appropriate.
ii. Experiment with theCropSelectorcomponent on its example page in "FD2 Examples" in farmOS.
- Be sure to try out the "+" button to add a crop as theHarvestUnitComponentwill have do something similar. - Implement the
HarvestUnitComponent. This component must:
i. Use aSelectorBasecomponent as the UI elementCropSelectordoes.
i. Provide props forcropName,selected, andshowValidityStyling
ii. Emiterror,ready,update:selectedandvalidevents.
iii. Use thegetCropNameToTermMapfunction in thefarmosUtillibrary to get aMapthat you can use to get thetaxonomy_term--plant_typeobject for the crop name provided by thecropNameprop.
iv. Use a URL similar to:http://farmos/taxonomy/term/53/editfor thepopupUrl
- The53in the URL must be replaced by theattributes.drupal_internal_tidfrom thetaxonomy_term--plant_typeobject.
v. If the crop indicated bycropNamehas only one harvest unit then that harvest unit should be selected by default in theSelectorBase, otherwise no harvest unit should be selected by default. - Update the
HarvestUnitComponentexample page in "FD2 Examples" to allow you to test the new component manually. All props and events should be included in the example page.- Use the
npm run build:examplescommand to rebuild the examples pages when you make changes.
- Use the
- Add documentation to the
HarvestUnitComponent.vuefile that documents its use. The documentation for theCropSelectorwould be a good example to emulate. - Implement the component tests for the new
HarvestUnitComponent. i. Studying the tests for theCropSelectorshould provide a good idea of how to write the tests for theHarvestUnitComponent.- Component tests can be run with
test.bash --comp --glob=components/HarvestUnitComponent/*.comp.cy.js --gui
- Component tests can be run with