From 7db9c238e8a3458746cfbce91848f9d24934c49f Mon Sep 17 00:00:00 2001 From: Ryan Barnett Date: Tue, 26 Dec 2023 09:03:47 -0500 Subject: [PATCH] Fix large promo test (#1863) * 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 --- .../features/large-promo/default.jsx | 4 +- .../features/large-promo/default.test.jsx | 46 +++++++++++++++++-- .../top-table-list/_children/large.jsx | 4 +- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/blocks/large-promo-block/features/large-promo/default.jsx b/blocks/large-promo-block/features/large-promo/default.jsx index d9817f86ca..af4a0b5b08 100644 --- a/blocks/large-promo-block/features/large-promo/default.jsx +++ b/blocks/large-promo-block/features/large-promo/default.jsx @@ -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 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 668a30a0f5..5d9dbc67f1 100644 --- a/blocks/large-promo-block/features/large-promo/default.test.jsx +++ b/blocks/large-promo-block/features/large-promo/default.test.jsx @@ -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: () => {}, @@ -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, }; @@ -116,6 +116,7 @@ describe("Large Promo", () => { }); it("should render complete promo", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); it("should not render overline", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { expect(screen.queryByRole("img")).not.toBeNull(); }); - it("should not render date", () => { + it("should not render date when disabled", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { 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( + , + ); + expect(screen.queryByText("December 02, 2019 at 6:58PM UTC")).toBeNull(); + }); + it("should not render byline", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); it("should not render headline", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); it("should not render description", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); it("should only render Image", () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); it('should not render Image if "showImage" is false', () => { + useContent.mockReturnValueOnce(largePromoMock); render( { }); 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", @@ -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", @@ -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", @@ -314,6 +350,7 @@ describe("Large Promo", () => { headlines: { basic: "Baby panda born at the zoo", }, + display_date: "2019-12-02T18:58:11.638Z", }); render( { 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( { }, } = 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 =