summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/node/components/manifest/components_application_panel-ManifestIssueList.test.js
blob: 71d59d3e07534697dbb182268f9c1789f0d1f197 (plain)
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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Import libs
const { shallow } = require("enzyme");
const { createFactory } = require("react");

const ManifestIssueList = createFactory(
  require("resource://devtools/client/application/src/components/manifest/ManifestIssueList.js")
);

/*
 * Tests for the ManifestIssue component
 */

describe("ManifestIssueList", () => {
  it("renders the expected snapshot for a populated list", () => {
    const issues = [
      { level: "error", message: "Foo" },
      { level: "warning", message: "Foo" },
      { level: "warning", message: "Bar" },
    ];
    const wrapper = shallow(ManifestIssueList({ issues }));
    expect(wrapper).toMatchSnapshot();
  });

  it("groups issues by level and shows errors first", () => {
    const issues = [
      { level: "warning", message: "A warning" },
      { level: "error", message: "An error" },
      { level: "warning", message: "Another warning" },
    ];
    const wrapper = shallow(ManifestIssueList({ issues }));
    expect(wrapper).toMatchSnapshot();

    expect(wrapper.find("ManifestIssue").get(0).props.level).toBe("error");
    expect(wrapper.find("ManifestIssue").get(1).props.level).toBe("warning");
    expect(wrapper.find("ManifestIssue").get(2).props.level).toBe("warning");
  });

  it("skips rendering empty level groups", () => {
    const issues = [
      { level: "warning", message: "A warning" },
      { level: "warning", message: "Another warning" },
    ];
    const wrapper = shallow(ManifestIssueList({ issues }));
    expect(wrapper).toMatchSnapshot();

    const lists = wrapper.find(".js-manifest-issues");
    expect(lists).toHaveLength(1);
  });

  it("renders nothing for empty issues", () => {
    const wrapper = shallow(ManifestIssueList({ issues: [] }));
    expect(wrapper).toMatchSnapshot();
  });
});