diff --git a/.prettierrc b/.prettierrc index f7b00e972..9d6346b28 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { "useTabs": true, "printWidth": 100, - experimentalTernaries: false, -} + "experimentalTernaries": false +} \ No newline at end of file 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", () => { diff --git a/blocks/medium-promo-block/features/medium-promo/default.jsx b/blocks/medium-promo-block/features/medium-promo/default.jsx index 8607eed5c..9a69a4d8a 100644 --- a/blocks/medium-promo-block/features/medium-promo/default.jsx +++ b/blocks/medium-promo-block/features/medium-promo/default.jsx @@ -35,7 +35,7 @@ const BLOCK_CLASS_NAME = "b-medium-promo"; const MediumPromo = ({ customFields }) => { const { registerSuccessEvent } = useComponentContext(); const { arcSite, isAdmin } = useFusionContext(); - const { searchableField } = useEditableContent(); + const { editableContent, searchableField } = useEditableContent(); const { dateLocalization: { language, timeZone, dateTimeFormat } = { language: "en", @@ -163,7 +163,13 @@ const MediumPromo = ({ customFields }) => { const hasAuthors = showByline ? content?.credits?.by && content?.credits?.by?.length : null; const contentDescription = showDescription ? content?.description?.basic : null; + const editableDescription = content?.description + ? editableContent(content, "description.basic") + : {}; const contentHeading = showHeadline ? content?.headlines?.basic : null; + const editableHeading = content?.headlines?.basic + ? editableContent(content, "headlines.basic") + : {}; const contentUrl = content?.websites?.[arcSite]?.website_url; const contentDate = content?.display_date; @@ -237,7 +243,7 @@ const MediumPromo = ({ customFields }) => { ) : null} {contentHeading ? ( - + { ) : null} - {showDescription ? {contentDescription} : null} + {showDescription ? ( + + {contentDescription} + + ) : null} {hasAuthors || showDate ? ( diff --git a/blocks/medium-promo-block/features/medium-promo/default.test.jsx b/blocks/medium-promo-block/features/medium-promo/default.test.jsx index ad50adcd6..5a960560c 100644 --- a/blocks/medium-promo-block/features/medium-promo/default.test.jsx +++ b/blocks/medium-promo-block/features/medium-promo/default.test.jsx @@ -1,4 +1,5 @@ import React from "react"; +import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import { useContent } from "fusion:content"; @@ -27,18 +28,18 @@ describe("the medium promo feature", () => { jest.clearAllMocks(); }); - it("should return null if lazyLoad on the server and not in the admin", () => { + it("should not render if lazyLoad on the server and not in the admin", () => { const config = { lazyLoad: true, }; - const { container } = render(); - expect(container.firstChild).toBe(null); + render(); + expect(screen.queryByRole("article")).not.toBeInTheDocument(); }); - it("should return null if none of the show... flags are true", () => { + it("should not render if none of the show... flags are true", () => { const config = {}; - const { container } = render(); - expect(container.firstChild).toBeNull(); + render(); + expect(screen.queryByRole("article")).not.toBeInTheDocument(); }); it("should display a headline if showHeadline is true", () => { @@ -47,7 +48,27 @@ describe("the medium promo feature", () => { }; render(); - expect(screen.queryByRole("heading", { name: config.headline })).not.toBeNull(); + expect(screen.getByRole("heading", { name: mockData.headlines.basic })).not.toBeNull(); + }); + + it("should headline be an editable field", () => { + const config = { + showHeadline: true, + }; + render(); + + expect(screen.queryByRole("heading", { name: mockData.headlines.basic })).toHaveAttribute( + "contenteditable", + ); + }); + + it("should description be an editable field", () => { + const config = { + showDescription: true, + }; + render(); + + expect(screen.queryByText(mockData.description.basic)).toHaveAttribute("contenteditable"); }); it("should display an image if showImage is true", () => { @@ -57,7 +78,7 @@ describe("the medium promo feature", () => { showImage: true, }; render(); - expect(screen.queryByRole("img", { name: config.headline })).not.toBeNull(); + expect(screen.getByRole("img", { name: config.headline })).not.toBeNull(); }); it("should make a blank call to the signing-service if the image is from PhotoCenter and has an Auth value", () => { @@ -108,7 +129,7 @@ describe("the medium promo feature", () => { showImage: true, }; render(); - expect(screen.queryByRole("img", { name: config.headline })).not.toBeNull(); + expect(screen.getByRole("img", { name: config.headline })).not.toBeNull(); }); it("should display a description if showDescription is true", () => { @@ -117,7 +138,7 @@ describe("the medium promo feature", () => { }; render(); expect( - screen.queryByText("Why does August seem hotter? Maybe it comes from weariness."), + screen.getByText("Why does August seem hotter? Maybe it comes from weariness."), ).not.toBeNull(); }); @@ -125,9 +146,11 @@ describe("the medium promo feature", () => { const config = { showByline: true, }; - const { getByText } = render(); + render(); expect( - getByText("global.by-text Example Author1, Example Author2, global.and-text Example Author3"), + screen.getByText( + "global.by-text Example Author1, Example Author2, global.and-text Example Author3", + ), ).not.toBeNull(); }); @@ -136,6 +159,6 @@ describe("the medium promo feature", () => { showDate: true, }; render(); - expect(screen.queryByText("January 30, 2020", { exact: false })).not.toBeNull(); + expect(screen.getByText("January 30, 2020", { exact: false })).not.toBeNull(); }); }); diff --git a/blocks/small-promo-block/features/small-promo/default.jsx b/blocks/small-promo-block/features/small-promo/default.jsx index 7bc6e985d..bced08732 100644 --- a/blocks/small-promo-block/features/small-promo/default.jsx +++ b/blocks/small-promo-block/features/small-promo/default.jsx @@ -35,7 +35,7 @@ const SmallPromo = ({ customFields }) => { } = customFields; const { registerSuccessEvent } = useComponentContext(); const { arcSite, isAdmin } = useFusionContext(); - const { searchableField } = useEditableContent(); + const { editableContent, searchableField } = useEditableContent(); const shouldLazyLoad = lazyLoad && !isAdmin; const content = @@ -171,9 +171,12 @@ const SmallPromo = ({ customFields }) => { ) : null; + const editableItem = + content?.headlines ? editableContent(content, "headlines.basic") : {}; + const promoHeading = showHeadline && headline ? ( - +