components_application_panel-Registration.test.js (2418B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Import libs 7 const { shallow } = require("enzyme"); 8 const { createFactory } = require("react"); 9 // Import test helpers 10 const { 11 setupStore, 12 } = require("resource://devtools/client/application/test/node/helpers.js"); 13 14 const { 15 REGISTRATION_SINGLE_WORKER, 16 REGISTRATION_MULTIPLE_WORKERS, 17 } = require("resource://devtools/client/application/test/node/fixtures/data/constants.js"); 18 19 const Registration = createFactory( 20 require("resource://devtools/client/application/src/components/service-workers/Registration.js") 21 ); 22 23 describe("Registration", () => { 24 it("Renders the expected snapshot for a registration with a worker", () => { 25 const store = setupStore({}); 26 27 const wrapper = shallow( 28 Registration({ 29 isDebugEnabled: true, 30 registration: REGISTRATION_SINGLE_WORKER, 31 store, 32 }) 33 ).dive(); 34 35 expect(wrapper).toMatchSnapshot(); 36 // ensure that we do have the proper amount of workers 37 expect(wrapper.find("Connect(Worker)")).toHaveLength(1); 38 }); 39 40 it("Renders the expected snapshot for a registration with multiple workers", () => { 41 const store = setupStore({}); 42 43 const wrapper = shallow( 44 Registration({ 45 isDebugEnabled: true, 46 registration: REGISTRATION_MULTIPLE_WORKERS, 47 store, 48 }) 49 ).dive(); 50 51 expect(wrapper).toMatchSnapshot(); 52 // ensure that we do have the proper amount of workers 53 expect(wrapper.find("Connect(Worker)")).toHaveLength(2); 54 }); 55 56 it("Renders the expected snapshot when sw debugging is disabled", () => { 57 const store = setupStore({}); 58 59 const wrapper = shallow( 60 Registration({ 61 isDebugEnabled: false, 62 registration: REGISTRATION_SINGLE_WORKER, 63 store, 64 }) 65 ).dive(); 66 67 expect(wrapper).toMatchSnapshot(); 68 }); 69 70 it("Removes the ending forward slash from the scope, when present", () => { 71 const store = setupStore({}); 72 73 const registration = Object.assign({}, REGISTRATION_SINGLE_WORKER, { 74 scope: "https://example.com/something/", 75 }); 76 77 const wrapper = shallow( 78 Registration({ 79 isDebugEnabled: false, 80 registration, 81 store, 82 }) 83 ).dive(); 84 85 const scopeEl = wrapper.find(".js-sw-scope"); 86 expect(scopeEl.text()).toBe("example.com/something"); 87 }); 88 });