@@ -4,7 +4,7 @@ import { render, waitFor } from "@testing-library/react";
4
4
import { ObjectItem } from "mendix" ;
5
5
import { createElement } from "react" ;
6
6
import { ItemHelperBuilder } from "../../utils/builders/ItemHelperBuilder" ;
7
- import { mockItemHelperWithAction , mockProps , setup } from "../../utils/test-utils" ;
7
+ import { mockItemHelperWithAction , mockProps , setup , withGalleryContext } from "../../utils/test-utils" ;
8
8
import { Gallery } from "../Gallery" ;
9
9
10
10
describe ( "Gallery" , ( ) => {
@@ -13,14 +13,14 @@ describe("Gallery", () => {
13
13
} ) ;
14
14
describe ( "DOM Structure" , ( ) => {
15
15
it ( "renders correctly" , ( ) => {
16
- const { asFragment } = render ( < Gallery { ...mockProps ( ) } /> ) ;
16
+ const { asFragment } = render ( withGalleryContext ( < Gallery { ...mockProps ( ) } /> ) ) ;
17
17
18
18
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
19
19
} ) ;
20
20
21
21
it ( "renders correctly with onclick event" , ( ) => {
22
22
const { asFragment } = render (
23
- < Gallery { ...mockProps ( ) } itemHelper = { mockItemHelperWithAction ( jest . fn ( ) ) } />
23
+ withGalleryContext ( < Gallery { ...mockProps ( ) } itemHelper = { mockItemHelperWithAction ( jest . fn ( ) ) } /> )
24
24
) ;
25
25
26
26
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
@@ -31,7 +31,7 @@ describe("Gallery", () => {
31
31
it ( "runs action on item click" , async ( ) => {
32
32
const execute = jest . fn ( ) ;
33
33
const props = mockProps ( { onClick : listAction ( mock => ( { ...mock ( ) , execute } ) ) } ) ;
34
- const { user, getAllByRole } = setup ( < Gallery { ...props } /> ) ;
34
+ const { user, getAllByRole } = setup ( withGalleryContext ( < Gallery { ...props } /> ) ) ;
35
35
const [ item ] = getAllByRole ( "listitem" ) ;
36
36
37
37
await user . click ( item ) ;
@@ -41,7 +41,7 @@ describe("Gallery", () => {
41
41
it ( "runs action on Enter|Space press when item is in focus" , async ( ) => {
42
42
const execute = jest . fn ( ) ;
43
43
const props = mockProps ( { onClick : listAction ( mock => ( { ...mock ( ) , execute } ) ) } ) ;
44
- const { user, getAllByRole } = setup ( < Gallery { ...props } header = { < span /> } /> ) ;
44
+ const { user, getAllByRole } = setup ( withGalleryContext ( < Gallery { ...props } header = { < span /> } /> ) ) ;
45
45
const [ item ] = getAllByRole ( "listitem" ) ;
46
46
47
47
await user . tab ( ) ;
@@ -55,37 +55,39 @@ describe("Gallery", () => {
55
55
56
56
describe ( "with different configurations per platform" , ( ) => {
57
57
it ( "contains correct classes for desktop" , ( ) => {
58
- const { getByRole } = render ( < Gallery { ...mockProps ( ) } desktopItems = { 12 } /> ) ;
58
+ const { getByRole } = render ( withGalleryContext ( < Gallery { ...mockProps ( ) } desktopItems = { 12 } /> ) ) ;
59
59
const list = getByRole ( "list" ) ;
60
60
expect ( list ) . toHaveClass ( "widget-gallery-lg-12" ) ;
61
61
} ) ;
62
62
63
63
it ( "contains correct classes for tablet" , ( ) => {
64
- const { getByRole } = render ( < Gallery { ...mockProps ( ) } tabletItems = { 6 } /> ) ;
64
+ const { getByRole } = render ( withGalleryContext ( < Gallery { ...mockProps ( ) } tabletItems = { 6 } /> ) ) ;
65
65
const list = getByRole ( "list" ) ;
66
66
expect ( list ) . toHaveClass ( "widget-gallery-md-6" ) ;
67
67
} ) ;
68
68
69
69
it ( "contains correct classes for phone" , ( ) => {
70
- const { getByRole } = render ( < Gallery { ...mockProps ( ) } phoneItems = { 3 } /> ) ;
70
+ const { getByRole } = render ( withGalleryContext ( < Gallery { ...mockProps ( ) } phoneItems = { 3 } /> ) ) ;
71
71
const list = getByRole ( "list" ) ;
72
72
expect ( list ) . toHaveClass ( "widget-gallery-sm-3" ) ;
73
73
} ) ;
74
74
} ) ;
75
75
76
76
describe ( "with custom classes" , ( ) => {
77
77
it ( "contains correct classes in the wrapper" , ( ) => {
78
- const { container } = render ( < Gallery { ...mockProps ( ) } className = "custom-class" /> ) ;
78
+ const { container } = render ( withGalleryContext ( < Gallery { ...mockProps ( ) } className = "custom-class" /> ) ) ;
79
79
80
80
expect ( container . querySelector ( ".custom-class" ) ) . toBeVisible ( ) ;
81
81
} ) ;
82
82
83
83
it ( "contains correct classes in the items" , ( ) => {
84
84
const { getAllByRole } = render (
85
- < Gallery
86
- { ...mockProps ( ) }
87
- itemHelper = { ItemHelperBuilder . sample ( b => b . withItemClass ( listExp ( ( ) => "custom-class" ) ) ) }
88
- />
85
+ withGalleryContext (
86
+ < Gallery
87
+ { ...mockProps ( ) }
88
+ itemHelper = { ItemHelperBuilder . sample ( b => b . withItemClass ( listExp ( ( ) => "custom-class" ) ) ) }
89
+ />
90
+ )
89
91
) ;
90
92
const [ item ] = getAllByRole ( "listitem" ) ;
91
93
@@ -96,7 +98,9 @@ describe("Gallery", () => {
96
98
describe ( "with pagination" , ( ) => {
97
99
it ( "renders correctly" , ( ) => {
98
100
const { asFragment } = render (
99
- < Gallery { ...mockProps ( ) } paging paginationPosition = "top" numberOfItems = { 20 } hasMoreItems />
101
+ withGalleryContext (
102
+ < Gallery { ...mockProps ( ) } paging paginationPosition = "top" numberOfItems = { 20 } hasMoreItems />
103
+ )
100
104
) ;
101
105
102
106
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
@@ -105,14 +109,16 @@ describe("Gallery", () => {
105
109
it ( "triggers correct events on click next button" , async ( ) => {
106
110
const setPage = jest . fn ( ) ;
107
111
const { user, getByLabelText } = setup (
108
- < Gallery
109
- { ...mockProps ( ) }
110
- paging
111
- paginationPosition = "top"
112
- numberOfItems = { 20 }
113
- hasMoreItems
114
- setPage = { setPage }
115
- />
112
+ withGalleryContext (
113
+ < Gallery
114
+ { ...mockProps ( ) }
115
+ paging
116
+ paginationPosition = "top"
117
+ numberOfItems = { 20 }
118
+ hasMoreItems
119
+ setPage = { setPage }
120
+ />
121
+ )
116
122
) ;
117
123
118
124
const next = getByLabelText ( "Go to next page" ) ;
@@ -124,11 +130,13 @@ describe("Gallery", () => {
124
130
describe ( "with empty option" , ( ) => {
125
131
it ( "renders correctly" , ( ) => {
126
132
const { asFragment } = render (
127
- < Gallery
128
- { ...mockProps ( ) }
129
- items = { [ ] }
130
- emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
131
- />
133
+ withGalleryContext (
134
+ < Gallery
135
+ { ...mockProps ( ) }
136
+ items = { [ ] }
137
+ emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
138
+ />
139
+ )
132
140
) ;
133
141
134
142
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
@@ -138,28 +146,32 @@ describe("Gallery", () => {
138
146
describe ( "with accessibility properties" , ( ) => {
139
147
it ( "renders correctly without items" , ( ) => {
140
148
const { asFragment } = render (
141
- < Gallery
142
- { ...mockProps ( ) }
143
- items = { [ ] }
144
- headerTitle = "filter title"
145
- emptyMessageTitle = "empty message"
146
- emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
147
- />
149
+ withGalleryContext (
150
+ < Gallery
151
+ { ...mockProps ( ) }
152
+ items = { [ ] }
153
+ headerTitle = "filter title"
154
+ emptyMessageTitle = "empty message"
155
+ emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
156
+ />
157
+ )
148
158
) ;
149
159
150
160
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
151
161
} ) ;
152
162
153
163
it ( "renders correctly with items" , ( ) => {
154
164
const { asFragment } = render (
155
- < Gallery
156
- { ...mockProps ( ) }
157
- items = { [ { id : "1" } as ObjectItem , { id : "2" } as ObjectItem , { id : "3" } as ObjectItem ] }
158
- ariaLabelItem = { ( item : ObjectItem ) => `title for '${ item . id } '` }
159
- headerTitle = "filter title"
160
- emptyMessageTitle = "empty message"
161
- emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
162
- />
165
+ withGalleryContext (
166
+ < Gallery
167
+ { ...mockProps ( ) }
168
+ items = { [ { id : "1" } as ObjectItem , { id : "2" } as ObjectItem , { id : "3" } as ObjectItem ] }
169
+ ariaLabelItem = { ( item : ObjectItem ) => `title for '${ item . id } '` }
170
+ headerTitle = "filter title"
171
+ emptyMessageTitle = "empty message"
172
+ emptyPlaceholderRenderer = { renderWrapper => renderWrapper ( < span > No items found</ span > ) }
173
+ />
174
+ )
163
175
) ;
164
176
165
177
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
@@ -169,7 +181,7 @@ describe("Gallery", () => {
169
181
describe ( "without filters" , ( ) => {
170
182
it ( "renders structure without header container" , ( ) => {
171
183
const props = { ...mockProps ( ) , showHeader : false , header : undefined } ;
172
- const { asFragment } = render ( < Gallery { ...props } /> ) ;
184
+ const { asFragment } = render ( withGalleryContext ( < Gallery { ...props } /> ) ) ;
173
185
174
186
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
175
187
} ) ;
0 commit comments