@instructure/ui-editable 10.19.2-snapshot-3 → 10.19.2-snapshot-5

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.
@@ -1,254 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2018 - 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 { render, screen } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import '@testing-library/jest-dom'
28
-
29
- import { InPlaceEdit } from '../index'
30
- import type { InPlaceEditProps } from '../props'
31
- import { runAxeCheck } from '@instructure/ui-axe-check'
32
-
33
- const VIEWER_TEXT = 'viewer-text'
34
- const EDIT_BUTTON_TEXT = 'edit-button-text'
35
-
36
- const renderViewer = () => <div>{VIEWER_TEXT}</div>
37
- const renderEditor: InPlaceEditProps['renderEditor'] = ({
38
- editorRef,
39
- onBlur
40
- }) => {
41
- return (
42
- <input
43
- data-testid="input-editor"
44
- ref={editorRef}
45
- onBlur={onBlur}
46
- defaultValue="textvalue"
47
- aria-label="Editor"
48
- />
49
- )
50
- }
51
- const renderEditButton: InPlaceEditProps['renderEditButton'] = (props) => {
52
- const elementRef = props.elementRef as (el: Element | null) => void
53
- const { onClick, onFocus, onBlur, isVisible, readOnly } = props
54
- return InPlaceEdit.renderDefaultEditButton({
55
- isVisible,
56
- readOnly,
57
- label: EDIT_BUTTON_TEXT,
58
- ...{ onClick, onFocus, onBlur, elementRef }
59
- })
60
- }
61
-
62
- describe('<InPlaceEdit />', () => {
63
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
64
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
65
-
66
- beforeEach(() => {
67
- // Mocking console to prevent test output pollution and expect for messages
68
- consoleWarningMock = vi
69
- .spyOn(console, 'warn')
70
- .mockImplementation(() => {}) as any
71
- consoleErrorMock = vi
72
- .spyOn(console, 'error')
73
- .mockImplementation(() => {}) as any
74
- })
75
-
76
- afterEach(() => {
77
- consoleWarningMock.mockRestore()
78
- consoleErrorMock.mockRestore()
79
- })
80
-
81
- it('should render view mode', () => {
82
- render(
83
- <InPlaceEdit
84
- mode="view"
85
- onChangeMode={vi.fn()}
86
- renderViewer={renderViewer}
87
- renderEditor={renderEditor}
88
- renderEditButton={renderEditButton}
89
- />
90
- )
91
- const viewModeText = screen.getByText(VIEWER_TEXT)
92
- const editButton = screen.getByRole('button')
93
-
94
- expect(viewModeText).toBeInTheDocument()
95
- expect(editButton).toBeInTheDocument()
96
- expect(editButton).toHaveTextContent(EDIT_BUTTON_TEXT)
97
- })
98
-
99
- it('should render view mode with string button label', () => {
100
- const { container } = render(
101
- <InPlaceEdit
102
- mode="view"
103
- onChangeMode={vi.fn()}
104
- renderViewer={renderViewer}
105
- renderEditor={renderEditor}
106
- renderEditButton={renderEditButton}
107
- />
108
- )
109
- const viewModeText = screen.getByText(VIEWER_TEXT)
110
- const editButton = screen.getByRole('button')
111
- const buttonLabel = container.querySelector(
112
- "[class$='-screenReaderContent']"
113
- ) as HTMLElement
114
-
115
- expect(viewModeText).toBeInTheDocument()
116
- expect(editButton).toBeInTheDocument()
117
- expect(editButton).toContainElement(buttonLabel!)
118
- expect(buttonLabel).toHaveTextContent(EDIT_BUTTON_TEXT)
119
- })
120
-
121
- it('should render edit mode', () => {
122
- render(
123
- <InPlaceEdit
124
- mode="edit"
125
- onChangeMode={vi.fn()}
126
- renderViewer={renderViewer}
127
- renderEditor={renderEditor}
128
- renderEditButton={renderEditButton}
129
- />
130
- )
131
- const inputForEdit = screen.getByTestId('input-editor')
132
-
133
- expect(inputForEdit).toBeInTheDocument()
134
- expect(document.activeElement).toBe(inputForEdit)
135
- })
136
-
137
- it('should render a custom edit button', () => {
138
- const customButtonText = 'custom-button-text'
139
- render(
140
- <InPlaceEdit
141
- mode="view"
142
- onChangeMode={vi.fn()}
143
- renderViewer={renderViewer}
144
- renderEditor={renderEditor}
145
- renderEditButton={() => {
146
- return <button data-testid="custom_button">{customButtonText}</button>
147
- }}
148
- />
149
- )
150
- const viewModeText = screen.getByText(VIEWER_TEXT)
151
- const customEditButton = screen.getByTestId('custom_button')
152
-
153
- expect(viewModeText).toBeInTheDocument()
154
- expect(customEditButton).toBeInTheDocument()
155
- expect(customEditButton).toHaveTextContent(customButtonText)
156
- })
157
-
158
- it('should switch mode to edit via props, and focus the editor', () => {
159
- const { rerender, container } = render(
160
- <InPlaceEdit
161
- mode="view"
162
- onChangeMode={vi.fn()}
163
- renderViewer={renderViewer}
164
- renderEditor={renderEditor}
165
- renderEditButton={renderEditButton}
166
- />
167
- )
168
- const viewModeText = screen.getByText(VIEWER_TEXT)
169
- expect(viewModeText).toBeInTheDocument()
170
-
171
- // Simulate mode prop change
172
- rerender(
173
- <InPlaceEdit
174
- mode="edit"
175
- onChangeMode={vi.fn()}
176
- renderViewer={renderViewer}
177
- renderEditor={renderEditor}
178
- renderEditButton={renderEditButton}
179
- />
180
- )
181
- const inputForEdit = screen.getByTestId('input-editor')
182
-
183
- expect(container).not.toHaveTextContent(VIEWER_TEXT)
184
- expect(inputForEdit).toBeInTheDocument()
185
- expect(document.activeElement).toBe(inputForEdit)
186
- })
187
-
188
- it('should switch mode to view via props, and focus the edit button', () => {
189
- const { rerender, container } = render(
190
- <InPlaceEdit
191
- mode="edit"
192
- onChangeMode={vi.fn()}
193
- renderViewer={renderViewer}
194
- renderEditor={renderEditor}
195
- renderEditButton={renderEditButton}
196
- />
197
- )
198
- const inputForEdit = screen.getByTestId('input-editor')
199
-
200
- expect(container).not.toHaveTextContent(VIEWER_TEXT)
201
- expect(inputForEdit).toBeInTheDocument()
202
-
203
- // Simulate mode prop change
204
- rerender(
205
- <InPlaceEdit
206
- mode="view"
207
- onChangeMode={vi.fn()}
208
- renderViewer={renderViewer}
209
- renderEditor={renderEditor}
210
- renderEditButton={renderEditButton}
211
- />
212
- )
213
- const inputForEditAfterModeChange = container.querySelector(
214
- "[id='input-editor']"
215
- )
216
- const editButton = screen.getByRole('button')
217
-
218
- expect(container).toHaveTextContent(VIEWER_TEXT)
219
- expect(inputForEditAfterModeChange).not.toBeInTheDocument()
220
- expect(editButton).toBeInTheDocument()
221
- expect(editButton).toHaveTextContent(EDIT_BUTTON_TEXT)
222
- expect(document.activeElement).toBe(editButton)
223
- })
224
-
225
- it('should meet a11y standards in view mode', async () => {
226
- const { container } = render(
227
- <InPlaceEdit
228
- mode="view"
229
- onChangeMode={vi.fn()}
230
- renderViewer={renderViewer}
231
- renderEditor={renderEditor}
232
- renderEditButton={renderEditButton}
233
- />
234
- )
235
- const axeCheck = await runAxeCheck(container)
236
-
237
- expect(axeCheck).toBe(true)
238
- })
239
-
240
- it('should meet a11y standards in edit mode', async () => {
241
- const { container } = render(
242
- <InPlaceEdit
243
- mode="edit"
244
- onChangeMode={vi.fn()}
245
- renderViewer={renderViewer}
246
- renderEditor={renderEditor}
247
- renderEditButton={renderEditButton}
248
- />
249
- )
250
- const axeCheck = await runAxeCheck(container)
251
-
252
- expect(axeCheck).toBe(true)
253
- })
254
- })
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=Editable.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Editable.test.d.ts","sourceRoot":"","sources":["../../../src/Editable/__new-tests__/Editable.test.tsx"],"names":[],"mappings":"AA4BA,OAAO,2BAA2B,CAAA"}
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=InPlaceEdit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InPlaceEdit.test.d.ts","sourceRoot":"","sources":["../../../src/InPlaceEdit/__new-tests__/InPlaceEdit.test.tsx"],"names":[],"mappings":"AA0BA,OAAO,2BAA2B,CAAA"}