components-compatibility-Settings.test.js (2181B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Unit tests for the Settings component. 8 */ 9 10 const { shallow } = require("enzyme"); 11 const { 12 createFactory, 13 } = require("resource://devtools/client/shared/vendor/react.mjs"); 14 const { 15 thunk, 16 } = require("resource://devtools/client/shared/redux/middleware/thunk.js"); 17 const configureStore = require("redux-mock-store").default; 18 19 const Settings = createFactory( 20 require("resource://devtools/client/inspector/compatibility/components/Settings.js") 21 ); 22 23 const DEFAULT_BROWSERS = [ 24 { id: "firefox", name: "Firefox", status: "nightly", version: "78" }, 25 { id: "firefox", name: "Firefox", status: "beta", version: "77" }, 26 { id: "firefox", name: "Firefox", status: "current", version: "76" }, 27 ]; 28 29 describe("Settings component", () => { 30 it("renders default browsers with no selected browsers", () => { 31 const mockStore = configureStore([thunk()]); 32 const store = mockStore({ 33 compatibility: { 34 defaultTargetBrowsers: DEFAULT_BROWSERS, 35 targetBrowsers: [], 36 }, 37 }); 38 39 const connectWrapper = shallow(Settings({ store })); 40 const targetComponent = connectWrapper.dive(); 41 expect(targetComponent).toMatchSnapshot(); 42 }); 43 44 it("renders default browsers with a selected browsers", () => { 45 const mockStore = configureStore([thunk()]); 46 const store = mockStore({ 47 compatibility: { 48 defaultTargetBrowsers: DEFAULT_BROWSERS, 49 targetBrowsers: [DEFAULT_BROWSERS[1]], 50 }, 51 }); 52 53 const connectWrapper = shallow(Settings({ store })); 54 const targetComponent = connectWrapper.dive(); 55 expect(targetComponent).toMatchSnapshot(); 56 }); 57 58 it("renders default browsers with full selected browsers", () => { 59 const mockStore = configureStore([thunk()]); 60 const store = mockStore({ 61 compatibility: { 62 defaultTargetBrowsers: DEFAULT_BROWSERS, 63 targetBrowsers: DEFAULT_BROWSERS, 64 }, 65 }); 66 67 const connectWrapper = shallow(Settings({ store })); 68 const targetComponent = connectWrapper.dive(); 69 expect(targetComponent).toMatchSnapshot(); 70 }); 71 });