All files / components/BasicCourseSearch BasicCourseSearchForm.js

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

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                    3x 35x           35x               35x       35x         35x   35x 4x 4x       35x                                                                                    
import { Form, Button, Container, Row, Col } from "react-bootstrap";
 
import { allTheLevels } from "fixtures/levelsFixtures";
import { standardQuarterRange } from "main/utils/quarterUtilities";
import SingleQuarterDropdown from "../Quarters/SingleQuarterDropdown";
import SingleSubjectDropdown from "../Subjects/SingleSubjectDropdown";
import SingleLevelDropdown from "../Levels/SingleLevelDropdown";
import { useBackend } from "main/utils/useBackend";
import useLocalStorage from "main/utils/useLocalStorage";
 
const BasicCourseSearchForm = ({ fetchJSON }) => {
  const quarters = standardQuarterRange();
 
  const {
    data: subjects,
    error: _error,
    status: _status,
  } = useBackend(
    // Stryker disable all : don't test internal caching of React Query
    ["/api/UCSBSubjects/all"],
    { method: "GET", url: "/api/UCSBSubjects/all" },
    [],
    // Stryker restore all
  );
 
  const [quarter, setQuarter] = useLocalStorage(
    "BasicSearch.Quarter",
    quarters[0].yyyyq,
  );
  const [subject, setSubject] = useLocalStorage(
    "BasicSearch.Subject",
    subjects.length > 0 ? subjects[0].subjectCode : "ANTH",
  );
 
  const [level, setLevel] = useLocalStorage("BasicSearch.Level", "U");
 
  const handleSubmit = (event) => {
    event.preventDefault();
    fetchJSON(event, { quarter, subject, level });
  };
 
  // Stryker disable all : Stryker is testing by changing the padding to 0. But this is simply a visual optimization as it makes it look better
  return (
    <Form onSubmit={handleSubmit}>
      <Container>
        <Row>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={quarter}
              setQuarter={setQuarter}
              controlId={"BasicSearch.Quarter"}
            />
          </Col>
          <Col md="auto">
            <SingleSubjectDropdown
              subjects={subjects}
              subject={subject}
              setSubject={setSubject}
              controlId={"BasicSearch.Subject"}
            />
          </Col>
          <Col md="auto">
            <SingleLevelDropdown
              levels={allTheLevels}
              level={level}
              setLevel={setLevel}
              controlId={"BasicSearch.Level"}
            />
          </Col>
        </Row>
        <Row style={{ paddingTop: 10, paddingBottom: 10 }}>
          <Col md="auto">
            <Button variant="primary" type="submit">
              Submit
            </Button>
          </Col>
        </Row>
      </Container>
    </Form>
  );
};
 
export default BasicCourseSearchForm;