Skip to content

Commit 84eb78a

Browse files
committed
Update unit listing page tests
1 parent 2bdea92 commit 84eb78a

File tree

3 files changed

+78
-44
lines changed

3 files changed

+78
-44
lines changed

frontends/api/src/test-utils/factories/channels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const _channelShared = (): Partial<Omit<Channel, "channel_type">> => {
148148
key: faker.lorem.slug(),
149149
value: faker.lorem.slug(),
150150
}),
151+
channel_url: `${faker.internet.url({ appendSlash: false })}${faker.system.directoryPath()}`,
151152
}
152153
}
153154

frontends/api/src/test-utils/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const channels = {
179179
details: (channelType: string, name: string) =>
180180
`${API_BASE_URL}/api/v0/channels/type/${channelType}/${name}/`,
181181
patch: (id: number) => `${API_BASE_URL}/api/v0/channels/${id}/`,
182+
list: (params?: Params<ChannelsApi, "channelsList">) =>
183+
`${API_BASE_URL}/api/v0/channels/${query(params)}`,
182184
}
183185

184186
const widgetLists = {

frontends/main/src/app-pages/UnitsListingPage/UnitsListingPage.test.tsx

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,71 @@ import React from "react"
22
import { renderWithProviders, screen, waitFor, within } from "@/test-utils"
33
import UnitsListingPage from "./UnitsListingPage"
44
import { factories, setMockResponse, urls } from "api/test-utils"
5+
import { ChannelTypeEnum } from "api/v0"
6+
import type { UnitChannel } from "api/v0"
57
import { assertHeadings } from "ol-test-utilities"
68

7-
describe("DepartmentListingPage", () => {
9+
describe("UnitListingPage", () => {
810
const setupApis = () => {
9-
const make = factories.learningResources
10-
const academicUnit1 = make.offeror({
11-
code: "academicUnit1",
12-
name: "Academic Unit 1",
13-
value_prop: "Academic Unit 1 value prop",
14-
professional: false,
11+
const make = factories.channels
12+
const academicUnit1 = make.channel({
13+
channel_type: ChannelTypeEnum.Unit,
14+
name: "academicUnit1",
15+
title: "Academic Unit 1",
16+
unit_detail: {
17+
unit: {
18+
value_prop: "Academic Unit 1 value prop",
19+
professional: false,
20+
},
21+
},
1522
})
16-
const academicUnit2 = make.offeror({
17-
code: "academicUnit2",
18-
name: "Academic Unit 2",
19-
value_prop: "Academic Unit 2 value prop",
20-
professional: false,
23+
const academicUnit2 = make.channel({
24+
channel_type: ChannelTypeEnum.Unit,
25+
name: "academicUnit2",
26+
title: "Academic Unit 2",
27+
unit_detail: {
28+
unit: {
29+
value_prop: "Academic Unit 2 value prop",
30+
professional: false,
31+
},
32+
},
2133
})
22-
const academicUnit3 = make.offeror({
23-
code: "academicUnit3",
24-
name: "Academic Unit 3",
25-
value_prop: "Academic Unit 3 value prop",
26-
professional: false,
34+
const academicUnit3 = make.channel({
35+
channel_type: ChannelTypeEnum.Unit,
36+
name: "academicUnit3",
37+
title: "Academic Unit 3",
38+
unit_detail: {
39+
unit: {
40+
value_prop: "Academic Unit 3 value prop",
41+
professional: false,
42+
},
43+
},
2744
})
2845

29-
const professionalUnit1 = make.offeror({
30-
code: "professionalUnit1",
31-
name: "Professional Unit 1",
32-
value_prop: "Professional Unit 1 value prop",
33-
professional: true,
46+
const professionalUnit1 = make.channel({
47+
channel_type: ChannelTypeEnum.Unit,
48+
name: "professionalUnit1",
49+
title: "Professional Unit 1",
50+
unit_detail: {
51+
unit: {
52+
value_prop: "Professional Unit 1 value prop",
53+
professional: true,
54+
},
55+
},
3456
})
35-
const professionalUnit2 = make.offeror({
36-
code: "professionalUnit2",
37-
name: "Professional Unit 2",
38-
value_prop: "Professional Unit 2 value prop",
39-
professional: true,
57+
const professionalUnit2 = make.channel({
58+
channel_type: ChannelTypeEnum.Unit,
59+
name: "professionalUnit2",
60+
title: "Professional Unit 2",
61+
unit_detail: {
62+
unit: {
63+
value_prop: "Professional Unit 2 value prop",
64+
professional: true,
65+
},
66+
},
4067
})
4168

42-
const units = [
69+
const unitChannels = [
4370
academicUnit1,
4471
academicUnit2,
4572
academicUnit3,
@@ -63,29 +90,29 @@ describe("DepartmentListingPage", () => {
6390

6491
setMockResponse.get(
6592
urls.channels.counts("unit"),
66-
units.map((unit) => {
93+
unitChannels.map((channel) => {
6794
return {
68-
name: unit.code,
95+
name: channel.name,
6996
counts: {
70-
courses: courseCounts[unit.code],
71-
programs: programCounts[unit.code],
97+
courses: courseCounts[channel.name],
98+
programs: programCounts[channel.name],
7299
},
73100
}
74101
}),
75102
)
76-
setMockResponse.get(urls.offerors.list(), {
77-
count: units.length,
78-
results: units,
103+
setMockResponse.get(urls.channels.list({ channel_type: "unit" }), {
104+
count: unitChannels.length,
105+
results: unitChannels,
79106
})
80107

81-
units.forEach((unit) => {
82-
setMockResponse.get(urls.channels.details("unit", unit.code), {
83-
channel_url: `${window.location.origin}/units/${unit.code}`,
84-
})
85-
})
108+
// units.forEach((unit) => {
109+
// setMockResponse.get(urls.channels.details("unit", unit.code), {
110+
// channel_url: `${window.location.origin}/units/${unit.code}`,
111+
// })
112+
// })
86113

87114
return {
88-
units,
115+
unitChannels,
89116
courseCounts,
90117
programCounts,
91118
}
@@ -98,7 +125,7 @@ describe("DepartmentListingPage", () => {
98125
})
99126

100127
it("Shows unit properties within the proper section", async () => {
101-
const { units, courseCounts, programCounts } = setupApis()
128+
const { unitChannels, courseCounts, programCounts } = setupApis()
102129

103130
renderWithProviders(<UnitsListingPage />)
104131

@@ -116,11 +143,15 @@ describe("DepartmentListingPage", () => {
116143
return links
117144
})
118145

119-
units.forEach((unit) => {
146+
unitChannels.forEach((channel) => {
147+
const { unit } = (channel as UnitChannel).unit_detail
120148
const section = unit.professional ? professionalSection : academicSection
121149
const card = within(section).getByTestId(`unit-card-${unit.code}`)
122150
const link = within(card).getByRole("link")
123-
expect(link).toHaveAttribute("href", `/units/${unit.code}`)
151+
expect(link).toHaveAttribute(
152+
"href",
153+
new URL(channel.channel_url!).pathname,
154+
)
124155

125156
const courseCount = courseCounts[unit.code]
126157
const programCount = programCounts[unit.code]

0 commit comments

Comments
 (0)