All files / components/BasicCourseSearch CourseInstructorSearchForm.js

100% Statements 16/16
100% Branches 10/10
100% Functions 2/2
100% Lines 16/16

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              2x   46x     46x 46x     46x     46x 46x 46x     46x             46x 46x 46x   46x 3x 3x       46x                                                                                
import { useState } from "react";
import { Form, Button, Container, Row, Col } from "react-bootstrap";
import { quarterRange } from "main/utils/quarterUtilities";
import { useSystemInfo } from "main/utils/systemInfo";
import SingleQuarterDropdown from "../Quarters/SingleQuarterDropdown";
import { useBackend  } from "main/utils/useBackend";
 
const CourseInstructorSearchForm = ({ fetchJSON }) => {
 
  const { data: systemInfo } = useSystemInfo();
 
  // Stryker disable OptionalChaining
  const startQtr = systemInfo?.startQtrYYYYQ || "20211";
  const endQtr = systemInfo?.endQtrYYYYQ || "20214";
  // Stryker restore OptionalChaining
 
  const quarters = quarterRange(startQtr, endQtr);
 
  // Stryker disable all : not sure how to test/mock local storage
  const localStartQuarter = localStorage.getItem("CourseInstructorSearch.StartQuarter");
  const localEndQuarter = localStorage.getItem("CourseInstructorSearch.EndQuarter");
  const localInstructor = localStorage.getItem("CourseInstructorSearch.instructor");
  //Styker restore all
  const {error: _error, status: _status } =
  useBackend(
  // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/UCSBSubjects/all"], 
    { method: "GET", url: "/api/UCSBSubjects/all" }, 
    []
  );
 
  const [startQuarter, setStartQuarter] = useState(localStartQuarter || quarters[0].yyyyq);
  const [endQuarter, setEndQuarter] = useState(localEndQuarter || quarters[0].yyyyq);
  const [instructor, setInstructor] = useState(localInstructor || "");
    
  const handleSubmit = (event) => {
    event.preventDefault();
    fetchJSON(event, { startQuarter, endQuarter, instructor });
  };
 
 
  return (
    <Form onSubmit={handleSubmit}>
      <Container>
        <Row>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={startQuarter}
              setQuarter={setStartQuarter}
              controlId={"CourseInstructorSearch.StartQuarter"}
              label={"Start Quarter"}
            />
          </Col>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={endQuarter}
              setQuarter={setEndQuarter}
              controlId={"CourseInstructorSearch.EndQuarter"}
              label={"End Quarter"}
            />
          </Col>
        </Row>
        <Form.Group controlId="CourseInstructorSearch.name">
            <Form.Label>Instructor Name (Try searching 'Conrad' or 'Mirza')</Form.Label>
            <Form.Control onChange={setInstructor} defaultValue={instructor} />
        </Form.Group>
        <Row style={{ paddingTop: 10, paddingBottom: 10 }}
          data-testid="submit-button">
          <Col md="auto">
            <Button variant="primary" type="submit">
              Submit
            </Button>
          </Col>
        </Row>
      </Container>
    </Form>
  );
};
 
export default CourseInstructorSearchForm;