@onewelcome/react-lib-components 0.2.2 → 0.2.3
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/dist/react-lib-components.cjs.development.js +5 -3
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +5 -3
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/ContextMenu/ContextMenu.test.tsx +16 -0
- package/src/ContextMenu/ContextMenu.tsx +5 -1
- package/src/ContextMenu/ContextMenuItem.tsx +3 -1
- package/src/Form/Input/Input.test.tsx +63 -42
package/package.json
CHANGED
|
@@ -72,6 +72,22 @@ describe("ContextMenu should render", () => {
|
|
|
72
72
|
expect(onClick).toHaveBeenCalled();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
it("passes custom class to ContextMenuItem", () => {
|
|
76
|
+
const { getByRole } = createContextMenu(defaultParams => ({
|
|
77
|
+
...defaultParams,
|
|
78
|
+
show: true,
|
|
79
|
+
children: [
|
|
80
|
+
<ContextMenuItem data-testid="contextmenuitem" key="1" className="custom">
|
|
81
|
+
Item 1
|
|
82
|
+
</ContextMenuItem>
|
|
83
|
+
]
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
const child = getByRole("menuitem");
|
|
87
|
+
|
|
88
|
+
expect(child).toHaveClass("custom");
|
|
89
|
+
});
|
|
90
|
+
|
|
75
91
|
it("should throw an error", () => {
|
|
76
92
|
// Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
|
|
77
93
|
const err = console.error;
|
|
@@ -121,7 +121,11 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
121
121
|
|
|
122
122
|
useBodyClick(
|
|
123
123
|
event => {
|
|
124
|
-
return
|
|
124
|
+
return (
|
|
125
|
+
showContextMenu &&
|
|
126
|
+
anchorEl.current !== event.target &&
|
|
127
|
+
anchorEl.current !== (event.target as HTMLElement).parentElement
|
|
128
|
+
);
|
|
125
129
|
},
|
|
126
130
|
() => {
|
|
127
131
|
setShowContextMenu(false);
|
|
@@ -25,6 +25,7 @@ export const ContextMenuItem = React.forwardRef<HTMLButtonElement, Props>(
|
|
|
25
25
|
childIndex,
|
|
26
26
|
contextMenuOpened,
|
|
27
27
|
shouldClick,
|
|
28
|
+
className,
|
|
28
29
|
...rest
|
|
29
30
|
}: Props,
|
|
30
31
|
ref
|
|
@@ -45,11 +46,12 @@ export const ContextMenuItem = React.forwardRef<HTMLButtonElement, Props>(
|
|
|
45
46
|
}, [hasFocus, innerButtonRef, contextMenuOpened]);
|
|
46
47
|
|
|
47
48
|
return (
|
|
48
|
-
<li role="menuitem" className={classes["context-menu-item"]}>
|
|
49
|
+
<li role="menuitem" className={`${classes["context-menu-item"]} ${className ?? ""}`}>
|
|
49
50
|
<button
|
|
50
51
|
{...rest}
|
|
51
52
|
ref={innerButtonRef}
|
|
52
53
|
data-focus={hasFocus}
|
|
54
|
+
tabIndex={-1}
|
|
53
55
|
onClick={event => {
|
|
54
56
|
onClick && onClick(event);
|
|
55
57
|
onSelectedChange && childIndex && onSelectedChange(childIndex);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from "react";
|
|
2
|
-
import { Input, Props } from "./Input";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
1
|
+
import React, { useEffect, useRef, useState, Fragment } from "react";
|
|
2
|
+
import { Input, Props, Type } from "./Input";
|
|
3
|
+
import { fireEvent, render } from "@testing-library/react";
|
|
4
4
|
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { Label } from "../Label/Label";
|
|
5
6
|
|
|
6
7
|
const defaultParams: Props = {
|
|
7
8
|
name: "input",
|
|
@@ -22,6 +23,35 @@ const createInput = (params?: (defaultParams: Props) => Props) => {
|
|
|
22
23
|
};
|
|
23
24
|
};
|
|
24
25
|
|
|
26
|
+
const CreateInputComponent = ({
|
|
27
|
+
onValueChange,
|
|
28
|
+
type
|
|
29
|
+
}: {
|
|
30
|
+
onValueChange: (value: string) => void;
|
|
31
|
+
type: Type;
|
|
32
|
+
}) => {
|
|
33
|
+
const [inputValue, setInputValue] = useState("");
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (inputValue !== "") {
|
|
37
|
+
onValueChange(inputValue);
|
|
38
|
+
}
|
|
39
|
+
}, [inputValue]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Fragment>
|
|
43
|
+
<Label htmlFor="sample-input">Test</Label>
|
|
44
|
+
<Input
|
|
45
|
+
name="sample_input"
|
|
46
|
+
type={type}
|
|
47
|
+
id="sample-input"
|
|
48
|
+
value={inputValue}
|
|
49
|
+
onChange={e => setInputValue(e.target.value)}
|
|
50
|
+
/>
|
|
51
|
+
</Fragment>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
25
55
|
describe("Input should render", () => {
|
|
26
56
|
it("renders without crashing and has a name and type", () => {
|
|
27
57
|
const { input } = createInput();
|
|
@@ -69,29 +99,32 @@ describe("Should have the appropriate attributes", () => {
|
|
|
69
99
|
});
|
|
70
100
|
|
|
71
101
|
describe("Should render all different types of inputs", () => {
|
|
72
|
-
it(
|
|
73
|
-
|
|
102
|
+
it.each([
|
|
103
|
+
["text", "testing", "testing"],
|
|
104
|
+
["email", "testing@testing.com", "testing@testing.com"],
|
|
105
|
+
["tel", "06123456789", "06123456789"],
|
|
106
|
+
["number", "1234567890", "1234567890"],
|
|
107
|
+
["search", "example", "example"],
|
|
108
|
+
["time", "1234", "12:34"],
|
|
109
|
+
["url", "https://www.onewelcome.com", "https://www.onewelcome.com"]
|
|
110
|
+
])(
|
|
111
|
+
"renders a %p input with %p as a value",
|
|
112
|
+
async (type: string, value: string, result: string) => {
|
|
113
|
+
let changedValue = "";
|
|
74
114
|
|
|
75
|
-
|
|
76
|
-
|
|
115
|
+
const { findByLabelText } = render(
|
|
116
|
+
<CreateInputComponent type={type as Type} onValueChange={value => (changedValue = value)} />
|
|
117
|
+
);
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "email" }));
|
|
119
|
+
const input = await findByLabelText(/Test/);
|
|
80
120
|
|
|
81
|
-
|
|
82
|
-
});
|
|
121
|
+
input.focus();
|
|
83
122
|
|
|
84
|
-
|
|
85
|
-
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "tel" }));
|
|
123
|
+
userEvent.keyboard(value);
|
|
86
124
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
it("should render a number input", () => {
|
|
91
|
-
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "number" }));
|
|
92
|
-
|
|
93
|
-
expect(input).toHaveAttribute("type", "number");
|
|
94
|
-
});
|
|
125
|
+
expect(changedValue).toBe(result);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
95
128
|
|
|
96
129
|
it("should render a password input", () => {
|
|
97
130
|
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "password" }));
|
|
@@ -99,31 +132,19 @@ describe("Should render all different types of inputs", () => {
|
|
|
99
132
|
expect(input).toHaveAttribute("type", "password");
|
|
100
133
|
});
|
|
101
134
|
|
|
102
|
-
it("should render a
|
|
103
|
-
|
|
135
|
+
it("should render a datetime input", async () => {
|
|
136
|
+
let changedValue = "";
|
|
104
137
|
|
|
105
|
-
|
|
106
|
-
|
|
138
|
+
const { findByLabelText } = render(
|
|
139
|
+
<CreateInputComponent type="datetime-local" onValueChange={value => (changedValue = value)} />
|
|
140
|
+
);
|
|
107
141
|
|
|
108
|
-
|
|
109
|
-
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "time" }));
|
|
142
|
+
const input = await findByLabelText(/Test/);
|
|
110
143
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
it("should render a url input", () => {
|
|
115
|
-
const { input } = createInput(defaultParams => ({ ...defaultParams, type: "url" }));
|
|
116
|
-
|
|
117
|
-
expect(input).toHaveAttribute("type", "url");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should render a datetime input", () => {
|
|
121
|
-
const { input } = createInput(defaultParams => ({
|
|
122
|
-
...defaultParams,
|
|
123
|
-
type: "datetime-local"
|
|
124
|
-
}));
|
|
144
|
+
const testValue = "2019-03-29T12:34";
|
|
145
|
+
fireEvent.change(input, { target: { value: testValue } });
|
|
125
146
|
|
|
126
|
-
expect(
|
|
147
|
+
expect(changedValue).toBe(testValue);
|
|
127
148
|
});
|
|
128
149
|
|
|
129
150
|
it("should be hidden", () => {
|