@griddo/ax 1.73.4 → 1.73.5

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.73.4",
4
+ "version": "1.73.5",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -226,5 +226,5 @@
226
226
  "publishConfig": {
227
227
  "access": "public"
228
228
  },
229
- "gitHead": "62dcd142febf2751510fe1d2c3de7be1b8233b25"
229
+ "gitHead": "1ef96a4cd7cae09f622854c52bfaa643b04beda3"
230
230
  }
@@ -0,0 +1,141 @@
1
+ import * as React from "react";
2
+
3
+ import { ThemeProvider } from "styled-components";
4
+ import { render, cleanup, screen, fireEvent, waitFor } from "@testing-library/react";
5
+ import { parseTheme } from "@ax/helpers";
6
+ import "@testing-library/jest-dom";
7
+
8
+ import MenuItem, { IMenuItemProps } from "@ax/components/MenuItem";
9
+ import globalTheme from "@ax/themes/theme.json";
10
+ import userEvent from "@testing-library/user-event";
11
+
12
+ afterEach(cleanup);
13
+
14
+ describe("MenuItem component rendering", () => {
15
+ it("should render the component inactive", () => {
16
+ const defaultProps: IMenuItemProps = {
17
+ children: <div>Item</div>,
18
+ };
19
+
20
+ render(
21
+ <ThemeProvider theme={parseTheme(globalTheme)}>
22
+ <MenuItem {...defaultProps} />
23
+ </ThemeProvider>
24
+ );
25
+
26
+ const subItem = screen.getByTestId("menu-subitem");
27
+ expect(subItem).toBeTruthy();
28
+ });
29
+
30
+ it("should render the component active", () => {
31
+ const defaultProps: IMenuItemProps = {
32
+ children: <div>Item</div>,
33
+ active: true,
34
+ };
35
+
36
+ render(
37
+ <ThemeProvider theme={parseTheme(globalTheme)}>
38
+ <MenuItem {...defaultProps} />
39
+ </ThemeProvider>
40
+ );
41
+
42
+ const subItem = screen.getByTestId("menu-subitem");
43
+ expect(subItem).toBeTruthy();
44
+ });
45
+
46
+ it("should render with extendend action visible", () => {
47
+ const defaultProps: IMenuItemProps = {
48
+ children: <div>Item</div>,
49
+ extendedAction: { icon: "delete", action: jest.fn(), onlyOnHover: false },
50
+ };
51
+
52
+ render(
53
+ <ThemeProvider theme={parseTheme(globalTheme)}>
54
+ <MenuItem {...defaultProps} />
55
+ </ThemeProvider>
56
+ );
57
+
58
+ const subItem = screen.getByTestId("menu-subitem");
59
+ const extendedAction = screen.getByTestId("menu-extended-action");
60
+ expect(subItem).toBeTruthy();
61
+ expect(extendedAction).toBeTruthy();
62
+ });
63
+
64
+ it("should render with extendend action not visible", () => {
65
+ const defaultProps: IMenuItemProps = {
66
+ children: <div>Item</div>,
67
+ extendedAction: { icon: "delete", action: jest.fn(), onlyOnHover: true },
68
+ };
69
+
70
+ render(
71
+ <ThemeProvider theme={parseTheme(globalTheme)}>
72
+ <MenuItem {...defaultProps} />
73
+ </ThemeProvider>
74
+ );
75
+
76
+ const subItem = screen.getByTestId("menu-subitem");
77
+ const extendedAction = screen.getByTestId("menu-extended-action");
78
+ expect(subItem).toBeTruthy();
79
+ expect(extendedAction).not.toBeVisible();
80
+ });
81
+
82
+ it("should render with extendend action not visible if onlyOnHover is undefined", () => {
83
+ const defaultProps: IMenuItemProps = {
84
+ children: <div>Item</div>,
85
+ extendedAction: { icon: "delete", action: jest.fn() },
86
+ };
87
+
88
+ render(
89
+ <ThemeProvider theme={parseTheme(globalTheme)}>
90
+ <MenuItem {...defaultProps} />
91
+ </ThemeProvider>
92
+ );
93
+
94
+ const subItem = screen.getByTestId("menu-subitem");
95
+ const extendedAction = screen.getByTestId("menu-extended-action");
96
+ expect(subItem).toBeTruthy();
97
+ expect(extendedAction).not.toBeVisible();
98
+ });
99
+ });
100
+
101
+ describe("component events", () => {
102
+ test("onClick is been called", () => {
103
+ const onClickMock = jest.fn();
104
+ const defaultProps: IMenuItemProps = {
105
+ children: <div>Item</div>,
106
+ onClick: onClickMock,
107
+ };
108
+
109
+ render(
110
+ <ThemeProvider theme={parseTheme(globalTheme)}>
111
+ <MenuItem {...defaultProps} />
112
+ </ThemeProvider>
113
+ );
114
+
115
+ const subItem = screen.getByTestId("menu-subitem");
116
+ expect(subItem).toBeTruthy();
117
+ fireEvent.click(subItem);
118
+ expect(onClickMock).toBeCalledTimes(1);
119
+ });
120
+
121
+ test("extended action is called", async () => {
122
+ const actionMock = jest.fn();
123
+ const defaultProps: IMenuItemProps = {
124
+ children: <div>Item</div>,
125
+ extendedAction: { icon: "delete", action: actionMock, onlyOnHover: false },
126
+ };
127
+
128
+ render(
129
+ <ThemeProvider theme={parseTheme(globalTheme)}>
130
+ <MenuItem {...defaultProps} />
131
+ </ThemeProvider>
132
+ );
133
+
134
+ const extendedAction = screen.getByTestId("menu-extended-action");
135
+ const iconActionComponent = screen.getByTestId("icon-action-component");
136
+ expect(extendedAction).toBeTruthy();
137
+ expect(iconActionComponent).toBeTruthy();
138
+ fireEvent.click(iconActionComponent);
139
+ expect(actionMock).toBeCalledTimes(1);
140
+ });
141
+ });
@@ -0,0 +1,56 @@
1
+ import * as React from "react";
2
+ import { BrowserRouter } from "react-router-dom";
3
+
4
+ import { ThemeProvider } from "styled-components";
5
+ import { render, cleanup, screen } from "@testing-library/react";
6
+ import { parseTheme } from "@ax/helpers";
7
+ import "@testing-library/jest-dom";
8
+
9
+ import Nav, { INavProps } from "@ax/components/Nav";
10
+ import globalTheme from "@ax/themes/theme.json";
11
+
12
+ afterEach(cleanup);
13
+
14
+ describe("Nav component rendering", () => {
15
+ it("should render the component with 3 links", () => {
16
+ const items = [
17
+ { title: "Item 1", path: "/item1", component: "Item1" },
18
+ { title: "Item 2", path: "/item2", component: "Item2" },
19
+ { title: "Item 3", path: "/item3", component: "Item3" },
20
+ ];
21
+
22
+ const defaultProps: INavProps = {
23
+ items,
24
+ current: items[0],
25
+ onClick: jest.fn(),
26
+ };
27
+
28
+ render(
29
+ <ThemeProvider theme={parseTheme(globalTheme)}>
30
+ <Nav {...defaultProps} />
31
+ </ThemeProvider>,
32
+ { wrapper: BrowserRouter }
33
+ );
34
+
35
+ const links = screen.queryAllByTestId("nav-link");
36
+ expect(links).toHaveLength(3);
37
+ });
38
+
39
+ it("should render the component with 0 links", () => {
40
+ const defaultProps: INavProps = {
41
+ items: [],
42
+ current: undefined,
43
+ onClick: jest.fn(),
44
+ };
45
+
46
+ render(
47
+ <ThemeProvider theme={parseTheme(globalTheme)}>
48
+ <Nav {...defaultProps} />
49
+ </ThemeProvider>,
50
+ { wrapper: BrowserRouter }
51
+ );
52
+
53
+ const links = screen.queryAllByTestId("nav-link");
54
+ expect(links).toHaveLength(0);
55
+ });
56
+ });
@@ -19,10 +19,10 @@ const MenuItem = (props: IMenuItemProps): JSX.Element => {
19
19
  };
20
20
 
21
21
  return (
22
- <S.SubItem onClick={handleOnClick} active={active}>
22
+ <S.SubItem onClick={handleOnClick} active={active} data-testid="menu-subitem">
23
23
  {children}
24
24
  {extendedAction && (
25
- <S.ExtendedAction onlyOnHover={extendedAction.onlyOnHover ?? true}>
25
+ <S.ExtendedAction onlyOnHover={extendedAction.onlyOnHover ?? true} data-testid="menu-extended-action">
26
26
  <IconAction icon={extendedAction.icon} size="s" onClick={handleExtendedAction} />
27
27
  </S.ExtendedAction>
28
28
  )}
@@ -30,7 +30,7 @@ const MenuItem = (props: IMenuItemProps): JSX.Element => {
30
30
  );
31
31
  };
32
32
 
33
- interface IMenuItemProps {
33
+ export interface IMenuItemProps {
34
34
  children: JSX.Element | string;
35
35
  active?: boolean;
36
36
  onClick?: (e: React.MouseEvent<HTMLLIElement>) => void;
@@ -4,22 +4,22 @@ import { NavLink } from "react-router-dom";
4
4
  import { SubNav, MenuItem } from "@ax/components";
5
5
  import { INavItem } from "@ax/types";
6
6
 
7
- import * as S from './style';
7
+ import * as S from "./style";
8
8
 
9
- const Nav = (props: IProps): JSX.Element => {
9
+ const Nav = (props: INavProps): JSX.Element => {
10
10
  const { current, items, onClick } = props;
11
11
 
12
12
  return (
13
13
  <SubNav>
14
14
  {items &&
15
15
  items.map((item: INavItem, key: number) => {
16
- const isSelected = current && item.title === current.title;
16
+ const isSelected = (current && item.title === current.title) || false;
17
17
  const selectedClass = isSelected ? "selected" : "";
18
18
  const handleClick = () => onClick(item.path);
19
19
  return (
20
20
  <MenuItem key={key} onClick={handleClick}>
21
21
  <NavLink to="#" className={selectedClass}>
22
- <S.Link active={isSelected}>
22
+ <S.Link active={isSelected} data-testid="nav-link">
23
23
  {item.title}
24
24
  </S.Link>
25
25
  </NavLink>
@@ -30,8 +30,8 @@ const Nav = (props: IProps): JSX.Element => {
30
30
  );
31
31
  };
32
32
 
33
- interface IProps {
34
- current: INavItem;
33
+ export interface INavProps {
34
+ current?: INavItem;
35
35
  items: INavItem[];
36
36
  onClick(path: string): void;
37
37
  }