@griddo/ax 1.74.13 → 1.74.15

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "1.74.13",
4
+ "version": "1.74.15",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -229,5 +229,5 @@
229
229
  "publishConfig": {
230
230
  "access": "public"
231
231
  },
232
- "gitHead": "fd0d729d956865a6101f606d64e782872956276b"
232
+ "gitHead": "928076a6e43976683b81a2fafc924d2a42695297"
233
233
  }
@@ -0,0 +1,310 @@
1
+ import * as React from "react";
2
+ import { ThemeProvider } from "styled-components";
3
+ import { render, cleanup, screen, fireEvent } from "@testing-library/react";
4
+ import "@testing-library/jest-dom";
5
+
6
+ import { parseTheme } from "@ax/helpers";
7
+ import Modal, { IModalProps } from "@ax/components/Modal";
8
+ import globalTheme from "@ax/themes/theme.json";
9
+
10
+ afterEach(cleanup);
11
+
12
+ describe("Modal component rendering", () => {
13
+ it("should render the component opened whith children", () => {
14
+ const defaultProps: IModalProps = {
15
+ children: <div>the children</div>,
16
+ isOpen: true,
17
+ hide: jest.fn(),
18
+ };
19
+
20
+ render(
21
+ <ThemeProvider theme={parseTheme(globalTheme)}>
22
+ <Modal {...defaultProps} />
23
+ </ThemeProvider>
24
+ );
25
+
26
+ const modalWrapper = screen.getByTestId("modal-wrapper");
27
+ expect(modalWrapper).toBeTruthy();
28
+ const children = screen.getByText("the children");
29
+ expect(children).toBeTruthy();
30
+ });
31
+
32
+ it("should not render the component closed", () => {
33
+ const defaultProps: IModalProps = {
34
+ children: <div>the children</div>,
35
+ isOpen: false,
36
+ hide: jest.fn(),
37
+ };
38
+
39
+ render(
40
+ <ThemeProvider theme={parseTheme(globalTheme)}>
41
+ <Modal {...defaultProps} />
42
+ </ThemeProvider>
43
+ );
44
+
45
+ const modalWrapper = screen.queryByTestId("modal-wrapper");
46
+ expect(modalWrapper).toBeFalsy();
47
+ });
48
+
49
+ it("should render the component title", () => {
50
+ const titleText = "The Modal Title";
51
+ const defaultProps: IModalProps = {
52
+ children: <div>the children</div>,
53
+ isOpen: true,
54
+ hide: jest.fn(),
55
+ title: titleText,
56
+ };
57
+
58
+ render(
59
+ <ThemeProvider theme={parseTheme(globalTheme)}>
60
+ <Modal {...defaultProps} />
61
+ </ThemeProvider>
62
+ );
63
+
64
+ const title = screen.getByText(titleText);
65
+ expect(title).toBeTruthy();
66
+ });
67
+
68
+ it("should render the main action button", () => {
69
+ const buttonText = "Main Action Button";
70
+ const defaultProps: IModalProps = {
71
+ children: <div>the children</div>,
72
+ isOpen: true,
73
+ hide: jest.fn(),
74
+ mainAction: {
75
+ title: buttonText,
76
+ onClick: jest.fn(),
77
+ },
78
+ };
79
+
80
+ render(
81
+ <ThemeProvider theme={parseTheme(globalTheme)}>
82
+ <Modal {...defaultProps} />
83
+ </ThemeProvider>
84
+ );
85
+
86
+ const mainActionButton = screen.getByText(buttonText).closest("button");
87
+ expect(mainActionButton).toBeTruthy();
88
+ });
89
+
90
+ it("should render the main action button disabled", () => {
91
+ const buttonText = "Main Action Button";
92
+ const defaultProps: IModalProps = {
93
+ children: <div>the children</div>,
94
+ isOpen: true,
95
+ hide: jest.fn(),
96
+ mainAction: {
97
+ title: buttonText,
98
+ onClick: jest.fn(),
99
+ disabled: true,
100
+ },
101
+ };
102
+
103
+ render(
104
+ <ThemeProvider theme={parseTheme(globalTheme)}>
105
+ <Modal {...defaultProps} />
106
+ </ThemeProvider>
107
+ );
108
+
109
+ const mainActionButton = screen.getByText(buttonText).closest("button");
110
+ expect(mainActionButton).toBeTruthy();
111
+ expect(mainActionButton).toBeDisabled();
112
+ });
113
+
114
+ it("should render the secondary action button", () => {
115
+ const buttonText = "Secondary Action Button";
116
+ const defaultProps: IModalProps = {
117
+ children: <div>the children</div>,
118
+ isOpen: true,
119
+ hide: jest.fn(),
120
+ secondaryAction: {
121
+ title: buttonText,
122
+ onClick: jest.fn(),
123
+ },
124
+ };
125
+
126
+ render(
127
+ <ThemeProvider theme={parseTheme(globalTheme)}>
128
+ <Modal {...defaultProps} />
129
+ </ThemeProvider>
130
+ );
131
+
132
+ const secondaryActionButton = screen.getByText(buttonText).closest("button");
133
+ expect(secondaryActionButton).toBeTruthy();
134
+ });
135
+
136
+ it("should render the component whith overflow hidden", () => {
137
+ const defaultProps: IModalProps = {
138
+ children: <div>the children</div>,
139
+ isOpen: true,
140
+ hide: jest.fn(),
141
+ overflow: "hidden",
142
+ };
143
+
144
+ render(
145
+ <ThemeProvider theme={parseTheme(globalTheme)}>
146
+ <Modal {...defaultProps} />
147
+ </ThemeProvider>
148
+ );
149
+
150
+ const modalWrapper = screen.getByTestId("modal-wrapper");
151
+ expect(modalWrapper).toBeTruthy();
152
+ const children = screen.getByText("the children");
153
+ expect(children).toBeTruthy();
154
+ });
155
+
156
+ it("should render the component whith size M", () => {
157
+ const defaultProps: IModalProps = {
158
+ children: <div>the children</div>,
159
+ isOpen: true,
160
+ hide: jest.fn(),
161
+ size: "M",
162
+ };
163
+
164
+ render(
165
+ <ThemeProvider theme={parseTheme(globalTheme)}>
166
+ <Modal {...defaultProps} />
167
+ </ThemeProvider>
168
+ );
169
+
170
+ const modalComponent = screen.getByTestId("modal-component");
171
+ expect(modalComponent).toBeTruthy();
172
+ expect(modalComponent).toHaveStyle("width: 640px");
173
+ });
174
+
175
+ it("should render the component whith size L", () => {
176
+ const defaultProps: IModalProps = {
177
+ children: <div>the children</div>,
178
+ isOpen: true,
179
+ hide: jest.fn(),
180
+ size: "L",
181
+ };
182
+
183
+ render(
184
+ <ThemeProvider theme={parseTheme(globalTheme)}>
185
+ <Modal {...defaultProps} />
186
+ </ThemeProvider>
187
+ );
188
+
189
+ const modalComponent = screen.getByTestId("modal-component");
190
+ expect(modalComponent).toBeTruthy();
191
+ expect(modalComponent).toHaveStyle("width: 896px");
192
+ });
193
+
194
+ it("should render the component whith size XL", () => {
195
+ const defaultProps: IModalProps = {
196
+ children: <div>the children</div>,
197
+ isOpen: true,
198
+ hide: jest.fn(),
199
+ size: "XL",
200
+ };
201
+
202
+ render(
203
+ <ThemeProvider theme={parseTheme(globalTheme)}>
204
+ <Modal {...defaultProps} />
205
+ </ThemeProvider>
206
+ );
207
+
208
+ const modalComponent = screen.getByTestId("modal-component");
209
+ expect(modalComponent).toBeTruthy();
210
+ expect(modalComponent).toHaveStyle("width: 1088px");
211
+ });
212
+ });
213
+
214
+ describe("Modal events", () => {
215
+ it("should call hide on icon button click", () => {
216
+ const hideMock = jest.fn();
217
+ const defaultProps: IModalProps = {
218
+ children: <div>the children</div>,
219
+ isOpen: true,
220
+ hide: hideMock,
221
+ };
222
+
223
+ render(
224
+ <ThemeProvider theme={parseTheme(globalTheme)}>
225
+ <Modal {...defaultProps} />
226
+ </ThemeProvider>
227
+ );
228
+
229
+ const modalButton = screen.getByTestId("icon-action-component");
230
+ expect(modalButton).toBeTruthy();
231
+ fireEvent.click(modalButton);
232
+ expect(hideMock).toBeCalledTimes(1);
233
+ });
234
+
235
+ it("should call action on main action button click", () => {
236
+ const actionMock = jest.fn();
237
+ const buttonText = "Main Action";
238
+ const defaultProps: IModalProps = {
239
+ children: <div>the children</div>,
240
+ isOpen: true,
241
+ hide: jest.fn(),
242
+ mainAction: {
243
+ title: buttonText,
244
+ onClick: actionMock,
245
+ },
246
+ };
247
+
248
+ render(
249
+ <ThemeProvider theme={parseTheme(globalTheme)}>
250
+ <Modal {...defaultProps} />
251
+ </ThemeProvider>
252
+ );
253
+
254
+ const mainActionButton = screen.getByText(buttonText).closest("button");
255
+ expect(mainActionButton).toBeTruthy();
256
+ mainActionButton && fireEvent.click(mainActionButton);
257
+ expect(actionMock).toBeCalledTimes(1);
258
+ });
259
+
260
+ it("should not call action on main action button click if disabled", () => {
261
+ const actionMock = jest.fn();
262
+ const buttonText = "Main Action";
263
+ const defaultProps: IModalProps = {
264
+ children: <div>the children</div>,
265
+ isOpen: true,
266
+ hide: jest.fn(),
267
+ mainAction: {
268
+ title: buttonText,
269
+ onClick: actionMock,
270
+ disabled: true,
271
+ },
272
+ };
273
+
274
+ render(
275
+ <ThemeProvider theme={parseTheme(globalTheme)}>
276
+ <Modal {...defaultProps} />
277
+ </ThemeProvider>
278
+ );
279
+
280
+ const mainActionButton = screen.getByText(buttonText).closest("button");
281
+ expect(mainActionButton).toBeTruthy();
282
+ mainActionButton && fireEvent.click(mainActionButton);
283
+ expect(actionMock).toBeCalledTimes(0);
284
+ });
285
+
286
+ it("should call action on secondary action button click", () => {
287
+ const actionMock = jest.fn();
288
+ const buttonText = "Secondary Action";
289
+ const defaultProps: IModalProps = {
290
+ children: <div>the children</div>,
291
+ isOpen: true,
292
+ hide: jest.fn(),
293
+ secondaryAction: {
294
+ title: buttonText,
295
+ onClick: actionMock,
296
+ },
297
+ };
298
+
299
+ render(
300
+ <ThemeProvider theme={parseTheme(globalTheme)}>
301
+ <Modal {...defaultProps} />
302
+ </ThemeProvider>
303
+ );
304
+
305
+ const secondaryActionButton = screen.getByText(buttonText).closest("button");
306
+ expect(secondaryActionButton).toBeTruthy();
307
+ secondaryActionButton && fireEvent.click(secondaryActionButton);
308
+ expect(actionMock).toBeCalledTimes(1);
309
+ });
310
+ });
@@ -41,7 +41,7 @@ const Modal = (props: IModalProps): JSX.Element | null => {
41
41
  <>
42
42
  <S.ModalOverlay />
43
43
  <S.ModalWrapper data-testid="modal-wrapper">
44
- <S.Modal size={size}>
44
+ <S.Modal size={size} data-testid="modal-component">
45
45
  <S.ModalHeader>
46
46
  {titleContent}
47
47
  <S.ButtonWrapper>
@@ -58,9 +58,9 @@ const Modal = (props: IModalProps): JSX.Element | null => {
58
58
  : null;
59
59
  };
60
60
 
61
- interface IModalProps {
61
+ export interface IModalProps {
62
62
  isOpen: boolean;
63
- hide: any;
63
+ hide: () => void;
64
64
  children: any;
65
65
  title?: string;
66
66
  size?: "S" | "M" | "L" | "XL";
@@ -71,7 +71,7 @@ interface IModalProps {
71
71
 
72
72
  interface IAction {
73
73
  title: string;
74
- onClick: any;
74
+ onClick: () => void;
75
75
  disabled?: boolean;
76
76
  }
77
77