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
|
/* 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 fixtures
const {
EMPTY_WORKER_LIST,
SINGLE_WORKER_DEFAULT_DOMAIN_LIST,
SINGLE_WORKER_DIFFERENT_DOMAIN_LIST,
MULTIPLE_WORKER_LIST,
MULTIPLE_WORKER_MIXED_DOMAINS_LIST,
} = require("resource://devtools/client/application/test/node/fixtures/data/constants.js");
// Import setupStore with imported & combined reducers
const {
setupStore,
} = require("resource://devtools/client/application/test/node/helpers.js");
// Import component
const WorkersPage = createFactory(
require("resource://devtools/client/application/src/components/service-workers/WorkersPage.js")
);
/**
* Test for App.js component
*/
describe("WorkersPage", () => {
const baseState = {
workers: { list: [], canDebugWorkers: true },
page: { domain: "example.com" },
};
function buildStoreWithWorkers(workerList) {
const workers = { list: workerList, canDebugWorkers: true };
const state = Object.assign({}, baseState, { workers });
return setupStore(state);
}
it("renders an empty list if there are no workers", () => {
const store = buildStoreWithWorkers(EMPTY_WORKER_LIST);
const wrapper = shallow(WorkersPage({ store })).dive();
expect(wrapper).toMatchSnapshot();
});
it("it renders a list with a single element if there's just 1 worker", () => {
const store = buildStoreWithWorkers(SINGLE_WORKER_DEFAULT_DOMAIN_LIST);
const wrapper = shallow(WorkersPage({ store })).dive();
expect(wrapper).toMatchSnapshot();
});
it("renders a list with multiple elements when there are multiple workers", () => {
const store = buildStoreWithWorkers(MULTIPLE_WORKER_LIST);
const wrapper = shallow(WorkersPage({ store })).dive();
expect(wrapper).toMatchSnapshot();
});
it("filters out workers from diferent domains", () => {
const store = buildStoreWithWorkers(MULTIPLE_WORKER_MIXED_DOMAINS_LIST);
const wrapper = shallow(WorkersPage({ store })).dive();
expect(wrapper).toMatchSnapshot();
});
it(
"filters out workers from different domains and renders an empty list when " +
"there is none left",
() => {
const store = buildStoreWithWorkers(SINGLE_WORKER_DIFFERENT_DOMAIN_LIST);
const wrapper = shallow(WorkersPage({ store })).dive();
expect(wrapper).toMatchSnapshot();
}
);
});
|