All files / components/BasicCourseSearch CourseOverTimeInstructorSearchForm.js

100% Statements 20/20
100% Branches 8/8
100% Functions 4/4
100% Lines 20/20

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102          2x 58x     58x     58x     58x       58x   58x     58x     58x 58x     58x 4x 4x     58x 30x     58x 5x 5x           58x   58x                                                                                                      
import { useState } from "react";
import { Form, Button, Container, Row, Col, FormCheck } from "react-bootstrap";
import { standardQuarterRange } from "main/utils/quarterUtilities";
import SingleQuarterDropdown from "../Quarters/SingleQuarterDropdown";
 
const CourseOverTimeInstructorSearchForm = ({ fetchJSON }) => {
  const quarters = standardQuarterRange();
 
  // Stryker disable all : not sure how to test/mock local storage
  const localStartQuarter = localStorage.getItem(
    "CourseOverTimeInstructorSearch.StartQuarter",
  );
  const localEndQuarter = localStorage.getItem(
    "CourseOverTimeInstructorSearch.EndQuarter",
  );
  const localInstructor = localStorage.getItem(
    "CourseOverTimeInstructorSearch.Instructor",
  );
  const localStorageCheckbox =
    localStorage.getItem("CourseOverTimeInstructorSearch.Checkbox") === "true";
 
  const [startQuarter, setStartQuarter] = useState(
    localStartQuarter || quarters[0].yyyyq,
  );
  const [endQuarter, setEndQuarter] = useState(
    localEndQuarter || quarters[0].yyyyq,
  );
  const [instructor, setInstructor] = useState(localInstructor || "");
  const [checkbox, setCheckbox] = useState(localStorageCheckbox || false);
  // Stryker restore all
 
  const handleSubmit = (event) => {
    event.preventDefault();
    fetchJSON(event, { startQuarter, endQuarter, instructor, checkbox });
  };
 
  const handleInstructorOnChange = (event) => {
    setInstructor(event.target.value);
  };
 
  const handleCheckboxOnChange = (event) => {
    setCheckbox(event.target.checked);
    localStorage.setItem(
      "CourseOverTimeInstructorSearch.Checkbox",
      event.target.checked.toString(),
    );
  };
 
  const testid = "CourseOverTimeInstructorSearchForm";
 
  return (
    <Form onSubmit={handleSubmit}>
      <Container>
        <Row>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={startQuarter}
              setQuarter={setStartQuarter}
              controlId={"CourseOverTimeInstructorSearch.StartQuarter"}
              label={"Start Quarter"}
            />
          </Col>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={endQuarter}
              setQuarter={setEndQuarter}
              controlId={"CourseOverTimeInstructorSearch.EndQuarter"}
              label={"End Quarter"}
            />
          </Col>
        </Row>
        <Form.Group controlId="CourseOverTimeInstructorSearch.Instructor">
          <Form.Label>Instructor Name</Form.Label>
          <Form.Control
            onChange={handleInstructorOnChange}
            defaultValue={instructor}
          />
        </Form.Group>
        <Form.Group controlId="CourseOverTimeInstructorSearch.Checkbox">
          <FormCheck
            data-testid={`${testid}-checkbox`}
            label="Lectures Only"
            onChange={handleCheckboxOnChange}
            checked={checkbox}
          ></FormCheck>
        </Form.Group>
        <Row style={{ paddingTop: 10, paddingBottom: 10 }}>
          <Col md="auto">
            <Button variant="primary" type="submit">
              Submit
            </Button>
          </Col>
        </Row>
      </Container>
    </Form>
  );
};
 
export default CourseOverTimeInstructorSearchForm;