All files / components/Courses SchoolDropdown.js

100% Statements 5/5
100% Branches 3/3
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35        4x         39x   39x                 96x 96x                          
import React from "react";
import { Form } from "react-bootstrap";
import {useFormContext} from "react-hook-form";
 
const SchoolDropdown = ({schools = [], testId}) => {
    const {
        register,
        formState: {errors},
        formState
    } = useFormContext();
 
    return (<Form.Group>
        <Form.Label htmlFor="school">School</Form.Label>
        <Form.Control data-testid={`${testId}-school`} id="school"  as="select"
          isInvalid={Boolean(errors.school)}
          {...register("schoolAbbrev", {required: true, minLength: 2})}
            value={formState.defaultValues.schoolAbbrev}
        >
            <option value=""></option>
            {schools.map(function (object, i) {
                const key = `${testId}-option-${i}`
                return(
                    <option key={key} data-testid={key} value={object.abbrev}>
                        {object.name}
                    </option>
                );
            })}
        </Form.Control>
        <Form.Control.Feedback type="invalid">
            {errors.schoolAbbrev && 'School is required. '}
        </Form.Control.Feedback>
    </Form.Group>);
}
 
export default SchoolDropdown;