Flow Coverage Report - src/components/tests/Outline.spec.js

FilenamePercentTotalCoveredUncovered
src/components/tests/Outline.spec.js 68 % 124 85 39
x
 
1
import React from "react";
2
import { shallow } from "enzyme";
3
import Outline from "../../components/PrimaryPanes/Outline";
4
import devtoolsConfig from "devtools-config";
5
import { makeSymbolDeclaration } from "../../utils/test-head";
6
7
1x
const sourceId = "id";
8
9
1x
function generateDefaults(symbols) {
10
  return {
11
1x
    selectLocation: jest.genMockFunction(),
12
    selectedSource: {
13
      get: () => sourceId
14
    },
15
    isHidden: false,
16
1x
    symbols
17
  };
18
}
19
20
function render(symbols = {}) {
21
3x
  const props = generateDefaults(symbols);
22
6x
  const component = shallow(<Outline.WrappedComponent {...props} />);
23
2x
  return { component, props };
24
}
25
26
describe("Outline", () => {
27
  beforeEach(() => {
28
1x
    devtoolsConfig.isEnabled = jest.fn();
29
1x
    devtoolsConfig.isEnabled.mockReturnValue(true);
30
  });
31
32
  it("should render a list of functions when properties change", async () => {
33
1x
    const symbols = {
34
      functions: [
35
        makeSymbolDeclaration("my_example_function1", 21),
36
        makeSymbolDeclaration("my_example_function2", 22)
37
      ]
38
    };
39
40
2x
    const { component } = render(symbols);
41
1x
    expect(component).toMatchSnapshot();
42
  });
43
44
  it("should render ignore anonimous functions", async () => {
45
1x
    const symbols = {
46
      functions: [
47
        makeSymbolDeclaration("my_example_function1", 21),
48
        makeSymbolDeclaration("anonymous", 25)
49
      ]
50
    };
51
52
2x
    const { component } = render(symbols);
53
1x
    expect(component).toMatchSnapshot();
54
  });
55
56
  it("should select a line of code in the current file on click", async () => {
57
1x
    const startLine = 12;
58
1x
    const symbols = {
59
      functions: [makeSymbolDeclaration("my_example_function", startLine)]
60
    };
61
62
3x
    const { component, props } = render(symbols);
63
64
2x
    const { selectLocation } = props;
65
4x
    const listItem = component.find("li").first();
66
2x
    listItem.simulate("click");
67
1x
    expect(selectLocation).toHaveBeenCalledWith({ line: 12, sourceId });
68
  });
69
});
70