1
1
import React from "react"
2
- import { renderWithProviders , screen } from "@/test-utils"
2
+ import { renderWithProviders , screen , within } from "@/test-utils"
3
3
import { DashboardCard } from "./DashboardCard"
4
4
import { dashboardCourse } from "./test-utils"
5
5
import { faker } from "@faker-js/faker/locale/en"
@@ -11,10 +11,12 @@ describe("EnrollmentCard", () => {
11
11
const course = dashboardCourse ( )
12
12
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
13
13
14
- const courseLink = screen . getByRole ( "link" , {
14
+ const courseLinks = screen . getAllByRole ( "link" , {
15
15
name : course . title ,
16
16
} )
17
- expect ( courseLink ) . toHaveAttribute ( "href" , course . marketingUrl )
17
+ for ( const courseLink of courseLinks ) {
18
+ expect ( courseLink ) . toHaveAttribute ( "href" , course . marketingUrl )
19
+ }
18
20
} )
19
21
20
22
test ( "Courseware button is disabled if course has not started" , ( ) => {
@@ -24,11 +26,13 @@ describe("EnrollmentCard", () => {
24
26
} ,
25
27
} )
26
28
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
27
- const coursewareButton = screen . getByRole ( "button" , {
29
+ const coursewareButtons = screen . getAllByRole ( "button" , {
28
30
name : "Continue Course" ,
29
31
hidden : true ,
30
32
} )
31
- expect ( coursewareButton ) . toBeDisabled ( )
33
+ for ( const coursewareButton of coursewareButtons ) {
34
+ expect ( coursewareButton ) . toBeDisabled ( )
35
+ }
32
36
} )
33
37
34
38
test ( "Courseware button is enabled if course has started AND NOT ended" , ( ) => {
@@ -39,10 +43,12 @@ describe("EnrollmentCard", () => {
39
43
} ,
40
44
} )
41
45
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
42
- const coursewareLink = screen . getByRole ( "link" , {
46
+ const coursewareLinks = screen . getAllByRole ( "link" , {
43
47
name : "Continue Course" ,
44
48
} )
45
- expect ( coursewareLink ) . toHaveAttribute ( "href" , course . run . coursewareUrl )
49
+ for ( const coursewareLink of coursewareLinks ) {
50
+ expect ( coursewareLink ) . toHaveAttribute ( "href" , course . run . coursewareUrl )
51
+ }
46
52
} )
47
53
48
54
test ( "Courseware button says 'View Course' if course has ended" , ( ) => {
@@ -53,10 +59,12 @@ describe("EnrollmentCard", () => {
53
59
} ,
54
60
} )
55
61
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
56
- const coursewareLink = screen . getByRole ( "link" , {
62
+ const coursewareLinks = screen . getAllByRole ( "link" , {
57
63
name : "View Course" ,
58
64
} )
59
- expect ( coursewareLink ) . toHaveAttribute ( "href" , course . run . coursewareUrl )
65
+ for ( const coursewareLink of coursewareLinks ) {
66
+ expect ( coursewareLink ) . toHaveAttribute ( "href" , course . run . coursewareUrl )
67
+ }
60
68
} )
61
69
62
70
test . each ( [
@@ -93,8 +101,14 @@ describe("EnrollmentCard", () => {
93
101
( { overrides, expectation } ) => {
94
102
const course = dashboardCourse ( overrides )
95
103
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
96
- const upgradeRoot = screen . queryByTestId ( "upgrade-root" )
97
- expect ( ! ! upgradeRoot ) . toBe ( expectation . visible )
104
+ const upgradeRootDesktop = within (
105
+ screen . getByTestId ( "enrollment-card-desktop" ) ,
106
+ ) . queryByTestId ( "upgrade-root" )
107
+ const upgradeRootMobile = within (
108
+ screen . getByTestId ( "enrollment-card-mobile" ) ,
109
+ ) . queryByTestId ( "upgrade-root" )
110
+ expect ( ! ! upgradeRootDesktop ) . toBe ( expectation . visible )
111
+ expect ( ! ! upgradeRootMobile ) . toBe ( expectation . visible )
98
112
} ,
99
113
)
100
114
@@ -117,13 +131,20 @@ describe("EnrollmentCard", () => {
117
131
118
132
renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
119
133
120
- const upgradeRoot = screen . getByTestId ( "upgrade-root" )
121
- expect ( upgradeRoot ) . toBeVisible ( )
122
-
123
- expect ( upgradeRoot ) . toHaveTextContent ( / 5 d a y s r e m a i n i n g / )
124
- expect ( upgradeRoot ) . toHaveTextContent (
125
- `Add a certificate for $${ certificateUpgradePrice } ` ,
126
- )
134
+ const upgradeRootDesktop = within (
135
+ screen . getByTestId ( "enrollment-card-desktop" ) ,
136
+ ) . queryByTestId ( "upgrade-root" )
137
+ const upgradeRootMobile = within (
138
+ screen . getByTestId ( "enrollment-card-mobile" ) ,
139
+ ) . queryByTestId ( "upgrade-root" )
140
+ for ( const upgradeRoot of [ upgradeRootDesktop , upgradeRootMobile ] ) {
141
+ expect ( upgradeRoot ) . toBeVisible ( )
142
+
143
+ expect ( upgradeRoot ) . toHaveTextContent ( / 5 d a y s r e m a i n i n g / )
144
+ expect ( upgradeRoot ) . toHaveTextContent (
145
+ `Add a certificate for $${ certificateUpgradePrice } ` ,
146
+ )
147
+ }
127
148
} )
128
149
129
150
test ( "Shows number of days until course starts" , ( ) => {
@@ -141,18 +162,43 @@ describe("EnrollmentCard", () => {
141
162
} )
142
163
143
164
test . each ( [
144
- { enrollmentStatus : EnrollmentStatus . Completed , hasCompleted : true } ,
145
- { enrollmentStatus : EnrollmentStatus . Enrolled , hasCompleted : false } ,
165
+ {
166
+ enrollmentStatus : EnrollmentStatus . Completed ,
167
+ hasCompleted : true ,
168
+ showNotComplete : false ,
169
+ } ,
170
+ {
171
+ enrollmentStatus : EnrollmentStatus . Enrolled ,
172
+ hasCompleted : false ,
173
+ showNotComplete : false ,
174
+ } ,
175
+ {
176
+ enrollmentStatus : EnrollmentStatus . Completed ,
177
+ hasCompleted : true ,
178
+ showNotComplete : true ,
179
+ } ,
180
+ {
181
+ enrollmentStatus : EnrollmentStatus . Enrolled ,
182
+ hasCompleted : false ,
183
+ showNotComplete : true ,
184
+ } ,
146
185
] ) (
147
186
"Shows completed icon if course is completed" ,
148
- ( { enrollmentStatus, hasCompleted } ) => {
187
+ ( { enrollmentStatus, hasCompleted, showNotComplete } ) => {
149
188
const course = dashboardCourse ( {
150
189
enrollment : { status : enrollmentStatus } ,
151
190
} )
152
- renderWithProviders ( < DashboardCard dashboardResource = { course } /> )
153
-
154
- const completedIcon = screen . queryByRole ( "img" , { name : "Completed" } )
155
- expect ( ! ! completedIcon ) . toBe ( hasCompleted )
191
+ renderWithProviders (
192
+ < DashboardCard
193
+ dashboardResource = { course }
194
+ showNotComplete = { showNotComplete }
195
+ /> ,
196
+ )
197
+
198
+ const completedIcon = screen . queryAllByRole ( "img" , { name : "Completed" } )
199
+ for ( const icon of completedIcon ) {
200
+ expect ( ! ! icon ) . toBe ( hasCompleted )
201
+ }
156
202
} ,
157
203
)
158
204
} )
@@ -173,7 +219,13 @@ test.each([
173
219
/> ,
174
220
)
175
221
176
- const notCompletedIcon = screen . queryByTestId ( "not-complete-icon" )
177
- expect ( ! ! notCompletedIcon ) . toBe ( showNotComplete )
222
+ const notCompletedIconDesktop = within (
223
+ screen . getByTestId ( "enrollment-card-desktop" ) ,
224
+ ) . queryByTestId ( "not-complete-icon" )
225
+ const notCompletedIconMobile = within (
226
+ screen . getByTestId ( "enrollment-card-mobile" ) ,
227
+ ) . queryByTestId ( "not-complete-icon" )
228
+ expect ( ! ! notCompletedIconDesktop ) . toBe ( showNotComplete )
229
+ expect ( ! ! notCompletedIconMobile ) . toBe ( showNotComplete )
178
230
} ,
179
231
)
0 commit comments