diff --git a/blocks/large-promo-block/features/large-promo/default.jsx b/blocks/large-promo-block/features/large-promo/default.jsx index 45b716349..6e28a563f 100644 --- a/blocks/large-promo-block/features/large-promo/default.jsx +++ b/blocks/large-promo-block/features/large-promo/default.jsx @@ -49,6 +49,8 @@ export const LargePromoPresentation = ({ contentUrl, displayDate, editableDescription, + editableHeading, + editableOverline, embedMarkup, labelIconName, labelIconText, @@ -111,12 +113,18 @@ export const LargePromoPresentation = ({ contentDate ? ( {contentOverline ? ( - {contentOverline} + + {contentOverline} + ) : null} {contentHeading || contentDescription || contentAuthors || contentDate ? ( {contentHeading ? ( - + { : ""; const phrases = usePhrases(); + const editableHeading = content?.headlines ? editableContent(content, "headlines.basic") : {}; + const editableDescription = content?.description ? editableContent(content, "description.basic") : {}; @@ -328,6 +338,25 @@ const LargePromoItem = ({ customFields, arcSite }) => { content?.websites?.[arcSite]?.website_section || {}; let [overlineText, overlineURL] = [sectionText, sectionUrl]; + const shouldUseLabel = !!labelDisplay; + + let editableOverline = content?.websites?.[arcSite]?.website_section?.name + ? editableContent(content, `websites.${[arcSite]}.website_section.name`) + : {}; + + if (content?.owner?.sponsored) { + overlineText = content?.label?.basic?.text || phrases.t("global.sponsored-content"); + overlineURL = null; + editableOverline = content?.label?.basic?.text + ? editableContent(content, "label.basic.text") + : {}; + } else if (shouldUseLabel) { + [overlineText, overlineURL] = [labelText, labelUrl]; + editableOverline = content?.label?.basic?.text + ? editableContent(content, "label.basic.text") + : {}; + } + if (content?.owner?.sponsored) { overlineText = content?.label?.basic?.text || phrases.t("global.sponsored-content"); overlineURL = null; @@ -380,6 +409,8 @@ const LargePromoItem = ({ customFields, arcSite }) => { contentUrl={contentUrl} displayDate={displayDate} editableDescription={editableDescription} + editableHeading={editableHeading} + editableOverline={editableOverline} embedMarkup={embedMarkup} labelIconName={labelIconName} labelIconText={labelIconText} diff --git a/blocks/large-promo-block/features/large-promo/default.test.jsx b/blocks/large-promo-block/features/large-promo/default.test.jsx index 5d9dbc67f..95558c7bc 100644 --- a/blocks/large-promo-block/features/large-promo/default.test.jsx +++ b/blocks/large-promo-block/features/large-promo/default.test.jsx @@ -112,7 +112,7 @@ describe("Large Promo", () => { }; isServerSide.mockReturnValue(true); const { container } = render(); - expect(container.firstChild).toBe(null); + expect(container.innerHTML).toBe(''); }); it("should render complete promo", () => { @@ -130,11 +130,11 @@ describe("Large Promo", () => { />, ); - expect(screen.queryByText(largePromoMock.label.basic.text)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.description.basic)).not.toBeNull(); - expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByText(largePromoMock.label.basic.text)).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.description.basic)).not.toBeNull(); + expect(screen.getByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); + expect(screen.getByAltText("Baby panda born at the zoo")).not.toBeNull(); }); it("should not render overline", () => { @@ -152,10 +152,10 @@ describe("Large Promo", () => { />, ); expect(screen.queryByText(largePromoMock.label.basic.text)).toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.description.basic)).not.toBeNull(); - expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.description.basic)).not.toBeNull(); + expect(screen.getByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it("should not render date when disabled", () => { @@ -173,10 +173,10 @@ describe("Large Promo", () => { />, ); expect(screen.queryByText(largePromoMock.label.basic.text)).toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.description.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.description.basic)).not.toBeNull(); expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it("should not render date when null", () => { @@ -218,11 +218,11 @@ describe("Large Promo", () => { }} />, ); - expect(screen.queryByText(largePromoMock.label.basic.text)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.description.basic)).not.toBeNull(); - expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByText(largePromoMock.label.basic.text)).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.description.basic)).not.toBeNull(); + expect(screen.getByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it("should not render headline", () => { @@ -239,11 +239,11 @@ describe("Large Promo", () => { }} />, ); - expect(screen.queryByText(largePromoMock.label.basic.text)).not.toBeNull(); + expect(screen.getByText(largePromoMock.label.basic.text)).not.toBeNull(); expect(screen.queryByText(largePromoMock.headlines.basic)).toBeNull(); - expect(screen.queryByText(largePromoMock.description.basic)).not.toBeNull(); - expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByText(largePromoMock.description.basic)).not.toBeNull(); + expect(screen.getByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it("should not render description", () => { @@ -260,11 +260,11 @@ describe("Large Promo", () => { }} />, ); - expect(screen.queryByText(largePromoMock.label.basic.text)).not.toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText(largePromoMock.label.basic.text)).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); expect(screen.queryByText(largePromoMock.description.basic)).toBeNull(); - expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByText("December 02, 2019 at 6:58PM UTC")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it("should only render Image", () => { @@ -281,7 +281,7 @@ describe("Large Promo", () => { expect(screen.queryByText(largePromoMock.headlines.basic)).toBeNull(); expect(screen.queryByText(largePromoMock.description.basic)).toBeNull(); expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).toBeNull(); - expect(screen.queryByRole("img")).not.toBeNull(); + expect(screen.getByRole("img")).not.toBeNull(); }); it('should not render Image if "showImage" is false', () => { @@ -366,15 +366,15 @@ describe("Large Promo", () => { />, ); expect(screen.queryByText(largePromoMock.label.basic.text)).toBeNull(); - expect(screen.queryByText("global.sponsored-content")).not.toBeNull(); - expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull(); + expect(screen.getByText("global.sponsored-content")).not.toBeNull(); + expect(screen.getByText(largePromoMock.headlines.basic)).not.toBeNull(); expect(screen.queryByText(largePromoMock.description.basic)).toBeNull(); }); it("should render image icon label", () => { useContent.mockReturnValueOnce(largePromoMock); - const { container } = render( + render( { }} />, ); - expect(container.querySelector(".b-large-promo__icon_label")).not.toBeNull(); + const img = screen.getByAltText("Baby panda born at the zoo"); + expect(img).not.toBeNull(); }); // it("should render video player media when 'playVideoInPlace' prop is passed", () => {