/**
 * TEAM: frontend_infra
 * @flow
 */

import {act} from "react-dom/test-utils";
// TODO: Fix this eslint issue on next edit. This is an autogenerated comment.
// eslint-disable-next-line flexport/no-legacy-dependencies
import {mount} from "enzyme";
import ProgressBar from "../ProgressBar";

function mountProgressBar(propOverrides: {...} = {}) {
  const defaultProps = {loaded: false};
  // $FlowFixMe[cannot-spread-inexact] upgrade 0.110.1 -> 0.111.1
  const mergedProps = {...defaultProps, ...propOverrides};
  return mount(<ProgressBar {...mergedProps} />);
}

describe("ProgressBar", () => {
  describe("it does the bare minimum", () => {
    it("matches snapshot", () => {
      const progressBar = mountProgressBar({loaded: false});
      expect(progressBar).toMatchSnapshot();
    });
    it("Renders children if loaded", () => {
      const testChild = "Hi, test.";
      const comp = mountProgressBar({loaded: true, children: testChild});

      act(() => {
        jest.runAllTimers();
      });
      comp.update();

      expect(comp.html()).toContain(testChild);
    });
  });
});
