InstallButton.test.jsx (1296B)
1 import React from "react"; 2 import { shallow } from "enzyme"; 3 import { InstallButton } from "content-src/components/InstallButton"; 4 5 const TEST_ADDON_INFO = [ 6 { 7 name: "Test Add-on", 8 id: "d634138d-c276-4fc8-924b-40a0ea21d284", 9 url: "http://example.com", 10 icons: { 32: "test.png", 64: "test.png" }, 11 type: "extension", 12 }, 13 ]; 14 15 describe("InstallButton component", () => { 16 let sandbox; 17 let wrapper; 18 let handleAction; 19 20 beforeEach(() => { 21 sandbox = sinon.createSandbox(); 22 handleAction = sandbox.stub(); 23 wrapper = shallow( 24 <InstallButton 25 key={TEST_ADDON_INFO.id} 26 addonId={TEST_ADDON_INFO.id} 27 addonType={TEST_ADDON_INFO.type} 28 addonName={TEST_ADDON_INFO.name} 29 index={"primary_button"} 30 handleAction={handleAction} 31 installedAddons={[]} 32 /> 33 ); 34 }); 35 36 it("should render InstallButton component", () => { 37 assert.ok(wrapper.exists()); 38 }); 39 40 it("should render the button with the correct value", () => { 41 assert.lengthOf(wrapper.find("button[value='primary_button']"), 1); 42 }); 43 44 it("should call handleAction method when button is link is clicked", () => { 45 const btnLink = wrapper.find("button.primary"); 46 btnLink.simulate("click"); 47 assert.calledOnce(handleAction); 48 }); 49 });