All files / components/RequestTypeDropdown RequestTypeDropdown.js

61.53% Statements 8/13
50% Branches 4/8
66.66% Functions 2/3
61.53% Lines 8/13

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        1x               5x   5x           5x                   5x   5x                 15x 15x                        
import { compareValues } from "main/utils/sortHelper";
import React, { useState } from "react";
import { Form } from "react-bootstrap";
 
const SingleRequestDropdown = ({
  requests,
  request,
  setrequest = null,
  controlId = null,
  onChange = null,
  label = "Request Area",
}) => {
  const localSearchrequest = localStorage.getItem(controlId);
 
  const [requestState, setrequestState] = useState(
    // Stryker disable next-line all : not sure how to test/mock local storage
    localSearchrequest || request,
  );
 
  // Stryker disable all
  const handleRequestOnChange = (event) => {
    localStorage.setItem(controlId, event.target.value);
    setrequestState(event.target.value);
    setrequest(event.target.value);
    if (onChange != null) {
      onChange(event);
    }
  };
  // Stryker restore all
 
  requests.sort(compareValues("requestCode"));
 
  return (
    <Form.Group controlId={controlId}>
      <Form.Label>{label}</Form.Label>
      <Form.Control
        as="select"
        value={requestState}
        onChange={handleRequestOnChange}
      >
        {requests.map(function (object) {
          const key = `${controlId}-option-${object.id}`;
          return (
            <option key={key} data-testid={key} value={object.requestType}>
              {object.requestType}
            </option>
          );
        })}
      </Form.Control>
    </Form.Group>
  );
};
 
export default SingleRequestDropdown;