AdBannerContextMenu.test.jsx (4048B)
1 import { shallow } from "enzyme"; 2 import { AdBannerContextMenu } from "content-src/components/DiscoveryStreamComponents/AdBannerContextMenu/AdBannerContextMenu"; 3 import { LinkMenu } from "content-src/components/LinkMenu/LinkMenu"; 4 import React from "react"; 5 6 describe("<AdBannerContextMenu>", () => { 7 let wrapper; 8 9 describe("Ad banner context menu options", () => { 10 const props = { 11 spoc: { url: "https://www.test.com/", shim: "aaabbbcccddd" }, 12 position: 1, 13 type: "billboard", 14 prefs: {}, 15 }; 16 17 beforeEach(() => { 18 wrapper = shallow(<AdBannerContextMenu {...props} />); 19 }); 20 21 it("should render a context menu button", () => { 22 assert.ok(wrapper.exists()); 23 assert.ok( 24 wrapper.find("moz-button").exists(), 25 "context menu button exists" 26 ); 27 28 // Make sure the menu wrapper has the correct default styles 29 assert.isFalse( 30 wrapper.find("div.ads-context-menu").hasClass("context-menu-open") 31 ); 32 }); 33 34 it("should render a context menu button with hover styles when context menu is open", () => { 35 let button = wrapper.find("moz-button"); 36 button.simulate("click", { 37 preventDefault: () => {}, 38 }); 39 40 // Make sure the menu wrapper adds an extra classname when the menu is open 41 assert.isTrue( 42 wrapper.find("div.ads-context-menu").hasClass("context-menu-open") 43 ); 44 }); 45 46 it("should render LinkMenu when context menu button is clicked", () => { 47 let button = wrapper.find("moz-button"); 48 button.simulate("click", { 49 preventDefault: () => {}, 50 }); 51 assert.equal(wrapper.find(LinkMenu).length, 1); 52 }); 53 54 it("should render LinkMenu when context menu is accessed with the 'Enter' key", () => { 55 let button = wrapper.find("moz-button"); 56 57 button.simulate("keydown", { key: "Enter", preventDefault: () => {} }); 58 59 assert.equal(wrapper.find(LinkMenu).length, 1); 60 }); 61 62 it("should render LinkMenu when context menu is accessed with the 'Space' key", () => { 63 let button = wrapper.find("moz-button"); 64 65 button.simulate("keydown", { key: " ", preventDefault: () => {} }); 66 67 assert.equal(wrapper.find(LinkMenu).length, 1); 68 }); 69 70 it("should pass props to LinkMenu", () => { 71 wrapper.find("moz-button").simulate("click", { 72 preventDefault: () => {}, 73 }); 74 const linkMenuProps = wrapper.find(LinkMenu).props(); 75 [ 76 "onUpdate", 77 "dispatch", 78 "keyboardAccess", 79 "options", 80 "shouldSendImpressionStats", 81 "userEvent", 82 "site", 83 "index", 84 "source", 85 ].forEach(prop => assert.property(linkMenuProps, prop)); 86 }); 87 88 it("should pass through the correct menu options to LinkMenu for ad banners with reporting INCLUDED", () => { 89 const propsWithReporting = { 90 ...props, 91 showAdReporting: true, 92 }; 93 wrapper = shallow(<AdBannerContextMenu {...propsWithReporting} />); 94 wrapper.find("moz-button").simulate("click", { 95 preventDefault: () => {}, 96 }); 97 const linkMenuProps = wrapper.find(LinkMenu).props(); 98 99 const linkMenuOptions = [ 100 "BlockAdUrl", 101 "ReportAd", 102 "ManageSponsoredContent", 103 "OurSponsorsAndYourPrivacy", 104 ]; 105 106 assert.deepEqual(linkMenuProps.options, linkMenuOptions); 107 }); 108 109 it("should pass through correct menu options to LinkMenu for ad banner with reporting EXCLUDED", () => { 110 const propsWithoutReporting = { 111 ...props, 112 showAdReporting: false, 113 }; 114 115 wrapper = shallow(<AdBannerContextMenu {...propsWithoutReporting} />); 116 wrapper.find("moz-button").simulate("click", { 117 preventDefault: () => {}, 118 }); 119 const linkMenuProps = wrapper.find(LinkMenu).props(); 120 121 const linkMenuOptions = [ 122 "BlockAdUrl", 123 "ManageSponsoredContent", 124 "OurSponsorsAndYourPrivacy", 125 ]; 126 127 assert.deepEqual(linkMenuProps.options, linkMenuOptions); 128 }); 129 }); 130 });