Skip to content

Commit

Permalink
Add editable headline, description and overline for extra-large-promo…
Browse files Browse the repository at this point in the history
…-block
  • Loading branch information
Gripholder committed Oct 15, 2024
1 parent 4c73cf4 commit ae9afc9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ const getType = (type, content) => (content?.type === type ? content : undefined

export const ExtraLargePromoPresentation = ({
hasOverline,
editableOverline,
contentHeading,
editableHeading,
showImage,
contentDescription,
editableDescription,
hasDate,
shouldLazyLoad,
overlineUrl,
Expand All @@ -61,7 +64,11 @@ export const ExtraLargePromoPresentation = ({
hasOverline || contentHeading || showImage || contentDescription || contentAuthors || hasDate ? (
<LazyLoad enabled={shouldLazyLoad}>
<article className={BLOCK_CLASS_NAME}>
{hasOverline ? <Overline href={overlineUrl}>{overlineText}</Overline> : null}
{hasOverline ? (
<Overline href={overlineUrl} suppressContentEditableWarning {...editableOverline}>
{overlineText}
</Overline>
) : null}
{contentHeading ||
showImage ||
contentDescription ||
Expand All @@ -71,7 +78,7 @@ export const ExtraLargePromoPresentation = ({
<Stack>
{contentHeading ? (
<HeadingSection>
<Heading>
<Heading suppressContentEditableWarning {...editableHeading}>
<Conditional component={Link} condition={contentUrl} href={contentUrl}>
{contentHeading}
</Conditional>
Expand Down Expand Up @@ -112,7 +119,11 @@ export const ExtraLargePromoPresentation = ({
)}
</MediaItem>
) : null}
{contentDescription ? <Paragraph>{contentDescription}</Paragraph> : null}
{contentDescription ? (
<Paragraph suppressContentEditableWarning {...editableDescription}>
{contentDescription}
</Paragraph>
) : null}
{contentAuthors || hasDate ? (
<Attribution>
<Join separator={Separator}>
Expand All @@ -136,7 +147,7 @@ export const ExtraLargePromoPresentation = ({

const ExtraLargePromo = ({ customFields }) => {
const { arcSite, isAdmin } = useFusionContext();
const { searchableField } = useEditableContent();
const { editableContent, searchableField } = useEditableContent();
const {
dateLocalization: { language, timeZone, dateTimeFormat } = {
language: "en",
Expand Down Expand Up @@ -290,17 +301,32 @@ const ExtraLargePromo = ({ customFields }) => {

// Default to websites object data
let [overlineText, overlineUrl] = [sectionText, sectionUrl];
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")
: {};
}

const hasOverline = showOverline && overlineText;
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 embedMarkup = playVideoInPlace && getVideoFromANS(content);
const contentAuthors =
Expand Down Expand Up @@ -351,9 +377,12 @@ const ExtraLargePromo = ({ customFields }) => {
return (
<ExtraLargePromoPresentation
hasOverline={hasOverline}
editableOverline={editableOverline}
contentHeading={contentHeading}
editableHeading={editableHeading}
showImage={showImage}
contentDescription={contentDescription}
editableDescription={editableDescription}
hasDate={hasDate}
shouldLazyLoad={shouldLazyLoad}
overlineUrl={overlineUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -45,6 +46,25 @@ describe("the extra large promo feature", () => {
expect(screen.queryByRole("link", { name: "Premium" })).not.toBeNull();

Check warning on line 46 in blocks/extra-large-promo-block/features/extra-large-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Use `getBy*` queries rather than `queryBy*` for checking element is present
});

it("should overline text be an editable field", () => {
const arcSite = "dagen"; // using default website

const config = {
showOverline: true,
};
render(<ExtraLargePromo customFields={config} />);

let overline = mockData?.websites[arcSite]?.website_section?.name;

if (!!mockData.owner?.sponsored) {

Check failure on line 59 in blocks/extra-large-promo-block/features/extra-large-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Redundant double negation
overline = mockData.label.basic.text;
} else if (!!mockData?.label?.basic?.display) {

Check failure on line 61 in blocks/extra-large-promo-block/features/extra-large-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Redundant double negation
overline = mockData?.label?.basic?.text;
}

overline ? expect(screen.getByText(overline)).toHaveAttribute("contenteditable", "true") : null; // Bypass test if overline value doesn't exist (to be editable)

Check failure on line 65 in blocks/extra-large-promo-block/features/extra-large-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Expected an assignment or function call and instead saw an expression
});

it("should return a headline if showHeadline is true", () => {
const config = {
showHeadline: true,
Expand All @@ -53,6 +73,26 @@ describe("the extra large promo feature", () => {
expect(screen.queryByRole("heading", { name: config.headline })).not.toBeNull();

Check warning on line 73 in blocks/extra-large-promo-block/features/extra-large-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Use `getBy*` queries rather than `queryBy*` for checking element is present
});

it("should headline be an editable field", () => {
const config = {
showHeadline: true,
};
render(<ExtraLargePromo customFields={config} />);

expect(screen.queryByRole("heading", { name: mockData.headlines.basic })).toHaveAttribute(
"contenteditable",
);
});

it("should description be an editable field", () => {
const config = {
showDescription: true,
};
render(<ExtraLargePromo customFields={config} />);

expect(screen.queryByText(mockData.description.basic)).toHaveAttribute("contenteditable");
});

it("should return a image if showImage is true", () => {
const config = {
imageOverrideURL: "#",
Expand Down

0 comments on commit ae9afc9

Please sign in to comment.