Skip to content

Commit

Permalink
Shanbady/xpro logo for all xpro offerings (#1695)
Browse files Browse the repository at this point in the history
* conditionalizing for xpro platform

* adding test

* fixing types

* fixing typo
  • Loading branch information
shanbady authored Oct 16, 2024
1 parent 984eacb commit cffa89d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
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

0 comments on commit cffa89d

Please sign in to comment.