tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

badges.test.js (3540B)


      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 { mount } = require("enzyme");
      8 
      9 const {
     10  createFactory,
     11 } = require("resource://devtools/client/shared/vendor/react.mjs");
     12 const Provider = createFactory(
     13  require("resource://devtools/client/shared/vendor/react-redux.js").Provider
     14 );
     15 const {
     16  setupStore,
     17 } = require("resource://devtools/client/accessibility/test/node/helpers.js");
     18 
     19 const Badge = require("resource://devtools/client/accessibility/components/Badge.js");
     20 const Badges = createFactory(
     21  require("resource://devtools/client/accessibility/components/Badges.js")
     22 );
     23 const ContrastBadge = require("resource://devtools/client/accessibility/components/ContrastBadge.js");
     24 
     25 const {
     26  accessibility: { SCORES },
     27 } = require("resource://devtools/shared/constants.js");
     28 
     29 describe("Badges component:", () => {
     30  const store = setupStore();
     31 
     32  it("no props render", () => {
     33    const wrapper = mount(Provider({ store }, Badges()));
     34    expect(wrapper.html()).toMatchSnapshot();
     35    expect(wrapper.isEmptyRender()).toBe(true);
     36  });
     37 
     38  it("null checks render", () => {
     39    const wrapper = mount(Provider({ store }, Badges({ checks: null })));
     40    expect(wrapper.html()).toMatchSnapshot();
     41    expect(wrapper.isEmptyRender()).toBe(true);
     42  });
     43 
     44  it("empty checks render", () => {
     45    const wrapper = mount(Provider({ store }, Badges({ checks: {} })));
     46    expect(wrapper.html()).toMatchSnapshot();
     47    expect(wrapper.isEmptyRender()).toBe(true);
     48  });
     49 
     50  it("unsupported checks render", () => {
     51    const wrapper = mount(Provider({ store }, Badges({ checks: { tbd: {} } })));
     52    expect(wrapper.html()).toMatchSnapshot();
     53    expect(wrapper.isEmptyRender()).toBe(true);
     54  });
     55 
     56  it("contrast ratio success render", () => {
     57    const wrapper = mount(
     58      Provider(
     59        { store },
     60        Badges({
     61          checks: {
     62            CONTRAST: {
     63              value: 5.11,
     64              color: [255, 0, 0, 1],
     65              backgroundColor: [255, 255, 255, 1],
     66              isLargeText: false,
     67              score: SCORES.AA,
     68            },
     69          },
     70        })
     71      )
     72    );
     73    expect(wrapper.html()).toMatchSnapshot();
     74    expect(wrapper.isEmptyRender()).toBe(true);
     75  });
     76 
     77  it("contrast ratio fail render", () => {
     78    const CONTRAST = {
     79      value: 3.1,
     80      color: [255, 0, 0, 1],
     81      backgroundColor: [255, 255, 255, 1],
     82      isLargeText: false,
     83      score: SCORES.FAIL,
     84    };
     85    const wrapper = mount(
     86      Provider({ store }, Badges({ checks: { CONTRAST } }))
     87    );
     88 
     89    expect(wrapper.html()).toMatchSnapshot();
     90    expect(wrapper.find(Badge).length).toBe(1);
     91    expect(wrapper.find(ContrastBadge).length).toBe(1);
     92    expect(wrapper.find(ContrastBadge).first().props()).toMatchObject(CONTRAST);
     93  });
     94 
     95  it("contrast ratio fail range render", () => {
     96    const CONTRAST = {
     97      min: 1.19,
     98      max: 1.39,
     99      color: [128, 128, 128, 1],
    100      backgroundColorMin: [219, 106, 116, 1],
    101      backgroundColorMax: [156, 145, 211, 1],
    102      isLargeText: false,
    103      score: SCORES.FAIL,
    104    };
    105    const wrapper = mount(
    106      Provider({ store }, Badges({ checks: { CONTRAST } }))
    107    );
    108 
    109    expect(wrapper.html()).toMatchSnapshot();
    110    expect(wrapper.find(Badge).length).toBe(1);
    111    expect(wrapper.find(ContrastBadge).length).toBe(1);
    112    expect(wrapper.find(ContrastBadge).first().props()).toMatchObject(CONTRAST);
    113  });
    114 });