All files / components/Schools SchoolsDropdown.js

100% Statements 11/11
100% Branches 7/7
100% Functions 3/3
100% Lines 11/11

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 36 37 38 39 40 41 42 43 44 45 46 47 48          48x   48x   48x   48x 23x     48x   48x 47x 114x                 48x         7x                            
import { useState } from "react";
import { Form } from "react-bootstrap";
 
function SchoolsDropdown({ schools , initialContents}){
    // Stryker disable next-line all : don't test useState
    const [isActive, setIsActive] = useState();
 
    const testId = "FormSelect";
 
    let initialSchool = null;
 
    if(initialContents){
        initialSchool = initialContents.school;
    }
 
    let schoolOptions = null;
 
    if(schools){
        schoolOptions = schools.map((school) => 
            <option 
                key = {school.abbrev}
                data-testid={`${testId}-option-${school.abbrev}`}
            > 
                {school.abbrev} 
            </option>);
    }
 
 
    return(
        <Form.Select 
            id = "FormSelect"
            data-testid = "FormSelect"
            value = { isActive || initialSchool || "No school selected" } 
            onChange = { option => setIsActive(option.target.value)} 
            >
            <option 
                key = "No school selected"
                disabled = {true}
                data-testid={`${testId}-option-No school selected`}
            >
                No school selected
            </option>
            { schoolOptions }
        </Form.Select>
    )
}
 
export default SchoolsDropdown;