Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editable headline and description for medium-promo-block #2217

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions blocks/medium-promo-block/features/medium-promo/default.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -237,7 +243,7 @@ const MediumPromo = ({ customFields }) => {
) : null}

{contentHeading ? (
<Heading>
<Heading suppressContentEditableWarning {...editableHeading}>
<Conditional
component={Link}
condition={contentUrl}
Expand All @@ -249,7 +255,11 @@ const MediumPromo = ({ customFields }) => {
</Heading>
) : null}

{showDescription ? <Paragraph>{contentDescription}</Paragraph> : null}
{showDescription ? (
<Paragraph suppressContentEditableWarning {...editableDescription}>
{contentDescription}
</Paragraph>
) : null}
{hasAuthors || showDate ? (
<Attribution>
<Join separator={Separator}>
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 @@ -32,13 +33,13 @@
lazyLoad: true,
};
const { container } = render(<MediumPromo customFields={config} />);
expect(container.firstChild).toBe(null);

Check warning on line 36 in blocks/medium-promo-block/features/medium-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Avoid direct Node access. Prefer using the methods from Testing Library
});

it("should return null if none of the show... flags are true", () => {
const config = {};
const { container } = render(<MediumPromo customFields={config} />);
expect(container.firstChild).toBeNull();

Check warning on line 42 in blocks/medium-promo-block/features/medium-promo/default.test.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Avoid direct Node access. Prefer using the methods from Testing Library
});

it("should display a headline if showHeadline is true", () => {
Expand All @@ -47,7 +48,27 @@
};
render(<MediumPromo customFields={config} />);

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(<MediumPromo customFields={config} />);

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

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

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

it("should display an image if showImage is true", () => {
Expand All @@ -57,7 +78,7 @@
showImage: true,
};
render(<MediumPromo customFields={config} />);
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", () => {
Expand Down Expand Up @@ -108,7 +129,7 @@
showImage: true,
};
render(<MediumPromo customFields={config} />);
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", () => {
Expand All @@ -117,17 +138,19 @@
};
render(<MediumPromo customFields={config} />);
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();
});

it("should display a byline if showByline is true", () => {
const config = {
showByline: true,
};
const { getByText } = render(<MediumPromo customFields={config} />);
render(<MediumPromo customFields={config} />);
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();
});

Expand All @@ -136,6 +159,6 @@
showDate: true,
};
render(<MediumPromo customFields={config} />);
expect(screen.queryByText("January 30, 2020", { exact: false })).not.toBeNull();
expect(screen.getByText("January 30, 2020", { exact: false })).not.toBeNull();
});
});
Loading