@@ -2,44 +2,71 @@ import React from "react"
2
2
import { renderWithProviders , screen , waitFor , within } from "@/test-utils"
3
3
import UnitsListingPage from "./UnitsListingPage"
4
4
import { factories , setMockResponse , urls } from "api/test-utils"
5
+ import { ChannelTypeEnum } from "api/v0"
6
+ import type { UnitChannel } from "api/v0"
5
7
import { assertHeadings } from "ol-test-utilities"
6
8
7
- describe ( "DepartmentListingPage " , ( ) => {
9
+ describe ( "UnitListingPage " , ( ) => {
8
10
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
+ } ,
15
22
} )
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
+ } ,
21
33
} )
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
+ } ,
27
44
} )
28
45
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
+ } ,
34
56
} )
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
+ } ,
40
67
} )
41
68
42
- const units = [
69
+ const unitChannels = [
43
70
academicUnit1 ,
44
71
academicUnit2 ,
45
72
academicUnit3 ,
@@ -63,29 +90,29 @@ describe("DepartmentListingPage", () => {
63
90
64
91
setMockResponse . get (
65
92
urls . channels . counts ( "unit" ) ,
66
- units . map ( ( unit ) => {
93
+ unitChannels . map ( ( channel ) => {
67
94
return {
68
- name : unit . code ,
95
+ name : channel . name ,
69
96
counts : {
70
- courses : courseCounts [ unit . code ] ,
71
- programs : programCounts [ unit . code ] ,
97
+ courses : courseCounts [ channel . name ] ,
98
+ programs : programCounts [ channel . name ] ,
72
99
} ,
73
100
}
74
101
} ) ,
75
102
)
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 ,
79
106
} )
80
107
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
+ // })
86
113
87
114
return {
88
- units ,
115
+ unitChannels ,
89
116
courseCounts,
90
117
programCounts,
91
118
}
@@ -98,7 +125,7 @@ describe("DepartmentListingPage", () => {
98
125
} )
99
126
100
127
it ( "Shows unit properties within the proper section" , async ( ) => {
101
- const { units , courseCounts, programCounts } = setupApis ( )
128
+ const { unitChannels , courseCounts, programCounts } = setupApis ( )
102
129
103
130
renderWithProviders ( < UnitsListingPage /> )
104
131
@@ -116,11 +143,15 @@ describe("DepartmentListingPage", () => {
116
143
return links
117
144
} )
118
145
119
- units . forEach ( ( unit ) => {
146
+ unitChannels . forEach ( ( channel ) => {
147
+ const { unit } = ( channel as UnitChannel ) . unit_detail
120
148
const section = unit . professional ? professionalSection : academicSection
121
149
const card = within ( section ) . getByTestId ( `unit-card-${ unit . code } ` )
122
150
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
+ )
124
155
125
156
const courseCount = courseCounts [ unit . code ]
126
157
const programCount = programCounts [ unit . code ]
0 commit comments