@centreon/ui 26.7.1 → 26.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "26.7.1",
3
+ "version": "26.7.2",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -72,17 +72,19 @@ const DashboardTemplate = ({
72
72
  header,
73
73
  layout = dashboardLayout
74
74
  }: DashboardTemplateProps): ReactElement => (
75
- <DashboardLayout.Layout<CustomLayout> layout={layout}>
76
- {layout.map(({ i, content, shouldUseFluidTypography }) => (
77
- <DashboardLayout.Item header={header} id={i} key={i}>
78
- {shouldUseFluidTypography ? (
79
- <FluidTypography text={content} />
80
- ) : (
81
- <Typography>{content}</Typography>
82
- )}
83
- </DashboardLayout.Item>
84
- ))}
85
- </DashboardLayout.Layout>
75
+ <div className="h-150 overflow-y-auto">
76
+ <DashboardLayout.Layout<CustomLayout> layout={layout}>
77
+ {layout.map(({ i, content, shouldUseFluidTypography }) => (
78
+ <DashboardLayout.Item header={header} id={i} key={i}>
79
+ {shouldUseFluidTypography ? (
80
+ <FluidTypography text={content} />
81
+ ) : (
82
+ <Typography>{content}</Typography>
83
+ )}
84
+ </DashboardLayout.Item>
85
+ ))}
86
+ </DashboardLayout.Layout>
87
+ </div>
86
88
  );
87
89
 
88
90
  const meta: Meta<typeof DashboardTemplate> = {
@@ -36,6 +36,7 @@ const getEndpoint = ({ endpoint, parameters }): string =>
36
36
 
37
37
  const mockSearch = (page: number): object => ({
38
38
  delay: 1000,
39
+ headers: { 'Content-Type': 'application/json' },
39
40
  method: 'GET',
40
41
  response: (request): Listing<SelectEntry> => {
41
42
  const { searchParams } = request;
@@ -1,129 +1,130 @@
1
1
  import {
2
- act,
3
- fireEvent,
4
- getFetchCall,
5
- mockResponse,
6
- type RenderResult,
7
- render,
8
- resetMocks,
9
- waitFor,
10
- } from "../../../../../test/testRenderer";
11
- import buildListingEndpoint from "../../../../api/buildListingEndpoint";
2
+ act,
3
+ fireEvent,
4
+ getFetchCall,
5
+ mockResponse,
6
+ type RenderResult,
7
+ render,
8
+ resetMocks,
9
+ waitFor
10
+ } from '../../../../../test/testRenderer';
11
+ import buildListingEndpoint from '../../../../api/buildListingEndpoint';
12
12
  import type {
13
- BuildListingEndpointParameters,
14
- ConditionsSearchParameter,
15
- } from "../../../../api/buildListingEndpoint/models";
16
- import TestQueryProvider from "../../../../api/TestQueryProvider";
13
+ BuildListingEndpointParameters,
14
+ ConditionsSearchParameter
15
+ } from '../../../../api/buildListingEndpoint/models';
16
+ import TestQueryProvider from '../../../../api/TestQueryProvider';
17
+ import SingleConnectedAutocompleteField from './Single';
17
18
 
18
- import SingleConnectedAutocompleteField from "./Single";
19
-
20
- const label = "Connected Autocomplete";
21
- const placeholder = "Type here...";
19
+ const label = 'Connected Autocomplete';
20
+ const placeholder = 'Type here...';
22
21
 
23
22
  const optionsData = {
24
- meta: {
25
- limit: 2,
26
- page: 1,
27
- total: 20,
28
- },
29
- result: [
30
- { id: 0, name: "My Option 1" },
31
- { id: 1, name: "My Option 2" },
32
- ],
23
+ meta: {
24
+ limit: 2,
25
+ page: 1,
26
+ total: 20
27
+ },
28
+ result: [
29
+ { id: 0, name: 'My Option 1' },
30
+ { id: 1, name: 'My Option 2' }
31
+ ]
33
32
  };
34
33
 
35
- const baseEndpoint = "endpoint";
34
+ const baseEndpoint = 'endpoint';
36
35
 
37
36
  const getEndpoint = (
38
- parameters: BuildListingEndpointParameters["parameters"],
37
+ parameters: BuildListingEndpointParameters['parameters']
39
38
  ): string => {
40
- return buildListingEndpoint({ baseEndpoint, parameters });
39
+ return buildListingEndpoint({ baseEndpoint, parameters });
41
40
  };
42
41
 
43
42
  interface Props {
44
- searchConditions?: Array<ConditionsSearchParameter>;
43
+ searchConditions?: Array<ConditionsSearchParameter>;
45
44
  }
46
45
 
46
+ const mockParams = { headers: { 'Content-Type': 'application/json' } };
47
+
47
48
  const renderSingleConnectedAutocompleteField = (
48
- { searchConditions }: Props = { searchConditions: undefined },
49
+ { searchConditions }: Props = { searchConditions: undefined }
49
50
  ): RenderResult =>
50
- render(
51
- <TestQueryProvider>
52
- <SingleConnectedAutocompleteField
53
- baseEndpoint=""
54
- field="host.name"
55
- getEndpoint={getEndpoint}
56
- label={label}
57
- placeholder="Type here..."
58
- searchConditions={searchConditions}
59
- />
60
- </TestQueryProvider>,
61
- );
51
+ render(
52
+ <TestQueryProvider>
53
+ <SingleConnectedAutocompleteField
54
+ baseEndpoint=""
55
+ field="host.name"
56
+ getEndpoint={getEndpoint}
57
+ label={label}
58
+ placeholder="Type here..."
59
+ searchConditions={searchConditions}
60
+ />
61
+ </TestQueryProvider>
62
+ );
62
63
 
63
64
  describe(SingleConnectedAutocompleteField, () => {
64
- beforeEach(() => {
65
- resetMocks();
66
- mockResponse({ data: optionsData });
67
- });
68
-
69
- it("populates options with the first page result from the endpoint request", async () => {
70
- const { getByLabelText, getByText } =
71
- renderSingleConnectedAutocompleteField();
72
-
73
- fireEvent.click(getByLabelText("Open"));
74
-
75
- expect(getFetchCall(0)).toEqual(`${baseEndpoint}?page=1`);
76
-
77
- await waitFor(() => {
78
- expect(getByText("My Option 1")).toBeInTheDocument();
79
- });
80
- });
81
-
82
- it("populates options with the first page result from the endpoint request after typing something in input field", async () => {
83
- const { getByLabelText, getByPlaceholderText } =
84
- renderSingleConnectedAutocompleteField();
85
-
86
- act(() => {
87
- fireEvent.click(getByLabelText("Open"));
88
- });
89
-
90
- await waitFor(() => {
91
- expect(getFetchCall(0)).toEqual(`${baseEndpoint}?page=1`);
92
- });
93
-
94
- await waitFor(() => {
95
- expect(getFetchCall(1)).toEqual(`${baseEndpoint}?page=2`);
96
- });
97
-
98
- fireEvent.change(getByPlaceholderText(placeholder), {
99
- target: { value: "My Option 2" },
100
- });
101
-
102
- await waitFor(() => {
103
- expect(decodeURIComponent(getFetchCall(2) as string)).toEqual(
104
- 'endpoint?page=1&search={"$and":[{"$and":[{"host.name":{"$lk":"%My Option 2%"}}]}]}',
105
- );
106
- });
107
- });
108
-
109
- it("adds search conditions to the endpoint request when the corresponding prop is passed", async () => {
110
- const { getByLabelText } = renderSingleConnectedAutocompleteField({
111
- searchConditions: [
112
- {
113
- field: "parent_name",
114
- value: {
115
- $eq: "Centreon-Server",
116
- },
117
- },
118
- ],
119
- });
120
-
121
- fireEvent.click(getByLabelText("Open"));
122
-
123
- await waitFor(() => {
124
- expect(getFetchCall(0)).toEqual(
125
- `${baseEndpoint}?page=1&search=%7B%22%24and%22%3A%5B%7B%22%24or%22%3A%5B%7B%22parent_name%22%3A%7B%22%24eq%22%3A%22Centreon-Server%22%7D%7D%5D%7D%5D%7D`,
126
- );
127
- });
128
- });
65
+ beforeEach(() => {
66
+ resetMocks();
67
+ mockResponse({ data: optionsData, options: mockParams });
68
+ });
69
+
70
+ it('populates options with the first page result from the endpoint request', async () => {
71
+ const { getByLabelText, getByText } =
72
+ renderSingleConnectedAutocompleteField();
73
+
74
+ fireEvent.click(getByLabelText('Open'));
75
+
76
+ expect(getFetchCall(0)).toEqual(`${baseEndpoint}?page=1`);
77
+
78
+ await waitFor(() => {
79
+ expect(getByText('My Option 1')).toBeInTheDocument();
80
+ });
81
+ });
82
+
83
+ it('populates options with the first page result from the endpoint request after typing something in input field', async () => {
84
+ const { getByLabelText, getByPlaceholderText } =
85
+ renderSingleConnectedAutocompleteField();
86
+
87
+ act(() => {
88
+ fireEvent.click(getByLabelText('Open'));
89
+ });
90
+
91
+ await waitFor(() => {
92
+ expect(getFetchCall(0)).toEqual(`${baseEndpoint}?page=1`);
93
+ });
94
+
95
+ await waitFor(() => {
96
+ expect(getFetchCall(1)).toEqual(`${baseEndpoint}?page=2`);
97
+ });
98
+
99
+ fireEvent.change(getByPlaceholderText(placeholder), {
100
+ target: { value: 'My Option 2' }
101
+ });
102
+
103
+ await waitFor(() => {
104
+ expect(decodeURIComponent(getFetchCall(2) as string)).toEqual(
105
+ 'endpoint?page=1&search={"$and":[{"$and":[{"host.name":{"$lk":"%My Option 2%"}}]}]}'
106
+ );
107
+ });
108
+ });
109
+
110
+ it('adds search conditions to the endpoint request when the corresponding prop is passed', async () => {
111
+ const { getByLabelText } = renderSingleConnectedAutocompleteField({
112
+ searchConditions: [
113
+ {
114
+ field: 'parent_name',
115
+ value: {
116
+ $eq: 'Centreon-Server'
117
+ }
118
+ }
119
+ ]
120
+ });
121
+
122
+ fireEvent.click(getByLabelText('Open'));
123
+
124
+ await waitFor(() => {
125
+ expect(getFetchCall(0)).toEqual(
126
+ `${baseEndpoint}?page=1&search=%7B%22%24and%22%3A%5B%7B%22%24or%22%3A%5B%7B%22parent_name%22%3A%7B%22%24eq%22%3A%22Centreon-Server%22%7D%7D%5D%7D%5D%7D`
127
+ );
128
+ });
129
+ });
129
130
  });
@@ -104,7 +104,13 @@ export const autoSizeWithEndAdornment = (): JSX.Element => (
104
104
  autoSize
105
105
  autoSizeCustomPadding={10}
106
106
  autoSizeDefaultWidth={60}
107
- EndAdornment={AbcIcon}
108
107
  placeholder="Auto size"
108
+ textFieldSlotsAndSlotProps={{
109
+ slotProps: {
110
+ input: {
111
+ endAdornment: <AbcIcon />
112
+ }
113
+ }
114
+ }}
109
115
  />
110
116
  );
@@ -74,8 +74,13 @@ export const customFetch = <T>({
74
74
  };
75
75
  }
76
76
 
77
- return response
78
- .json()
77
+ const responseParsingMethod = response.headers
78
+ .get('Content-Type')
79
+ ?.startsWith('text')
80
+ ? 'text'
81
+ : 'json';
82
+
83
+ return response[responseParsingMethod]()
79
84
  .then((data) => {
80
85
  if (!response.ok) {
81
86
  const defaultError = {
@@ -37,6 +37,8 @@ const renderFetchQuery = <T extends object>(
37
37
  wrapper: TestQueryProvider
38
38
  }) as RenderHookResult<UseFetchQueryState<T>, unknown>;
39
39
 
40
+ const mockParams = { headers: { 'Content-Type': 'application/json' } };
41
+
40
42
  describe('useFetchQuery', () => {
41
43
  beforeEach(() => {
42
44
  mockedShowErrorMessage.mockReset();
@@ -57,7 +59,7 @@ describe('useFetchQuery', () => {
57
59
  });
58
60
 
59
61
  it('retrieves data from an endpoint', async () => {
60
- fetchMock.once(JSON.stringify(user));
62
+ fetchMock.once(JSON.stringify(user), mockParams);
61
63
  const { result } = renderFetchQuery<User>({
62
64
  getEndpoint: () => '/endpoint',
63
65
  getQueryKey: () => ['queryKey']
@@ -70,6 +72,7 @@ describe('useFetchQuery', () => {
70
72
 
71
73
  it("shows an error from the API via the Snackbar and inside the browser's console", async () => {
72
74
  fetchMock.once(JSON.stringify({ code: 2, message: 'custom message' }), {
75
+ ...mockParams,
73
76
  status: 400
74
77
  });
75
78
 
@@ -109,6 +112,7 @@ describe('useFetchQuery', () => {
109
112
 
110
113
  it('shows a default failure message via the Snackbar as fallback', async () => {
111
114
  fetchMock.once(JSON.stringify({}), {
115
+ ...mockParams,
112
116
  status: 400
113
117
  });
114
118
 
@@ -134,6 +138,7 @@ describe('useFetchQuery', () => {
134
138
 
135
139
  it('does not show any message via the Snackbar when the httpCodesBypassErrorSnackbar is passed', async () => {
136
140
  fetchMock.once(JSON.stringify({}), {
141
+ ...mockParams,
137
142
  status: 400
138
143
  });
139
144