contrast-badge.test.js (2656B)
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 5 "use strict"; 6 7 const { shallow, mount } = require("enzyme"); 8 9 const { 10 createFactory, 11 } = require("resource://devtools/client/shared/vendor/react.mjs"); 12 13 const Provider = createFactory( 14 require("resource://devtools/client/shared/vendor/react-redux.js").Provider 15 ); 16 const { 17 setupStore, 18 } = require("resource://devtools/client/accessibility/test/node/helpers.js"); 19 20 const Badge = require("resource://devtools/client/accessibility/components/Badge.js"); 21 const ContrastBadgeClass = require("resource://devtools/client/accessibility/components/ContrastBadge.js"); 22 const ContrastBadge = createFactory(ContrastBadgeClass); 23 24 const { 25 accessibility: { SCORES }, 26 } = require("resource://devtools/shared/constants.js"); 27 28 describe("ContrastBadge component:", () => { 29 const store = setupStore(); 30 31 it("error render", () => { 32 const wrapper = shallow(ContrastBadge({ error: true })); 33 expect(wrapper.html()).toMatchSnapshot(); 34 expect(wrapper.isEmptyRender()).toBe(true); 35 }); 36 37 it("success render", () => { 38 const wrapper = shallow( 39 ContrastBadge({ 40 value: 5.11, 41 isLargeText: false, 42 score: SCORES.AA, 43 }) 44 ); 45 expect(wrapper.html()).toMatchSnapshot(); 46 expect(wrapper.isEmptyRender()).toBe(true); 47 }); 48 49 it("success range render", () => { 50 const wrapper = shallow( 51 ContrastBadge({ 52 min: 5.11, 53 max: 6.25, 54 isLargeText: false, 55 score: SCORES.AA, 56 }) 57 ); 58 expect(wrapper.html()).toMatchSnapshot(); 59 expect(wrapper.isEmptyRender()).toBe(true); 60 }); 61 62 it("success large text render", () => { 63 const wrapper = shallow( 64 ContrastBadge({ 65 value: 3.77, 66 isLargeText: true, 67 score: SCORES.AA, 68 }) 69 ); 70 expect(wrapper.html()).toMatchSnapshot(); 71 expect(wrapper.isEmptyRender()).toBe(true); 72 }); 73 74 it("fail render", () => { 75 const wrapper = mount( 76 Provider( 77 { store }, 78 ContrastBadge({ 79 value: 3.77, 80 isLargeText: false, 81 score: SCORES.FAIL, 82 }) 83 ) 84 ); 85 86 expect(wrapper.html()).toMatchSnapshot(); 87 expect(wrapper.children().length).toBe(1); 88 const contrastBadge = wrapper.find(ContrastBadgeClass); 89 const badge = contrastBadge.childAt(0); 90 expect(badge.type()).toBe(Badge); 91 expect(badge.props()).toMatchObject({ 92 label: "contrast", 93 tooltip: "Does not meet WCAG standards for accessible text.", 94 }); 95 }); 96 });