Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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",
Expand Down Expand Up @@ -132,6 +133,28 @@ describe("Learning Resource Expanded", () => {
},
)

test.each([ResourceTypeEnum.PodcastEpisode])(
"Renders xpro logo conditionally 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", PLATFORMS["xpro"].name)
},
)

test(`Renders info section for resource type "${ResourceTypeEnum.Video}"`, () => {
const resource = factories.learningResources.resource({
resource_type: ResourceTypeEnum.Video,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ const CallToActionSection = ({
</CallToAction>
)
}

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) {
Expand Down Expand Up @@ -244,7 +246,7 @@ const CallToActionSection = ({
{platformImage ? (
<Platform>
<OnPlatform>on</OnPlatform>
<StyledPlatformLogo platformCode={platform?.code as PlatformEnum} />
<StyledPlatformLogo platformCode={platformCode} />
</Platform>
) : null}
</CallToAction>
Expand Down
Loading