From 9058cd0a233656048abb7535af803fff5d388c35 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Tue, 15 Oct 2024 13:38:05 -0400 Subject: [PATCH 1/4] conditionalizing for xpro platform --- .../LearningResourceExpanded.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.tsx b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.tsx index 8949a85719..e188df4962 100644 --- a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.tsx +++ b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.tsx @@ -212,11 +212,13 @@ const CallToActionSection = ({ ) } - - const platformImage = - PLATFORMS[resource?.platform?.code as PlatformEnum]?.image - const { platform } = resource! + const offeredBy = resource?.offered_by + const platformCode = + (offeredBy?.code as PlatformEnum) === PlatformEnum.Xpro + ? (offeredBy?.code as PlatformEnum) + : (platform?.code as PlatformEnum) + const platformImage = PLATFORMS[platformCode]?.image const getCallToActionText = (resource: LearningResource): string => { if (resource?.platform?.code === PlatformEnum.Ocw) { @@ -244,7 +246,7 @@ const CallToActionSection = ({ {platformImage ? ( on - + ) : null} From 3416c2e7bd81349d365c8170eb5ac05003007418 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Wed, 16 Oct 2024 09:05:11 -0400 Subject: [PATCH 2/4] adding test --- .../LearningResourceExpanded.test.tsx | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx index 4848ea4785..8f742b6c1f 100644 --- a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx +++ b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx @@ -4,7 +4,12 @@ import { render, screen, within } from "@testing-library/react" import user from "@testing-library/user-event" import { LearningResourceExpanded } from "./LearningResourceExpanded" import type { LearningResourceExpandedProps } from "./LearningResourceExpanded" -import { ResourceTypeEnum, PodcastEpisodeResource, AvailabilityEnum } from "api" +import { + ResourceTypeEnum, + PodcastEpisodeResource, + AvailabilityEnum, + PlatformEnum, +} from "api" import { factories } from "api/test-utils" import { formatDate } from "ol-utilities" import { ThemeProvider } from "../ThemeProvider/ThemeProvider" @@ -132,6 +137,29 @@ describe("Learning Resource Expanded", () => { }, ) + test.each([ResourceTypeEnum.PodcastEpisode])( + "Renders xpro logo onditionally on offered_by=xpro and not platform.code", + (resourceType) => { + const resource = factories.learningResources.resource({ + resource_type: resourceType, + platform: { code: "test" }, + offered_by: { code: "xpro" }, + podcast_episode: { + episode_link: "https://example.com", + }, + }) + + setup(resource) + const xproImage = screen + .getAllByRole("img") + .find((img) => img.getAttribute("alt")?.includes("xPRO")) + + expect(xproImage).toBeInTheDocument() + + expect(xproImage).toHaveAttribute("alt", PlatformEnum.Xpro.name) + }, + ) + test(`Renders info section for resource type "${ResourceTypeEnum.Video}"`, () => { const resource = factories.learningResources.resource({ resource_type: ResourceTypeEnum.Video, From ee50b00b98a0211d7588fb9ef93b789f72f9328b Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Wed, 16 Oct 2024 09:26:00 -0400 Subject: [PATCH 3/4] fixing types --- .../LearningResourceExpanded.test.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx index 8f742b6c1f..f650895342 100644 --- a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx +++ b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx @@ -4,18 +4,14 @@ import { render, screen, within } from "@testing-library/react" import user from "@testing-library/user-event" import { LearningResourceExpanded } from "./LearningResourceExpanded" import type { LearningResourceExpandedProps } from "./LearningResourceExpanded" -import { - ResourceTypeEnum, - PodcastEpisodeResource, - AvailabilityEnum, - PlatformEnum, -} from "api" +import { ResourceTypeEnum, PodcastEpisodeResource, AvailabilityEnum } from "api" import { factories } from "api/test-utils" import { formatDate } from "ol-utilities" import { ThemeProvider } from "../ThemeProvider/ThemeProvider" import invariant from "tiny-invariant" import type { LearningResource } from "api" import { faker } from "@faker-js/faker/locale/en" +import { PLATFORMS } from "../Logo/Logo" const IMG_CONFIG: LearningResourceExpandedProps["imgConfig"] = { key: "fake-key", @@ -155,8 +151,7 @@ describe("Learning Resource Expanded", () => { .find((img) => img.getAttribute("alt")?.includes("xPRO")) expect(xproImage).toBeInTheDocument() - - expect(xproImage).toHaveAttribute("alt", PlatformEnum.Xpro.name) + expect(xproImage).toHaveAttribute("alt", PLATFORMS["xpro"].name) }, ) From cd31e342926f27a1f79e5905dafe69524a771825 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Wed, 16 Oct 2024 15:35:45 -0400 Subject: [PATCH 4/4] fixing typo --- .../LearningResourceExpanded/LearningResourceExpanded.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx index f650895342..0af5945c86 100644 --- a/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx +++ b/frontends/ol-components/src/components/LearningResourceExpanded/LearningResourceExpanded.test.tsx @@ -134,7 +134,7 @@ describe("Learning Resource Expanded", () => { ) test.each([ResourceTypeEnum.PodcastEpisode])( - "Renders xpro logo onditionally on offered_by=xpro and not platform.code", + "Renders xpro logo conditionally on offered_by=xpro and not platform.code", (resourceType) => { const resource = factories.learningResources.resource({ resource_type: resourceType,