@@ -4,62 +4,52 @@ import { MemoryRouter } from 'react-router-dom';
44import { render } from '../../../../test-utils/testing-library' ;
55import withRouterIfEnabled from '../withRouterIfEnabled' ;
66
7- describe ( 'elements/common/routing/withRouterIfEnabled' , ( ) => {
8- const TestComponent = ( props : any ) => {
9- const { history, location, match, routerDisabled } = props ;
10- return (
11- // Expose which props were injected
12- < div
13- data-testid = "test-component"
14- data-router-disabled = { routerDisabled ? 'true' : undefined }
15- data-has-history = { history ? 'true' : undefined }
16- data-has-location = { location ? 'true' : undefined }
17- data-has-match = { match ? 'true' : undefined }
18- />
19- ) ;
20- } ;
21- TestComponent . displayName = 'TestComponent' ;
22-
23- const WithRouterIfEnabled = withRouterIfEnabled ( TestComponent ) ;
24-
25- describe ( 'router enabled (default)' , ( ) => {
26- test ( 'injects router props when wrapped in a Router' , ( ) => {
27- const { getByTestId } = render (
28- < MemoryRouter initialEntries = { [ { pathname : '/foo' } ] } >
29- < WithRouterIfEnabled />
30- </ MemoryRouter > ,
31- ) ;
32-
33- const el = getByTestId ( 'test-component' ) ;
34- expect ( el ) . toHaveAttribute ( 'data-has-history' , 'true' ) ;
35- expect ( el ) . toHaveAttribute ( 'data-has-location' , 'true' ) ;
36- expect ( el ) . toHaveAttribute ( 'data-has-match' , 'true' ) ;
37- expect ( el ) . not . toHaveAttribute ( 'data-router-disabled' ) ;
38- } ) ;
39- } ) ;
7+ const TestComponent = ( props : any ) => {
8+ const { history, location, match, routerDisabled } = props ;
9+ return (
10+ < div
11+ data-testid = "test-component"
12+ data-router-disabled = { routerDisabled ? 'true' : undefined }
13+ data-has-history = { history ? 'true' : undefined }
14+ data-has-location = { location ? 'true' : undefined }
15+ data-has-match = { match ? 'true' : undefined }
16+ />
17+ ) ;
18+ } ;
19+ TestComponent . displayName = 'TestComponent' ;
20+
21+ const WithRouterIfEnabled = withRouterIfEnabled ( TestComponent ) ;
22+
23+ test ( 'injects router props when wrapped in a Router' , ( ) => {
24+ const { getByTestId } = render (
25+ < MemoryRouter initialEntries = { [ { pathname : '/foo' } ] } >
26+ < WithRouterIfEnabled />
27+ </ MemoryRouter > ,
28+ ) ;
29+
30+ const el = getByTestId ( 'test-component' ) ;
31+ expect ( el ) . toHaveAttribute ( 'data-has-history' , 'true' ) ;
32+ expect ( el ) . toHaveAttribute ( 'data-has-location' , 'true' ) ;
33+ expect ( el ) . toHaveAttribute ( 'data-has-match' , 'true' ) ;
34+ expect ( el ) . not . toHaveAttribute ( 'data-router-disabled' ) ;
35+ } ) ;
4036
41- describe ( 'router disabled via prop' , ( ) => {
42- test ( 'renders without Router and without router props' , ( ) => {
43- const { getByTestId } = render ( < WithRouterIfEnabled routerDisabled /> ) ;
44- const el = getByTestId ( 'test-component' ) ;
45- expect ( el ) . not . toHaveAttribute ( 'data-has-history' ) ;
46- expect ( el ) . not . toHaveAttribute ( 'data-has-location' ) ;
47- expect ( el ) . not . toHaveAttribute ( 'data-has-match' ) ;
48- expect ( el ) . toHaveAttribute ( 'data-router-disabled' , 'true' ) ;
49- } ) ;
50- } ) ;
37+ test ( 'renders without Router and without router props (routerDisabled prop)' , ( ) => {
38+ const { getByTestId } = render ( < WithRouterIfEnabled routerDisabled /> ) ;
39+ const el = getByTestId ( 'test-component' ) ;
40+ expect ( el ) . not . toHaveAttribute ( 'data-has-history' ) ;
41+ expect ( el ) . not . toHaveAttribute ( 'data-has-location' ) ;
42+ expect ( el ) . not . toHaveAttribute ( 'data-has-match' ) ;
43+ expect ( el ) . toHaveAttribute ( 'data-router-disabled' , 'true' ) ;
44+ } ) ;
5145
52- describe ( 'router disabled via feature flag' , ( ) => {
53- test ( 'renders without Router and without router props when feature is enabled' , ( ) => {
54- const { getByTestId } = render ( < WithRouterIfEnabled /> , {
55- wrapperProps : { features : { routerDisabled : { value : true } } } ,
56- } ) ;
46+ test ( 'renders without Router and without router props (feature flag)' , ( ) => {
47+ const features = { routerDisabled : { value : true } } ;
48+ const { getByTestId } = render ( < WithRouterIfEnabled features = { features } /> ) ;
5749
58- const el = getByTestId ( 'test-component' ) ;
59- expect ( el ) . not . toHaveAttribute ( 'data-has-history' ) ;
60- expect ( el ) . not . toHaveAttribute ( 'data-has-location' ) ;
61- expect ( el ) . not . toHaveAttribute ( 'data-has-match' ) ;
62- } ) ;
63- } ) ;
50+ const el = getByTestId ( 'test-component' ) ;
51+ expect ( el ) . not . toHaveAttribute ( 'data-has-history' ) ;
52+ expect ( el ) . not . toHaveAttribute ( 'data-has-location' ) ;
53+ expect ( el ) . not . toHaveAttribute ( 'data-has-match' ) ;
6454} ) ;
6555
0 commit comments