summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/node/components/service-workers/components_application_panel-Registration.test.js
blob: 7473a61d230831efb9ef936210dddc9a3bfee877 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* 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");
// Import test helpers
const {
  setupStore,
} = require("resource://devtools/client/application/test/node/helpers.js");

const {
  REGISTRATION_SINGLE_WORKER,
  REGISTRATION_MULTIPLE_WORKERS,
} = require("resource://devtools/client/application/test/node/fixtures/data/constants.js");

const Registration = createFactory(
  require("resource://devtools/client/application/src/components/service-workers/Registration.js")
);

describe("Registration", () => {
  it("Renders the expected snapshot for a registration with a worker", () => {
    const store = setupStore({});

    const wrapper = shallow(
      Registration({
        isDebugEnabled: true,
        registration: REGISTRATION_SINGLE_WORKER,
        store,
      })
    ).dive();

    expect(wrapper).toMatchSnapshot();
    // ensure that we do have the proper amount of workers
    expect(wrapper.find("Connect(Worker)")).toHaveLength(1);
  });

  it("Renders the expected snapshot for a registration with multiple workers", () => {
    const store = setupStore({});

    const wrapper = shallow(
      Registration({
        isDebugEnabled: true,
        registration: REGISTRATION_MULTIPLE_WORKERS,
        store,
      })
    ).dive();

    expect(wrapper).toMatchSnapshot();
    // ensure that we do have the proper amount of workers
    expect(wrapper.find("Connect(Worker)")).toHaveLength(2);
  });

  it("Renders the expected snapshot when sw debugging is disabled", () => {
    const store = setupStore({});

    const wrapper = shallow(
      Registration({
        isDebugEnabled: false,
        registration: REGISTRATION_SINGLE_WORKER,
        store,
      })
    ).dive();

    expect(wrapper).toMatchSnapshot();
  });

  it("Removes the ending forward slash from the scope, when present", () => {
    const store = setupStore({});

    const registration = Object.assign({}, REGISTRATION_SINGLE_WORKER, {
      scope: "https://example.com/something/",
    });

    const wrapper = shallow(
      Registration({
        isDebugEnabled: false,
        registration,
        store,
      })
    ).dive();

    const scopeEl = wrapper.find(".js-sw-scope");
    expect(scopeEl.text()).toBe("example.com/something");
  });
});