Skip to content

Commit

Permalink
[Themes 1884 ] fix (#2143)
Browse files Browse the repository at this point in the history
* Added FormatAuthors to check

---------

Co-authored-by: Malavika Koppula <[email protected]>
  • Loading branch information
malavikakoppula and Malavika Koppula authored May 22, 2024
1 parent 56f49d9 commit e344e42
Show file tree
Hide file tree
Showing 4 changed files with 2,875 additions and 2,987 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ const ExtraLarge = (props) => {
const contentHeading = showHeadlineXL ? element?.headlines?.basic : null;
const contentUrl = element?.websites?.[arcSite]?.website_url;
const embedMarkup = playVideoInPlaceXL && getVideoFromANS(element);
const hasAuthors = showBylineXL && element?.credits?.by?.length > 0;
const contentAuthors =
showBylineXL && element?.credits?.by?.length > 0
? formatAuthors(element.credits.by, phrases.t("global.and-text"))
: null;
const ansImage = getImageFromANS(element);
const imageParams =
element && ansImage
Expand All @@ -107,12 +110,12 @@ const ExtraLarge = (props) => {
contentHeading ||
showImageXL ||
contentDescription ||
hasAuthors ||
contentAuthors ||
hasDate ? (
<>
<article className={BLOCK_CLASS_NAME}>
{hasOverline ? <Overline href={overlineUrl}>{overlineText}</Overline> : null}
{contentHeading || showImageXL || contentDescription || hasAuthors || hasDate ? (
{contentHeading || showImageXL || contentDescription || contentAuthors || hasDate ? (
<Stack>
{contentHeading ? (
<HeadingSection>
Expand Down Expand Up @@ -140,13 +143,13 @@ const ExtraLarge = (props) => {
</MediaItem>
) : null}
{contentDescription ? <Paragraph>{contentDescription}</Paragraph> : null}
{hasAuthors || hasDate ? (
{contentAuthors || hasDate ? (
<Attribution>
<Join separator={Separator}>
{hasAuthors ? (
{contentAuthors ? (
<Join separator={() => " "}>
{phrases.t("global.by-text")}
{formatAuthors(element?.credits?.by, phrases.t("global.and-text"))}
{contentAuthors}
</Join>
) : null}
{hasDate ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import '@testing-library/jest-dom'
import mockData from "../../../mock-data";

import ExtraLarge from "./extra-large";
Expand All @@ -14,23 +15,23 @@ describe("the extra large promo feature", () => {
it("should return null if no show flag is true", () => {
const config = {};
const { container } = render(<ExtraLarge element={mockData} customFields={config} />);
expect(container.firstChild).toBeNull();
expect(container).toBeEmptyDOMElement();
});

it("should return an overline if showOverline is true", () => {
const config = {
showOverlineXL: true,
};
render(<ExtraLarge element={mockData} customFields={config} />);
expect(screen.queryByRole("link", { name: "Premium" })).not.toBeNull();
expect(screen.getByRole("link", { name: "Premium" })).not.toBeNull();
});

it("should return a headline if showHeadline is true", () => {
const config = {
showHeadlineXL: true,
};
render(<ExtraLarge element={mockData} customFields={config} />);
expect(screen.queryByRole("heading", { name: config.headline })).not.toBeNull();
expect(screen.getByRole("heading", { name: config.headline })).not.toBeNull();
});

it("should return a image if showImage is true", () => {
Expand All @@ -39,7 +40,7 @@ describe("the extra large promo feature", () => {
showImageXL: true,
};
render(<ExtraLarge element={mockData} customFields={config} />);
expect(screen.queryByRole("img", { name: config.headline })).not.toBeNull();
expect(screen.getByRole("img", { name: config.headline })).not.toBeNull();
});

it("should return a fallback image if showImage is true and imageUrl is not valid", () => {
Expand All @@ -48,7 +49,7 @@ describe("the extra large promo feature", () => {
showImageXL: true,
};
render(<ExtraLarge element={mockData} customFields={config} />);
expect(screen.queryByRole("img", { name: config.headline })).not.toBeNull();
expect(screen.getByRole("img", { name: config.headline })).not.toBeNull();
});

it("should return a description if showDescription is true", () => {
Expand All @@ -57,17 +58,17 @@ describe("the extra large promo feature", () => {
};
render(<ExtraLarge element={mockData} 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 return a byline if showByline is true", () => {
const config = {
showBylineXL: true,
};
const { getByText } = render(<ExtraLarge element={mockData} customFields={config} />);
render(<ExtraLarge element={mockData} 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 @@ -76,7 +77,7 @@ describe("the extra large promo feature", () => {
showDateXL: true,
};
render(<ExtraLarge element={mockData} customFields={config} />);
expect(screen.queryByText("January 30, 2020", { exact: false })).not.toBeNull();
expect(screen.getByText("January 30, 2020", { exact: false })).not.toBeNull();
});

it("should returned a sponsored overline if it's sponsored content", () => {
Expand All @@ -89,7 +90,7 @@ describe("the extra large promo feature", () => {
showOverlineXL: true,
};
render(<ExtraLarge element={modifiedData} customFields={config} />);
expect(screen.queryByText("global.sponsored-content")).not.toBeNull();
expect(screen.getByText("global.sponsored-content")).not.toBeNull();
});

it("should return a video if playVideoInPlace is true and video content available", () => {
Expand All @@ -106,6 +107,6 @@ describe("the extra large promo feature", () => {
showImageXL: true,
};
render(<ExtraLarge element={modifiedData} customFields={config} />);
expect(screen.queryByText("video embed")).not.toBeNull();
expect(screen.getByText("video embed")).not.toBeNull();
});
});
Loading

0 comments on commit e344e42

Please sign in to comment.