audit-controller.test.js (2485B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const { mount } = require("enzyme"); 7 8 const { 9 createFactory, 10 } = require("resource://devtools/client/shared/vendor/react.mjs"); 11 const { 12 span, 13 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 14 15 const AuditController = createFactory( 16 require("resource://devtools/client/accessibility/components/AuditController.js") 17 ); 18 const { 19 mockAccessible, 20 } = require("resource://devtools/client/accessibility/test/node/helpers.js"); 21 22 describe("AuditController component:", () => { 23 it("dead accessible actor", () => { 24 const accessibleFront = mockAccessible(); 25 const wrapper = mount( 26 AuditController( 27 { 28 accessibleFront, 29 }, 30 span() 31 ) 32 ); 33 34 expect(wrapper.html()).toMatchSnapshot(); 35 expect(wrapper.find("span").length).toBe(1); 36 expect(wrapper.find("span").first().props()).toMatchObject({ 37 checks: undefined, 38 }); 39 40 const instance = wrapper.instance(); 41 expect(accessibleFront.on.mock.calls.length).toBe(1); 42 expect(accessibleFront.off.mock.calls.length).toBe(1); 43 expect(accessibleFront.on.mock.calls[0]).toEqual([ 44 "audited", 45 instance.onAudited, 46 ]); 47 expect(accessibleFront.off.mock.calls[0]).toEqual([ 48 "audited", 49 instance.onAudited, 50 ]); 51 }); 52 53 it("accessible without checks", () => { 54 const accessibleFront = mockAccessible({ 55 actorID: "1", 56 }); 57 const wrapper = mount( 58 AuditController( 59 { 60 accessibleFront, 61 }, 62 span() 63 ) 64 ); 65 66 expect(wrapper.html()).toMatchSnapshot(); 67 expect(accessibleFront.audit.mock.calls.length).toBe(1); 68 expect(accessibleFront.on.mock.calls.length).toBe(1); 69 expect(accessibleFront.off.mock.calls.length).toBe(0); 70 }); 71 72 it("accessible with checks", () => { 73 const checks = { foo: "bar" }; 74 const accessibleFront = mockAccessible({ 75 actorID: "1", 76 checks, 77 }); 78 const wrapper = mount( 79 AuditController( 80 { 81 accessibleFront, 82 }, 83 span({ className: "child" }) 84 ) 85 ); 86 87 expect(wrapper.html()).toMatchSnapshot(); 88 expect(wrapper.state("checks")).toMatchObject(checks); 89 expect(wrapper.find(".child").prop("checks")).toMatchObject(checks); 90 }); 91 });