LinkParagraph.test.jsx (2742B)
1 import React from "react"; 2 import { mount } from "enzyme"; 3 import { LinkParagraph } from "content-src/components/LinkParagraph"; 4 5 describe("LinkParagraph component", () => { 6 let sandbox; 7 let wrapper; 8 let handleAction; 9 10 beforeEach(() => { 11 sandbox = sinon.createSandbox(); 12 handleAction = sandbox.stub(); 13 14 wrapper = mount( 15 <LinkParagraph 16 text_content={{ 17 text: { 18 string_id: "test-string-id", 19 }, 20 link_keys: ["privacy_policy"], 21 font_styles: "legal", 22 }} 23 handleAction={handleAction} 24 /> 25 ); 26 }); 27 28 afterEach(() => { 29 sandbox.restore(); 30 }); 31 32 it("should render LinkParagraph component", () => { 33 assert.ok(wrapper.exists()); 34 }); 35 36 it("should render copy with legal style if legal is passed to font_styles", () => { 37 assert.strictEqual(wrapper.find(".legal-paragraph").length, 1); 38 }); 39 40 it("should render one link when only one link id is passed", () => { 41 assert.strictEqual(wrapper.find(".legal-paragraph a").length, 1); 42 }); 43 44 it("should call handleAction method when link is clicked", () => { 45 const linkEl = wrapper.find(".legal-paragraph a"); 46 linkEl.simulate("click"); 47 assert.calledOnce(handleAction); 48 }); 49 50 it("should render two links if an additional link id is passed", () => { 51 wrapper.setProps({ 52 text_content: { 53 text: { 54 string_id: "test-string-id", 55 }, 56 link_keys: ["privacy_policy", "terms_of_use"], 57 font_styles: "legal", 58 }, 59 }); 60 assert.strictEqual(wrapper.find(".legal-paragraph a").length, 2); 61 }); 62 63 it("should render no links when no link id is passed", () => { 64 wrapper.setProps({ 65 text_content: { links: null }, 66 }); 67 assert.strictEqual(wrapper.find(".legal-paragraph a").length, 0); 68 }); 69 70 it("should render copy even when no link id is passed", () => { 71 wrapper.setProps({ 72 text_content: { links: null }, 73 }); 74 assert.ok(wrapper.find(".legal-paragraph")); 75 }); 76 77 it("should not render LinkParagraph component if text is not passed", () => { 78 wrapper.setProps({ text_content: { text: null } }); 79 assert.ok(wrapper.isEmptyRender()); 80 }); 81 82 it("should render copy in link style if no font style is passed", () => { 83 wrapper.setProps({ 84 text_content: { 85 text: { 86 string_id: "test-string-id", 87 }, 88 link_keys: ["learn_more"], 89 }, 90 }); 91 assert.strictEqual(wrapper.find(".link-paragraph").length, 1); 92 }); 93 94 it("should not render links if string_id is not provided", () => { 95 wrapper.setProps({ 96 text_content: { text: { string_id: null } }, 97 }); 98 assert.strictEqual(wrapper.find(".link-paragraph a").length, 0); 99 }); 100 });