All files / components/GeneralEducation GeneralEducationSearchForm.js

100% Statements 14/14
66.66% Branches 6/9
100% Functions 2/2
100% Lines 14/14

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                    2x   33x 33x   33x 33x 33x 33x           33x           33x 33x       33x 4x 4x     33x                                                                    
import { useState } from "react";
import { Form, Button, Container, Row, Col } from "react-bootstrap";
 
import SingleAreaDropdown from "main/components/Areas/SingleAreaDropdown";
import SingleQuarterDropdown from "main/components/Quarters/SingleQuarterDropdown";
 
import { useBackend } from "main/utils/useBackend";
import { useSystemInfo } from "main/utils/systemInfo";
import { quarterRange } from "main/utils/quarterUtilities";
 
const GeneralEducationSearchForm = ({ fetchJSON }) => {
  // Stryker disable all : not sure how to test/mock local storage
  const localArea = localStorage.getItem("GeneralEducationSearch.Area");
  const localQuarter = localStorage.getItem("GeneralEducationSearch.Quarter");
 
  const { data: systemInfo } = useSystemInfo();
  const startQtr = systemInfo?.startQtrYYYYQ || "20211";
  const endQtr = systemInfo?.endQtrYYYYQ || "20214";
  const quarters = quarterRange(startQtr, endQtr);
 
  const {
    data: areas,
    error: _error,
    status: _status,
  } = useBackend(
    ["/api/public/generalEducationInfo"],
    { method: "GET", url: "/api/public/generalEducationInfo" },
    [],
  );
 
  const [area, setArea] = useState(localArea || "A");
  const [quarter, setQuarter] = useState(
    localQuarter || quarters[0]?.yyyyq || "20211",
  );
 
  const handleSubmit = (event) => {
    event.preventDefault();
    fetchJSON(event, { area, quarter });
  };
 
  return (
    <Form onSubmit={handleSubmit}>
      <Container>
        <Row>
          <Col md="auto">
            <SingleQuarterDropdown
              quarters={quarters}
              quarter={quarter}
              setQuarter={setQuarter}
              controlId={"GeneralEducationSearch.Quarter"}
            />
          </Col>
          <Col md="auto">
            <SingleAreaDropdown
              areas={areas}
              area={area}
              setArea={setArea}
              controlId={"GeneralEducationSearch.Area"}
            />
          </Col>
        </Row>
        <Row style={{ paddingTop: 10, paddingBottom: 10 }}>
          <Col md="auto">
            <Button variant="primary" type="submit">
              Submit
            </Button>
          </Col>
        </Row>
      </Container>
    </Form>
  );
};
 
export default GeneralEducationSearchForm;