@instructure/ui-editable 10.16.1-snapshot-0 → 10.16.1
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.
- package/CHANGELOG.md +1 -1
- package/es/Editable/__new-tests__/Editable.test.js +28 -21
- package/es/InPlaceEdit/__new-tests__/InPlaceEdit.test.js +19 -16
- package/es/InPlaceEdit/index.js +27 -20
- package/lib/Editable/__new-tests__/Editable.test.js +50 -43
- package/lib/InPlaceEdit/__new-tests__/InPlaceEdit.test.js +31 -29
- package/lib/InPlaceEdit/index.js +26 -19
- package/package.json +14 -14
- package/src/Editable/__new-tests__/Editable.test.tsx +0 -1
- package/src/Editable/index.tsx +1 -1
- package/src/InPlaceEdit/__new-tests__/InPlaceEdit.test.tsx +0 -1
- package/src/InPlaceEdit/index.tsx +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Editable/__new-tests__/Editable.test.d.ts.map +1 -1
- package/types/Editable/index.d.ts +2 -2
- package/types/Editable/index.d.ts.map +1 -1
- package/types/InPlaceEdit/__new-tests__/InPlaceEdit.test.d.ts.map +1 -1
- package/types/InPlaceEdit/index.d.ts +4 -6
- package/types/InPlaceEdit/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [10.16.1
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-editable
|
|
9
9
|
|
|
@@ -24,12 +24,12 @@ const _excluded = ["isVisible", "buttonRef"];
|
|
|
24
24
|
* SOFTWARE.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import React from 'react';
|
|
28
27
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
29
28
|
import { vi } from 'vitest';
|
|
30
29
|
import userEvent from '@testing-library/user-event';
|
|
31
30
|
import '@testing-library/jest-dom';
|
|
32
31
|
import { Editable } from '../index';
|
|
32
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
33
33
|
const TEXT_VIEW = 'text-view';
|
|
34
34
|
const TEXT_EDIT = 'text-edit';
|
|
35
35
|
const childRender = vi.fn(({
|
|
@@ -46,16 +46,23 @@ const childRender = vi.fn(({
|
|
|
46
46
|
const _getEditorProps = getEditorProps(),
|
|
47
47
|
onBlur = _getEditorProps.onBlur,
|
|
48
48
|
editorRef = _getEditorProps.editorRef;
|
|
49
|
-
return
|
|
50
|
-
"data-testid": "child-container"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
return _jsxs("div", {
|
|
50
|
+
"data-testid": "child-container",
|
|
51
|
+
...getContainerProps(),
|
|
52
|
+
children: [mode === 'view' && _jsx("div", {
|
|
53
|
+
...getViewerProps(),
|
|
54
|
+
children: TEXT_VIEW
|
|
55
|
+
}), mode === 'edit' && _jsx("input", {
|
|
56
|
+
ref: editorRef,
|
|
57
|
+
onBlur: onBlur,
|
|
58
|
+
defaultValue: "textvalue",
|
|
59
|
+
"data-testid": "edit-mode-input"
|
|
60
|
+
}), _jsx("button", {
|
|
61
|
+
...buttonProps,
|
|
62
|
+
className: isVisible ? 'test-visible' : 'test-hidden',
|
|
63
|
+
children: TEXT_EDIT
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
59
66
|
});
|
|
60
67
|
describe('<Editable />', () => {
|
|
61
68
|
let consoleWarningMock;
|
|
@@ -71,7 +78,7 @@ describe('<Editable />', () => {
|
|
|
71
78
|
childRender.mockClear();
|
|
72
79
|
});
|
|
73
80
|
it('should render view mode', async () => {
|
|
74
|
-
render(
|
|
81
|
+
render(_jsx(Editable, {
|
|
75
82
|
mode: "view",
|
|
76
83
|
onChangeMode: vi.fn(),
|
|
77
84
|
render: childRender
|
|
@@ -87,7 +94,7 @@ describe('<Editable />', () => {
|
|
|
87
94
|
expect(editButton).toBeInTheDocument();
|
|
88
95
|
});
|
|
89
96
|
it('should render edit mode', async () => {
|
|
90
|
-
render(
|
|
97
|
+
render(_jsx(Editable, {
|
|
91
98
|
mode: "edit",
|
|
92
99
|
onChangeMode: vi.fn(),
|
|
93
100
|
render: childRender
|
|
@@ -104,7 +111,7 @@ describe('<Editable />', () => {
|
|
|
104
111
|
});
|
|
105
112
|
it('should change to edit mode on button click', () => {
|
|
106
113
|
const onChangeModeSpy = vi.fn();
|
|
107
|
-
render(
|
|
114
|
+
render(_jsx(Editable, {
|
|
108
115
|
mode: "view",
|
|
109
116
|
onChangeMode: onChangeModeSpy,
|
|
110
117
|
render: childRender
|
|
@@ -117,7 +124,7 @@ describe('<Editable />', () => {
|
|
|
117
124
|
});
|
|
118
125
|
it('should change to edit mode on component click', async () => {
|
|
119
126
|
const onChangeModeSpy = vi.fn();
|
|
120
|
-
render(
|
|
127
|
+
render(_jsx(Editable, {
|
|
121
128
|
mode: "view",
|
|
122
129
|
onChangeMode: onChangeModeSpy,
|
|
123
130
|
render: childRender
|
|
@@ -128,7 +135,7 @@ describe('<Editable />', () => {
|
|
|
128
135
|
});
|
|
129
136
|
it('should set the button to visible on mouse over', async () => {
|
|
130
137
|
const onChangeModeSpy = vi.fn();
|
|
131
|
-
render(
|
|
138
|
+
render(_jsx(Editable, {
|
|
132
139
|
mode: "view",
|
|
133
140
|
onChangeMode: onChangeModeSpy,
|
|
134
141
|
render: childRender
|
|
@@ -146,7 +153,7 @@ describe('<Editable />', () => {
|
|
|
146
153
|
});
|
|
147
154
|
it('should change to view mode on editor blur', () => {
|
|
148
155
|
const onChangeModeSpy = vi.fn();
|
|
149
|
-
render(
|
|
156
|
+
render(_jsx(Editable, {
|
|
150
157
|
mode: "edit",
|
|
151
158
|
onChangeMode: onChangeModeSpy,
|
|
152
159
|
render: childRender
|
|
@@ -158,7 +165,7 @@ describe('<Editable />', () => {
|
|
|
158
165
|
});
|
|
159
166
|
it('should change to view mode on escape', () => {
|
|
160
167
|
const onChangeModeSpy = vi.fn();
|
|
161
|
-
render(
|
|
168
|
+
render(_jsx(Editable, {
|
|
162
169
|
mode: "edit",
|
|
163
170
|
onChangeMode: onChangeModeSpy,
|
|
164
171
|
render: childRender
|
|
@@ -172,7 +179,7 @@ describe('<Editable />', () => {
|
|
|
172
179
|
});
|
|
173
180
|
it('should call onChange when the user is finished editing', () => {
|
|
174
181
|
const onChangeSpy = vi.fn();
|
|
175
|
-
const _render = render(
|
|
182
|
+
const _render = render(_jsx(Editable, {
|
|
176
183
|
mode: "edit",
|
|
177
184
|
onChangeMode: vi.fn(),
|
|
178
185
|
render: childRender,
|
|
@@ -189,7 +196,7 @@ describe('<Editable />', () => {
|
|
|
189
196
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
|
190
197
|
|
|
191
198
|
// Simulate mode prop change
|
|
192
|
-
rerender(
|
|
199
|
+
rerender(_jsx(Editable, {
|
|
193
200
|
mode: "view",
|
|
194
201
|
onChangeMode: vi.fn(),
|
|
195
202
|
render: childRender,
|
|
@@ -200,7 +207,7 @@ describe('<Editable />', () => {
|
|
|
200
207
|
});
|
|
201
208
|
it('should warn if readOnly + mode="edit"', () => {
|
|
202
209
|
const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
203
|
-
render(
|
|
210
|
+
render(_jsx(Editable, {
|
|
204
211
|
mode: "edit",
|
|
205
212
|
onChangeMode: vi.fn(),
|
|
206
213
|
render: childRender,
|
|
@@ -23,20 +23,22 @@ var _div;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen } from '@testing-library/react';
|
|
28
27
|
import { vi } from 'vitest';
|
|
29
28
|
import '@testing-library/jest-dom';
|
|
30
29
|
import { InPlaceEdit } from '../index';
|
|
31
30
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
31
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
32
|
const VIEWER_TEXT = 'viewer-text';
|
|
33
33
|
const EDIT_BUTTON_TEXT = 'edit-button-text';
|
|
34
|
-
const renderViewer = () => _div || (_div =
|
|
34
|
+
const renderViewer = () => _div || (_div = _jsx("div", {
|
|
35
|
+
children: VIEWER_TEXT
|
|
36
|
+
}));
|
|
35
37
|
const renderEditor = ({
|
|
36
38
|
editorRef,
|
|
37
39
|
onBlur
|
|
38
40
|
}) => {
|
|
39
|
-
return
|
|
41
|
+
return _jsx("input", {
|
|
40
42
|
"data-testid": "input-editor",
|
|
41
43
|
ref: editorRef,
|
|
42
44
|
onBlur: onBlur,
|
|
@@ -76,7 +78,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
76
78
|
consoleErrorMock.mockRestore();
|
|
77
79
|
});
|
|
78
80
|
it('should render view mode', () => {
|
|
79
|
-
render(
|
|
81
|
+
render(_jsx(InPlaceEdit, {
|
|
80
82
|
mode: "view",
|
|
81
83
|
onChangeMode: vi.fn(),
|
|
82
84
|
renderViewer: renderViewer,
|
|
@@ -90,7 +92,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
90
92
|
expect(editButton).toHaveTextContent(EDIT_BUTTON_TEXT);
|
|
91
93
|
});
|
|
92
94
|
it('should render view mode with string button label', () => {
|
|
93
|
-
const _render = render(
|
|
95
|
+
const _render = render(_jsx(InPlaceEdit, {
|
|
94
96
|
mode: "view",
|
|
95
97
|
onChangeMode: vi.fn(),
|
|
96
98
|
renderViewer: renderViewer,
|
|
@@ -107,7 +109,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
107
109
|
expect(buttonLabel).toHaveTextContent(EDIT_BUTTON_TEXT);
|
|
108
110
|
});
|
|
109
111
|
it('should render edit mode', () => {
|
|
110
|
-
render(
|
|
112
|
+
render(_jsx(InPlaceEdit, {
|
|
111
113
|
mode: "edit",
|
|
112
114
|
onChangeMode: vi.fn(),
|
|
113
115
|
renderViewer: renderViewer,
|
|
@@ -121,15 +123,16 @@ describe('<InPlaceEdit />', () => {
|
|
|
121
123
|
it('should render a custom edit button', () => {
|
|
122
124
|
var _button;
|
|
123
125
|
const customButtonText = 'custom-button-text';
|
|
124
|
-
render(
|
|
126
|
+
render(_jsx(InPlaceEdit, {
|
|
125
127
|
mode: "view",
|
|
126
128
|
onChangeMode: vi.fn(),
|
|
127
129
|
renderViewer: renderViewer,
|
|
128
130
|
renderEditor: renderEditor,
|
|
129
131
|
renderEditButton: () => {
|
|
130
|
-
return _button || (_button =
|
|
131
|
-
"data-testid": "custom_button"
|
|
132
|
-
|
|
132
|
+
return _button || (_button = _jsx("button", {
|
|
133
|
+
"data-testid": "custom_button",
|
|
134
|
+
children: customButtonText
|
|
135
|
+
}));
|
|
133
136
|
}
|
|
134
137
|
}));
|
|
135
138
|
const viewModeText = screen.getByText(VIEWER_TEXT);
|
|
@@ -139,7 +142,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
139
142
|
expect(customEditButton).toHaveTextContent(customButtonText);
|
|
140
143
|
});
|
|
141
144
|
it('should switch mode to edit via props, and focus the editor', () => {
|
|
142
|
-
const _render2 = render(
|
|
145
|
+
const _render2 = render(_jsx(InPlaceEdit, {
|
|
143
146
|
mode: "view",
|
|
144
147
|
onChangeMode: vi.fn(),
|
|
145
148
|
renderViewer: renderViewer,
|
|
@@ -152,7 +155,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
152
155
|
expect(viewModeText).toBeInTheDocument();
|
|
153
156
|
|
|
154
157
|
// Simulate mode prop change
|
|
155
|
-
rerender(
|
|
158
|
+
rerender(_jsx(InPlaceEdit, {
|
|
156
159
|
mode: "edit",
|
|
157
160
|
onChangeMode: vi.fn(),
|
|
158
161
|
renderViewer: renderViewer,
|
|
@@ -165,7 +168,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
165
168
|
expect(document.activeElement).toBe(inputForEdit);
|
|
166
169
|
});
|
|
167
170
|
it('should switch mode to view via props, and focus the edit button', () => {
|
|
168
|
-
const _render3 = render(
|
|
171
|
+
const _render3 = render(_jsx(InPlaceEdit, {
|
|
169
172
|
mode: "edit",
|
|
170
173
|
onChangeMode: vi.fn(),
|
|
171
174
|
renderViewer: renderViewer,
|
|
@@ -179,7 +182,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
179
182
|
expect(inputForEdit).toBeInTheDocument();
|
|
180
183
|
|
|
181
184
|
// Simulate mode prop change
|
|
182
|
-
rerender(
|
|
185
|
+
rerender(_jsx(InPlaceEdit, {
|
|
183
186
|
mode: "view",
|
|
184
187
|
onChangeMode: vi.fn(),
|
|
185
188
|
renderViewer: renderViewer,
|
|
@@ -195,7 +198,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
195
198
|
expect(document.activeElement).toBe(editButton);
|
|
196
199
|
});
|
|
197
200
|
it('should meet a11y standards in view mode', async () => {
|
|
198
|
-
const _render4 = render(
|
|
201
|
+
const _render4 = render(_jsx(InPlaceEdit, {
|
|
199
202
|
mode: "view",
|
|
200
203
|
onChangeMode: vi.fn(),
|
|
201
204
|
renderViewer: renderViewer,
|
|
@@ -207,7 +210,7 @@ describe('<InPlaceEdit />', () => {
|
|
|
207
210
|
expect(axeCheck).toBe(true);
|
|
208
211
|
});
|
|
209
212
|
it('should meet a11y standards in edit mode', async () => {
|
|
210
|
-
const _render5 = render(
|
|
213
|
+
const _render5 = render(_jsx(InPlaceEdit, {
|
|
211
214
|
mode: "edit",
|
|
212
215
|
onChangeMode: vi.fn(),
|
|
213
216
|
renderViewer: renderViewer,
|
package/es/InPlaceEdit/index.js
CHANGED
|
@@ -23,18 +23,18 @@ var _dec, _class, _InPlaceEdit;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
/** @jsx jsx */
|
|
27
26
|
import { Component } from 'react';
|
|
28
27
|
import { Flex } from '@instructure/ui-flex';
|
|
29
28
|
import { IconButton } from '@instructure/ui-buttons';
|
|
30
29
|
import { IconEditLine } from '@instructure/ui-icons';
|
|
31
30
|
import { logWarn as warn } from '@instructure/console';
|
|
32
31
|
import { createChainedFunction } from '@instructure/ui-utils';
|
|
33
|
-
import { withStyle
|
|
32
|
+
import { withStyle } from '@instructure/emotion';
|
|
34
33
|
import { View } from '@instructure/ui-view';
|
|
35
34
|
import { Editable } from '../Editable';
|
|
36
35
|
import generateStyle from './styles';
|
|
37
36
|
import { propTypes, allowedProps } from './props';
|
|
37
|
+
import { jsxs as _jsxs, jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
38
38
|
/**
|
|
39
39
|
---
|
|
40
40
|
category: components
|
|
@@ -60,16 +60,20 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
60
60
|
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
61
61
|
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
62
62
|
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
63
|
-
return
|
|
63
|
+
return _jsxs(Flex, {
|
|
64
64
|
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
65
65
|
direction: flexDir,
|
|
66
|
-
justifyItems: justifyItems
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
justifyItems: justifyItems,
|
|
67
|
+
...getContainerProps(),
|
|
68
|
+
children: [_jsxs(Flex.Item, {
|
|
69
|
+
shouldGrow: true,
|
|
70
|
+
shouldShrink: true,
|
|
71
|
+
children: [this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())]
|
|
72
|
+
}), _jsx(Flex.Item, {
|
|
73
|
+
margin: buttonMargin,
|
|
74
|
+
children: this.renderEditButton(getEditButtonProps())
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
73
77
|
};
|
|
74
78
|
warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
75
79
|
}
|
|
@@ -92,18 +96,19 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
92
96
|
showFocusRing = _this$props3.showFocusRing,
|
|
93
97
|
renderEditor = _this$props3.renderEditor;
|
|
94
98
|
const isEditMode = !readOnly && mode === 'edit';
|
|
95
|
-
return isEditMode ?
|
|
99
|
+
return isEditMode ? _jsx(View, {
|
|
96
100
|
as: "span",
|
|
97
101
|
display: "block",
|
|
98
102
|
withFocusOutline: showFocusRing,
|
|
99
103
|
position: "relative",
|
|
100
104
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.inPlaceEdit,
|
|
101
105
|
borderRadius: "medium",
|
|
102
|
-
margin: "auto"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
margin: "auto",
|
|
107
|
+
children: renderEditor({
|
|
108
|
+
onBlur,
|
|
109
|
+
editorRef
|
|
110
|
+
})
|
|
111
|
+
}) : null;
|
|
107
112
|
}
|
|
108
113
|
renderViewer({
|
|
109
114
|
readOnly,
|
|
@@ -131,7 +136,7 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
131
136
|
onChange = _this$props4.onChange,
|
|
132
137
|
onChangeMode = _this$props4.onChangeMode,
|
|
133
138
|
readOnly = _this$props4.readOnly;
|
|
134
|
-
return
|
|
139
|
+
return _jsx(Editable, {
|
|
135
140
|
mode: mode,
|
|
136
141
|
onChangeMode: onChangeMode,
|
|
137
142
|
render: this.renderAll,
|
|
@@ -155,12 +160,14 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_InPlac
|
|
|
155
160
|
if (readOnly) {
|
|
156
161
|
return null;
|
|
157
162
|
}
|
|
158
|
-
return
|
|
163
|
+
return _jsx(IconButton, {
|
|
159
164
|
size: "small",
|
|
160
165
|
screenReaderLabel: label,
|
|
161
166
|
withBackground: false,
|
|
162
|
-
withBorder: false
|
|
163
|
-
|
|
167
|
+
withBorder: false,
|
|
168
|
+
...buttonProps,
|
|
169
|
+
children: isVisible ? IconEditLine : null
|
|
170
|
+
});
|
|
164
171
|
}, _InPlaceEdit)) || _class);
|
|
165
172
|
export default InPlaceEdit;
|
|
166
173
|
export { InPlaceEdit };
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
5
|
-
var _react =
|
|
6
|
-
var _react2 = require("@testing-library/react");
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
7
6
|
var _vitest = require("vitest");
|
|
8
7
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
9
8
|
require("@testing-library/jest-dom");
|
|
10
9
|
var _index = require("../index");
|
|
10
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
11
|
const _excluded = ["isVisible", "buttonRef"];
|
|
12
12
|
/*
|
|
13
13
|
* The MIT License (MIT)
|
|
@@ -48,16 +48,23 @@ const childRender = _vitest.vi.fn(({
|
|
|
48
48
|
const _getEditorProps = getEditorProps(),
|
|
49
49
|
onBlur = _getEditorProps.onBlur,
|
|
50
50
|
editorRef = _getEditorProps.editorRef;
|
|
51
|
-
return
|
|
52
|
-
"data-testid": "child-container"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
52
|
+
"data-testid": "child-container",
|
|
53
|
+
...getContainerProps(),
|
|
54
|
+
children: [mode === 'view' && (0, _jsxRuntime.jsx)("div", {
|
|
55
|
+
...getViewerProps(),
|
|
56
|
+
children: TEXT_VIEW
|
|
57
|
+
}), mode === 'edit' && (0, _jsxRuntime.jsx)("input", {
|
|
58
|
+
ref: editorRef,
|
|
59
|
+
onBlur: onBlur,
|
|
60
|
+
defaultValue: "textvalue",
|
|
61
|
+
"data-testid": "edit-mode-input"
|
|
62
|
+
}), (0, _jsxRuntime.jsx)("button", {
|
|
63
|
+
...buttonProps,
|
|
64
|
+
className: isVisible ? 'test-visible' : 'test-hidden',
|
|
65
|
+
children: TEXT_EDIT
|
|
66
|
+
})]
|
|
67
|
+
});
|
|
61
68
|
});
|
|
62
69
|
describe('<Editable />', () => {
|
|
63
70
|
let consoleWarningMock;
|
|
@@ -73,14 +80,14 @@ describe('<Editable />', () => {
|
|
|
73
80
|
childRender.mockClear();
|
|
74
81
|
});
|
|
75
82
|
it('should render view mode', async () => {
|
|
76
|
-
(0,
|
|
83
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
77
84
|
mode: "view",
|
|
78
85
|
onChangeMode: _vitest.vi.fn(),
|
|
79
86
|
render: childRender
|
|
80
87
|
}));
|
|
81
88
|
const currentMode = childRender.mock.calls[0][0].mode;
|
|
82
|
-
const viewModeText =
|
|
83
|
-
const editButton =
|
|
89
|
+
const viewModeText = _react.screen.getByText(TEXT_VIEW);
|
|
90
|
+
const editButton = _react.screen.getByRole('button', {
|
|
84
91
|
name: TEXT_EDIT
|
|
85
92
|
});
|
|
86
93
|
expect(childRender).toHaveBeenCalled();
|
|
@@ -89,14 +96,14 @@ describe('<Editable />', () => {
|
|
|
89
96
|
expect(editButton).toBeInTheDocument();
|
|
90
97
|
});
|
|
91
98
|
it('should render edit mode', async () => {
|
|
92
|
-
(0,
|
|
99
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
93
100
|
mode: "edit",
|
|
94
101
|
onChangeMode: _vitest.vi.fn(),
|
|
95
102
|
render: childRender
|
|
96
103
|
}));
|
|
97
104
|
const currentMode = childRender.mock.calls[0][0].mode;
|
|
98
|
-
const inputForEdit =
|
|
99
|
-
const editButton =
|
|
105
|
+
const inputForEdit = _react.screen.getByTestId('edit-mode-input');
|
|
106
|
+
const editButton = _react.screen.getByRole('button', {
|
|
100
107
|
name: TEXT_EDIT
|
|
101
108
|
});
|
|
102
109
|
expect(childRender).toHaveBeenCalled();
|
|
@@ -106,67 +113,67 @@ describe('<Editable />', () => {
|
|
|
106
113
|
});
|
|
107
114
|
it('should change to edit mode on button click', () => {
|
|
108
115
|
const onChangeModeSpy = _vitest.vi.fn();
|
|
109
|
-
(0,
|
|
116
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
110
117
|
mode: "view",
|
|
111
118
|
onChangeMode: onChangeModeSpy,
|
|
112
119
|
render: childRender
|
|
113
120
|
}));
|
|
114
|
-
const viewModeText =
|
|
115
|
-
const editButton =
|
|
121
|
+
const viewModeText = _react.screen.getByText(TEXT_VIEW);
|
|
122
|
+
const editButton = _react.screen.getByRole('button');
|
|
116
123
|
expect(viewModeText).toBeInTheDocument();
|
|
117
|
-
|
|
124
|
+
_react.fireEvent.click(editButton);
|
|
118
125
|
expect(onChangeModeSpy).toHaveBeenCalledWith('edit');
|
|
119
126
|
});
|
|
120
127
|
it('should change to edit mode on component click', async () => {
|
|
121
128
|
const onChangeModeSpy = _vitest.vi.fn();
|
|
122
|
-
(0,
|
|
129
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
123
130
|
mode: "view",
|
|
124
131
|
onChangeMode: onChangeModeSpy,
|
|
125
132
|
render: childRender
|
|
126
133
|
}));
|
|
127
|
-
const childContainer =
|
|
134
|
+
const childContainer = _react.screen.getByTestId('child-container');
|
|
128
135
|
_userEvent.default.click(childContainer);
|
|
129
|
-
await (0,
|
|
136
|
+
await (0, _react.waitFor)(() => expect(onChangeModeSpy).toHaveBeenCalledWith('edit'));
|
|
130
137
|
});
|
|
131
138
|
it('should set the button to visible on mouse over', async () => {
|
|
132
139
|
const onChangeModeSpy = _vitest.vi.fn();
|
|
133
|
-
(0,
|
|
140
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
134
141
|
mode: "view",
|
|
135
142
|
onChangeMode: onChangeModeSpy,
|
|
136
143
|
render: childRender
|
|
137
144
|
}));
|
|
138
|
-
const editButton =
|
|
145
|
+
const editButton = _react.screen.getByRole('button');
|
|
139
146
|
expect(editButton).toHaveClass('test-hidden');
|
|
140
|
-
|
|
141
|
-
await (0,
|
|
147
|
+
_react.fireEvent.mouseOver(editButton);
|
|
148
|
+
await (0, _react.waitFor)(() => {
|
|
142
149
|
expect(editButton).toHaveClass('test-visible');
|
|
143
150
|
});
|
|
144
|
-
|
|
145
|
-
await (0,
|
|
151
|
+
_react.fireEvent.mouseOut(editButton);
|
|
152
|
+
await (0, _react.waitFor)(() => {
|
|
146
153
|
expect(editButton).toHaveClass('test-hidden');
|
|
147
154
|
});
|
|
148
155
|
});
|
|
149
156
|
it('should change to view mode on editor blur', () => {
|
|
150
157
|
const onChangeModeSpy = _vitest.vi.fn();
|
|
151
|
-
(0,
|
|
158
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
152
159
|
mode: "edit",
|
|
153
160
|
onChangeMode: onChangeModeSpy,
|
|
154
161
|
render: childRender
|
|
155
162
|
}));
|
|
156
|
-
const inputForEdit =
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const inputForEdit = _react.screen.getByTestId('edit-mode-input');
|
|
164
|
+
_react.fireEvent.focus(inputForEdit);
|
|
165
|
+
_react.fireEvent.blur(inputForEdit);
|
|
159
166
|
expect(onChangeModeSpy).toHaveBeenCalledWith('view');
|
|
160
167
|
});
|
|
161
168
|
it('should change to view mode on escape', () => {
|
|
162
169
|
const onChangeModeSpy = _vitest.vi.fn();
|
|
163
|
-
(0,
|
|
170
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
164
171
|
mode: "edit",
|
|
165
172
|
onChangeMode: onChangeModeSpy,
|
|
166
173
|
render: childRender
|
|
167
174
|
}));
|
|
168
|
-
const inputForEdit =
|
|
169
|
-
|
|
175
|
+
const inputForEdit = _react.screen.getByTestId('edit-mode-input');
|
|
176
|
+
_react.fireEvent.keyUp(inputForEdit, {
|
|
170
177
|
key: 'Escape',
|
|
171
178
|
code: 'Escape'
|
|
172
179
|
});
|
|
@@ -174,7 +181,7 @@ describe('<Editable />', () => {
|
|
|
174
181
|
});
|
|
175
182
|
it('should call onChange when the user is finished editing', () => {
|
|
176
183
|
const onChangeSpy = _vitest.vi.fn();
|
|
177
|
-
const _render = (0,
|
|
184
|
+
const _render = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
178
185
|
mode: "edit",
|
|
179
186
|
onChangeMode: _vitest.vi.fn(),
|
|
180
187
|
render: childRender,
|
|
@@ -182,8 +189,8 @@ describe('<Editable />', () => {
|
|
|
182
189
|
onChange: onChangeSpy
|
|
183
190
|
})),
|
|
184
191
|
rerender = _render.rerender;
|
|
185
|
-
const inputForEdit =
|
|
186
|
-
|
|
192
|
+
const inputForEdit = _react.screen.getByTestId('edit-mode-input');
|
|
193
|
+
_react.fireEvent.change(inputForEdit, {
|
|
187
194
|
target: {
|
|
188
195
|
value: 'updated_value'
|
|
189
196
|
}
|
|
@@ -191,7 +198,7 @@ describe('<Editable />', () => {
|
|
|
191
198
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
|
192
199
|
|
|
193
200
|
// Simulate mode prop change
|
|
194
|
-
rerender(
|
|
201
|
+
rerender((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
195
202
|
mode: "view",
|
|
196
203
|
onChangeMode: _vitest.vi.fn(),
|
|
197
204
|
render: childRender,
|
|
@@ -202,7 +209,7 @@ describe('<Editable />', () => {
|
|
|
202
209
|
});
|
|
203
210
|
it('should warn if readOnly + mode="edit"', () => {
|
|
204
211
|
const consoleWarningSpy = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
205
|
-
(0,
|
|
212
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Editable, {
|
|
206
213
|
mode: "edit",
|
|
207
214
|
onChangeMode: _vitest.vi.fn(),
|
|
208
215
|
render: childRender,
|