{"size": 1585, "ext": "js", "max_stars_repo_path": "src/App.test.js", "max_stars_repo_name": "alexjball/rate-quote", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/App.test.js", "max_issues_repo_name": "alexjball/rate-quote", "max_issues_repo_issues_event_min_datetime": "2022-02-13T20:29:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T10:24:14.000Z", "max_forks_repo_path": "src/App.test.js", "max_forks_repo_name": "alexjball/rate-quote", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 32.3469387755, "max_line_length": 78, "alphanum_fraction": 0.7123028391}
import React from "react";
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import App from "./App";
import { PropertyType, Occupancy } from "./RateQuoteClient";

// Use node-fetch as the fetch polyfill, rather than JSDom's browser polyfill.
// node-fetch supports the wildcard CORS headers the endpoint uses.
// https://github.com/jsdom/jsdom/issues/2408
import nodeFetch from "node-fetch";
window.fetch = nodeFetch;

test("renders a button to get quotes", () => {
  const { getByText } = render(<App />);
  const linkElement = getByText(/Quote Rates/);
  expect(linkElement).toBeInTheDocument();
});

test("fetches quotes and shows results", async () => {
  const {
    getByLabelText,
    queryByText,
    queryAllByText,
    getByText,
    findByText
  } = render(<App />);

  userEvent.type(getByLabelText("Loan Size"), "450000");
  userEvent.type(getByLabelText("Credit Score"), "680");
  userEvent.selectOptions(
    getByLabelText("Property Type"),
    PropertyType.MultiFamily
  );
  userEvent.selectOptions(getByLabelText("Occupancy"), Occupancy.Investment);

  // No result table
  expect(queryByText("Closing Costs")).toBeNull();

  // Search for quotes
  getByText("Quote Rates").click();

  // Table appears
  await expect(findByText("Closing Costs")).resolves.toBeTruthy();
  expect(queryAllByText("TFB Federal Credit Union")).toHaveLength(3);
  expect(queryAllByText(/\$2555/)).not.toHaveLength(0);
  expect(queryAllByText(/\$6150/)).not.toHaveLength(0);
  expect(queryAllByText(/5.623\%/)).not.toHaveLength(0);
});
