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
58 changes: 42 additions & 16 deletions frontends/mit-open/src/pages/ChannelPage/ChannelPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,43 @@ const setupApis = (

describe("ChannelPage", () => {
it("Displays the channel title, banner, and avatar", async () => {
const { channel } = setupApis()
const { channel } = setupApis({
search_filter: "offered_by=ocw",
channel_type: "unit",
})
renderTestApp({ url: `/c/${channel.channel_type}/${channel.name}` })

const title = await screen.findAllByText(channel.title)
const header = title[0].closest("header")
const findTitle = (titles: HTMLElement[]) => {
return titles[
titles.findIndex(
(title: HTMLElement) =>
title.textContent === channel.title ||
title.textContent === channel.configuration.heading,
)
]
}
await waitFor(() => {
const titles = screen.getAllByRole("heading")
const title = findTitle(titles)
expect(title).toBeInTheDocument()
})
const titles = screen.getAllByRole("heading")
const title = findTitle(titles)
expect(title).toBeInTheDocument()
const header = title.closest("header")
assertInstanceOf(header, HTMLElement)
const images = within(header).getAllByRole("img") as HTMLImageElement[]
const headerStyles = getComputedStyle(header)
expect(headerStyles.backgroundImage).toContain(
channel.configuration.banner_background,
)
if (channel.channel_type !== "unit") {
/*
* unit channels are filtered out from this assertion
* because they wrap the background image in a linear-gradient,
* which causes react testing library to not render the background-image
* property at all
*/
expect(headerStyles.backgroundImage).toContain(
channel.configuration.banner_background,
)
}
expect(images[0].src).toContain(channel.configuration.logo)
})
it("Displays a featured carousel if the channel type is 'unit'", async () => {
Expand Down Expand Up @@ -158,7 +184,7 @@ describe("ChannelPage", () => {
"platform=ocw&platform=mitxonline&department=8&department=9",
})
renderTestApp({ url: `/c/${channel.channel_type}/${channel.name}` })
await screen.findByText(channel.title)
await screen.findAllByText(channel.title)
const expectedProps = expect.objectContaining({
constantSearchParams: {
platform: ["ocw", "mitxonline"],
Expand All @@ -176,7 +202,7 @@ describe("ChannelPage", () => {
const { channel } = setupApis()
channel.search_filter = undefined
renderTestApp({ url: `/c/${channel.channel_type}/${channel.name}` })
await screen.findByText(channel.title)
await screen.findAllByText(channel.title)

expect(mockedChannelSearch).toHaveBeenCalledTimes(0)
})
Expand All @@ -185,17 +211,17 @@ describe("ChannelPage", () => {
const { channel } = setupApis()
channel.search_filter = undefined
renderTestApp({ url: `/c/${channel.channel_type}/${channel.name}` })
await screen.findByText(channel.title)
await screen.findAllByText(channel.title)

await waitFor(() => {
expect(
screen.getByText(channel.configuration.sub_heading),
).toBeInTheDocument()
screen.getAllByText(channel.configuration.sub_heading).forEach((el) => {
expect(el).toBeInTheDocument()
})
})
await waitFor(() => {
expect(
screen.getByText(channel.configuration.heading),
).toBeInTheDocument()
screen.getAllByText(channel.configuration.heading).forEach((el) => {
expect(el).toBeInTheDocument()
})
})
})

Expand Down
14 changes: 7 additions & 7 deletions frontends/mit-open/src/pages/ChannelPage/ChannelPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react"
import { useParams } from "react-router"
import ChannelPageSkeleton from "./ChannelPageSkeleton"
import { ChannelPageTemplate } from "./ChannelPageTemplate"
import { useChannelDetail } from "api/hooks/channels"
import FieldSearch from "./ChannelSearch"
import type {
Facets,
FacetKey,
BooleanFacets,
import {
type Facets,
type FacetKey,
type BooleanFacets,
} from "@mitodl/course-search-utils"
import { ChannelTypeEnum } from "api/v0"
import TestimonialDisplay from "@/page-components/TestimonialDisplay/TestimonialDisplay"
Expand Down Expand Up @@ -41,7 +41,7 @@ const ChannelPage: React.FC = () => {
return (
name &&
channelType && (
<ChannelPageSkeleton name={name} channelType={channelType}>
<ChannelPageTemplate name={name} channelType={channelType}>
<p>{channelQuery.data?.public_description}</p>
{channelType === "unit" ? (
<StyledTestimonialDisplay offerors={[name]} />
Expand All @@ -52,7 +52,7 @@ const ChannelPage: React.FC = () => {
channelType={channelType}
/>
)}
</ChannelPageSkeleton>
</ChannelPageTemplate>
)
)
}
Expand Down
Loading