-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMultiInputComponent.stories.tsx
More file actions
141 lines (134 loc) · 4.98 KB
/
MultiInputComponent.stories.tsx
File metadata and controls
141 lines (134 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import type { Meta, StoryObj } from '@storybook/react-vite';
import React, { useState } from 'react';
import { fn } from 'storybook/test';
import { http, HttpResponse } from 'msw';
import MultiInputComponent from '../MultiInputComponent';
import { getGlobalConfigMock } from '../../../mocks/globalConfigMock';
import { setUnifiedConfig } from '../../../util/util';
import { getMockServerResponseForInput } from '../../../mocks/server-response';
import { withControlGroup } from '../../../../.storybook/withControlGroup';
const meta = {
component: MultiInputComponent,
title: 'MultiInputComponent',
render: (props) => {
// due to stories incompatibility, eslint rule is off
// React Hook "useState" is called in function "render" that is neither a React function component
// TODO: introduce a stateless stories component to reflect thaat component logic itself
const mockConfig = getGlobalConfigMock();
setUnifiedConfig(mockConfig);
const [state, setState] = useState(props?.value || ''); // eslint-disable-line react-hooks/rules-of-hooks
return (
<MultiInputComponent
{...props}
value={state}
handleChange={(field, data) => {
setState(data);
props.handleChange(field, data);
}}
/>
);
},
decorators: [withControlGroup],
} satisfies Meta<typeof MultiInputComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Base: Story = {
args: {
handleChange: fn(),
field: 'field',
controlOptions: {
items: [
{ label: 'label1', value: 'value1' },
{ label: 'label2', value: 'value2' },
{ label: 'label3', value: 'value3' },
],
},
},
};
export const AllProps: Story = {
args: {
handleChange: fn(),
field: 'field',
controlOptions: {
delimiter: ',',
createSearchChoice: true,
referenceName: 'referenceName',
dependencies: undefined,
endpointUrl: undefined,
denyList: 'value1',
allowList: 'string',
labelField: 'labelField',
items: [
{ label: 'label1', value: 'value1' },
{ label: 'label2', value: 'value2' },
{ label: 'label3', value: 'value3' },
],
},
disabled: false,
value: undefined,
dependencyValues: {},
},
};
export const EndpointApi: Story = {
args: {
handleChange: fn(),
field: 'field',
controlOptions: {
delimiter: ',',
createSearchChoice: true,
dependencies: undefined,
denyList: undefined,
allowList: undefined,
labelField: 'testLabel',
valueField: 'testValue',
endpointUrl: '/demo_addon_for_splunk/some_API_endpint_for_select_data',
},
disabled: false,
value: undefined,
dependencyValues: {},
},
parameters: {
msw: {
handlers: [
http.get('demo_addon_for_splunk/some_API_endpint_for_select_data', () =>
HttpResponse.json(
getMockServerResponseForInput([
{
name: 'dataFromApiTest1',
content: { testLabel: 'aaa1', testValue: 'bbb1' },
},
{
name: 'dataFromApiTest2',
content: { testLabel: 'aaa2', testValue: 'bbb2' },
},
{
name: 'dataFromApiTest3',
content: { testLabel: 'aaa3', testValue: 'bbb3' },
},
{
name: 'dataFromApiTest4',
content: { testLabel: 'aaa4', testValue: 'bbb4' },
},
{
name: 'd1',
content: { testLabel: 'firstLabel', testValue: 'firstValue' },
},
{
name: 'd2',
content: { testLabel: 'secondLabel', testValue: 'secondValue' },
},
{
name: 'd3',
content: { testLabel: 'thirdLabel', testValue: 'thirdValue' },
},
{
name: 'd4',
content: { testLabel: 'fourthLabel', testValue: 'fourthValue' },
},
])
)
),
],
},
},
};