@@ -5,6 +5,14 @@ import {
5
5
} from '../../../../setupTest' ;
6
6
import UnitButton from './UnitButton' ;
7
7
8
+ jest . mock ( 'react-router-dom' , ( ) => {
9
+ const actual = jest . requireActual ( 'react-router-dom' ) ;
10
+ return {
11
+ ...actual ,
12
+ useLocation : ( ) => ( { pathname : '/preview/anything' } ) ,
13
+ } ;
14
+ } ) ;
15
+
8
16
describe ( 'Unit Button' , ( ) => {
9
17
let mockData ;
10
18
const courseMetadata = Factory . build ( 'courseMetadata' ) ;
@@ -31,6 +39,10 @@ describe('Unit Button', () => {
31
39
} ;
32
40
} ) ;
33
41
42
+ afterEach ( ( ) => {
43
+ jest . resetModules ( ) ;
44
+ } ) ;
45
+
34
46
it ( 'hides title by default' , ( ) => {
35
47
render ( < UnitButton { ...mockData } /> , { wrapWithRouter : true } ) ;
36
48
expect ( screen . getByRole ( 'tab' ) ) . not . toHaveTextContent ( unit . display_name ) ;
@@ -99,4 +111,19 @@ describe('Unit Button', () => {
99
111
100
112
expect ( screen . getByRole ( 'tab' ) ) . toBeInTheDocument ( ) ;
101
113
} ) ;
114
+
115
+ it ( 'prepends /preview to the unit path if in preview mode' , ( ) => {
116
+ const onClick = jest . fn ( ) ;
117
+
118
+ render (
119
+ < UnitButton { ...mockData } onClick = { onClick } /> ,
120
+ {
121
+ wrapWithRouter : true ,
122
+ initialEntries : [ '/preview/some/path' ] ,
123
+ } ,
124
+ ) ;
125
+
126
+ const button = screen . getByRole ( 'tab' ) ;
127
+ expect ( button . closest ( 'a' ) ) . toHaveAttribute ( 'href' , expect . stringContaining ( '/preview/course/' ) ) ;
128
+ } ) ;
102
129
} ) ;
0 commit comments