@instructure/ui-view 8.53.3-snapshot-22 → 8.53.3-snapshot-23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React, { CSSProperties } from 'react'
26
+ import { render, screen } from '@testing-library/react'
27
+ import '@testing-library/jest-dom'
28
+
29
+ import { View } from '../../index'
30
+ import { runAxeCheck } from '@instructure/ui-axe-check'
31
+
32
+ describe('<View />', () => {
33
+ it('should render', () => {
34
+ const { container } = render(
35
+ <View>
36
+ <h1>View Content</h1>
37
+ </View>
38
+ )
39
+ const view = container.querySelector("span[class$='-view']")
40
+
41
+ expect(view).toBeInTheDocument()
42
+ expect(view).toHaveTextContent('View Content')
43
+ })
44
+
45
+ it('should render children', () => {
46
+ render(
47
+ <View>
48
+ <h1>View Content</h1>
49
+ </View>
50
+ )
51
+
52
+ const viewContent = screen.getByText('View Content')
53
+
54
+ expect(viewContent).toBeInTheDocument()
55
+ expect(viewContent.tagName).toBe('H1')
56
+ })
57
+
58
+ it('should pass whitelisted style attributes', () => {
59
+ const styleProps: CSSProperties = {
60
+ top: '160px',
61
+ left: '5px',
62
+ minWidth: '20px',
63
+ minHeight: '208px',
64
+ position: 'absolute',
65
+ transform: 'translate(30px, 15px)',
66
+ overflow: 'hidden',
67
+ display: 'block',
68
+ pointerEvents: 'none'
69
+ }
70
+
71
+ const { container } = render(
72
+ <View style={{ ...styleProps }}>
73
+ <h1>View Content</h1>
74
+ </View>
75
+ )
76
+
77
+ const view = container.querySelector("span[class$='-view']")
78
+ const styles = getComputedStyle(view!)
79
+
80
+ expect(styles['top']).toEqual('160px')
81
+ expect(styles['left']).toEqual('5px')
82
+ expect(styles['minWidth']).toEqual('20px')
83
+ expect(styles['minHeight']).toEqual('208px')
84
+ expect(styles['position']).toEqual('absolute')
85
+ expect(styles['transform']).toEqual('translate(30px, 15px)')
86
+ expect(styles['overflow']).toEqual('hidden')
87
+ expect(styles['display']).toEqual('block')
88
+ expect(styles['pointerEvents']).toEqual('none')
89
+ })
90
+
91
+ it('should pass flex style', () => {
92
+ const { container } = render(
93
+ <View style={{ flexBasis: '200px' }}>
94
+ <h1>View Content</h1>
95
+ </View>
96
+ )
97
+
98
+ const view = container.querySelector("span[class$='-view']")
99
+ const styles = getComputedStyle(view!)
100
+
101
+ expect(styles['flexBasis']).toEqual('200px')
102
+ })
103
+
104
+ it('should pass className', () => {
105
+ const className = 'fooBarBaz'
106
+
107
+ const { container } = render(
108
+ <View className={className}>
109
+ <h1>View Content</h1>
110
+ </View>
111
+ )
112
+
113
+ const view = container.querySelector("span[class$='-view']")
114
+
115
+ expect(view!.classList.contains(className))
116
+ })
117
+
118
+ it('should provide an elementRef', () => {
119
+ const elementRef = jest.fn()
120
+
121
+ const { container } = render(
122
+ <View elementRef={elementRef}>
123
+ <h1>View Content</h1>
124
+ </View>
125
+ )
126
+ const view = container.querySelector("span[class$='-view']")
127
+
128
+ expect(elementRef).toHaveBeenCalledWith(view)
129
+ })
130
+
131
+ it('should pass cursor', () => {
132
+ const cursor = 'cell'
133
+
134
+ const { container } = render(
135
+ <View cursor={cursor}>
136
+ <h1>View Content</h1>
137
+ </View>
138
+ )
139
+
140
+ const view = container.querySelector("span[class$='-view']")
141
+ const styles = getComputedStyle(view!)
142
+
143
+ expect(styles['cursor']).toEqual(cursor)
144
+ })
145
+
146
+ it('should set overflow', () => {
147
+ const { container } = render(
148
+ <View overflowX="hidden" overflowY="auto">
149
+ <h1>View Content</h1>
150
+ </View>
151
+ )
152
+
153
+ const view = container.querySelector("span[class$='-view']")
154
+ const styles = getComputedStyle(view!)
155
+
156
+ expect(styles.overflowX).toEqual('hidden')
157
+ expect(styles.overflowY).toEqual('auto')
158
+ })
159
+
160
+ it('should set CSS position', () => {
161
+ const { container } = render(
162
+ <View position="fixed">
163
+ <h1>View Content</h1>
164
+ </View>
165
+ )
166
+
167
+ const view = container.querySelector("span[class$='-view']")
168
+ const styles = getComputedStyle(view!)
169
+
170
+ expect(styles.position).toEqual('fixed')
171
+ })
172
+
173
+ it('should set inline offset (top, bottom, left, right)', () => {
174
+ const { container } = render(
175
+ <View
176
+ insetBlockStart="0"
177
+ insetBlockEnd="20px"
178
+ insetInlineStart="2px"
179
+ insetInlineEnd="3px"
180
+ >
181
+ <h1>View Content</h1>
182
+ </View>
183
+ )
184
+
185
+ const view = container.querySelector("span[class$='-view']")
186
+ const styles = getComputedStyle(view!)
187
+
188
+ expect(styles['top']).toEqual('0px')
189
+ expect(styles['bottom']).toEqual('20px')
190
+ expect(styles['left']).toEqual('2px')
191
+ expect(styles['right']).toEqual('3px')
192
+ })
193
+
194
+ it('should override default max-width', () => {
195
+ const { container, rerender } = render(
196
+ <View>
197
+ <h1>View Content</h1>
198
+ </View>
199
+ )
200
+
201
+ const view = container.querySelector("span[class$='-view']")
202
+ const styles = getComputedStyle(view!)
203
+
204
+ expect(styles.maxWidth).toEqual('100%')
205
+
206
+ rerender(
207
+ <View maxWidth="200px">
208
+ <h1>View Content</h1>
209
+ </View>
210
+ )
211
+
212
+ const newStyles = getComputedStyle(view!)
213
+
214
+ expect(newStyles.maxWidth).toEqual('200px')
215
+ })
216
+
217
+ describe('withFocusOutline', () => {
218
+ it('should warn when withFocusOutline is true without position=relative', () => {
219
+ const consoleErrorSpy = jest
220
+ .spyOn(console, 'error')
221
+ .mockImplementation(() => {})
222
+
223
+ render(
224
+ <View withFocusOutline>
225
+ <h1>View Content</h1>
226
+ </View>
227
+ )
228
+ const expectedErrorMessage =
229
+ 'Warning: [View] the focus outline will only show if the `position` prop is `relative`.'
230
+
231
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
232
+ expect.stringContaining(expectedErrorMessage),
233
+ expect.any(String)
234
+ )
235
+
236
+ consoleErrorSpy.mockRestore()
237
+ })
238
+
239
+ it('should warn when withFocusOutline is `true`, display is set to `inline`, and focusPosition is set to `offset`', () => {
240
+ const consoleErrorSpy = jest
241
+ .spyOn(console, 'error')
242
+ .mockImplementation(() => {})
243
+
244
+ render(
245
+ <View withFocusOutline display="inline" focusPosition="offset">
246
+ <h1>View Content</h1>
247
+ </View>
248
+ )
249
+
250
+ const expectedErrorMessage =
251
+ 'Warning: [View] when display is set to `inline` the focus outline will only show if `focusPosition` is set to `inset`.'
252
+
253
+ expect(consoleErrorSpy).toHaveBeenCalledWith(
254
+ expect.stringContaining(expectedErrorMessage),
255
+ expect.any(String)
256
+ )
257
+
258
+ consoleErrorSpy.mockRestore()
259
+ })
260
+ })
261
+
262
+ it('should meet a11y standards', async () => {
263
+ const { container } = render(<View>View Content</View>)
264
+
265
+ const axeCheck = await runAxeCheck(container)
266
+
267
+ expect(axeCheck).toBe(true)
268
+ })
269
+ })
@@ -43,6 +43,9 @@
43
43
  },
44
44
  {
45
45
  "path": "../ui-themes/tsconfig.build.json"
46
+ },
47
+ {
48
+ "path": "../ui-axe-check/tsconfig.build.json"
46
49
  }
47
50
  ]
48
51
  }