Skip to content

Commit

Permalink
Fix large promo test (#1863)
Browse files Browse the repository at this point in the history
* fix: large promo test had module mock bleed and there was also an issue within the date time logic failing a test

* chore: remove it.only

* fix: use Date.parse() for the date check to keep it consistent with other code
  • Loading branch information
rmbrntt authored Dec 26, 2023
1 parent 97de62c commit 7db9c23
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions blocks/large-promo-block/features/large-promo/default.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ const LargePromoItem = ({ customFields, arcSite }) => {
fallbackImage,
} = getProperties(arcSite);

const displayDate = localizeDateTime(
const displayDate = content?.display_date && Date.parse(content?.display_date) ? localizeDateTime(
new Date(content?.display_date),
dateTimeFormat,
language,
timeZone
);
) : "";
const phrases = usePhrases();

const editableDescription = content?.description
Expand Down
46 changes: 42 additions & 4 deletions blocks/large-promo-block/features/large-promo/default.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jest.mock("@wpmedia/arc-themes-components", () => ({
}));

jest.mock("fusion:content", () => ({
useContent: jest.fn(() => largePromoMock),
useContent: jest.fn(() => ({})),
useEditableContent: jest.fn(() => ({
editableContent: () => {},
searchableField: () => {},
Expand All @@ -103,10 +103,10 @@ jest.mock("fusion:content", () => ({
describe("Large Promo", () => {
afterEach(() => {
jest.resetModules();
jest.clearAllMocks();
});

it("should return null if lazyLoad on the server and not in the admin", () => {
useContent.mockReturnValueOnce(largePromoMock);
const updatedConfig = {
lazyLoad: true,
};
Expand All @@ -116,6 +116,7 @@ describe("Large Promo", () => {
});

it("should render complete promo", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -137,6 +138,7 @@ describe("Large Promo", () => {
});

it("should not render overline", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -156,7 +158,8 @@ describe("Large Promo", () => {
expect(screen.queryByRole("img")).not.toBeNull();
});

it("should not render date", () => {
it("should not render date when disabled", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -176,7 +179,33 @@ describe("Large Promo", () => {
expect(screen.queryByRole("img")).not.toBeNull();
});

it("should not render date when null", () => {
useContent.mockReturnValueOnce({
owner: {
sponsored: true,
},
headlines: {
basic: "Baby panda born at the zoo",
},
});
render(
<LargePromo
customFields={{
showByline: true,
showDate: true,
showDescription: false,
showHeadline: true,
showImage: false,
imageRatio: "4:3",
showOverline: true,
}}
/>,
);
expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).toBeNull();
});

it("should not render byline", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -197,6 +226,7 @@ describe("Large Promo", () => {
});

it("should not render headline", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -217,6 +247,7 @@ describe("Large Promo", () => {
});

it("should not render description", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -237,6 +268,7 @@ describe("Large Promo", () => {
});

it("should only render Image", () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -253,6 +285,7 @@ describe("Large Promo", () => {
});

it('should not render Image if "showImage" is false', () => {
useContent.mockReturnValueOnce(largePromoMock);
render(
<LargePromo
customFields={{
Expand All @@ -265,6 +298,7 @@ describe("Large Promo", () => {
});

it("should make a blank call to the signing-service if the image is from PhotoCenter and has an Auth value", () => {
useContent.mockReturnValueOnce(largePromoMock);
const config = {
imageOverrideAuth: "test hash",
imageOverrideURL: "test_id=123",
Expand All @@ -277,6 +311,7 @@ describe("Large Promo", () => {
});

it("should make a call to the signing-service if the image is from PhotoCenter but does not have an Auth value", () => {
useContent.mockReturnValueOnce(largePromoMock);
const config = {
imageOverrideAuth: "",
imageOverrideURL: "test_id=123",
Expand All @@ -292,6 +327,7 @@ describe("Large Promo", () => {
});

it("should make a call to the signing-service if the image is not from PhotoCenter", () => {
useContent.mockReturnValueOnce(largePromoMock);
const config = {
imageOverrideAuth: "",
imageOverrideURL: "test_id=123",
Expand All @@ -314,6 +350,7 @@ describe("Large Promo", () => {
headlines: {
basic: "Baby panda born at the zoo",
},
display_date: "2019-12-02T18:58:11.638Z",
});
render(
<LargePromo
Expand All @@ -332,10 +369,11 @@ describe("Large Promo", () => {
expect(screen.queryByText("global.sponsored-content")).not.toBeNull();
expect(screen.queryByText(largePromoMock.headlines.basic)).not.toBeNull();
expect(screen.queryByText(largePromoMock.description.basic)).toBeNull();
expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).toBeNull();
});

it("should render image icon label", () => {
useContent.mockReturnValueOnce(largePromoMock);

const { container } = render(
<LargePromo
customFields={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ const Large = (props) => {
},
} = getProperties(arcSite);

const displayDate = localizeDateTime(
const displayDate = Date.parse(element?.display_date) ? localizeDateTime(
new Date(element?.display_date),
dateTimeFormat,
language,
timeZone
);
) : "";
const phrases = usePhrases();

const videoOrGalleryContent =
Expand Down

0 comments on commit 7db9c23

Please sign in to comment.