@axinom/mosaic-ui 0.63.0-rc.3 → 0.63.0-rc.4

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": "@axinom/mosaic-ui",
3
- "version": "0.63.0-rc.3",
3
+ "version": "0.63.0-rc.4",
4
4
  "description": "UI components for building Axinom Mosaic applications",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -112,5 +112,5 @@
112
112
  "publishConfig": {
113
113
  "access": "public"
114
114
  },
115
- "gitHead": "a78369cc85ef82dad007c3fa8ff8f0b8b0cb149b"
115
+ "gitHead": "490e0fb462b6c1dd2024b1f30076f647a14216ce"
116
116
  }
@@ -42,6 +42,7 @@
42
42
 
43
43
  .button {
44
44
  transition: transform 200ms ease;
45
+
45
46
  svg {
46
47
  height: 40%;
47
48
  }
@@ -49,10 +50,19 @@
49
50
  svg * {
50
51
  stroke: var(--accordion-item-arrow-color, $accordion-item-arrow-color);
51
52
  }
53
+
54
+ &.disabled {
55
+ svg * {
56
+ stroke: var(
57
+ --accordion-item-arrow-disabled-color,
58
+ $accordion-item-arrow-disabled-color
59
+ );
60
+ }
61
+ }
62
+
63
+ &.rotated {
64
+ transform: rotate(90deg);
65
+ }
52
66
  }
53
67
  }
54
68
  }
55
-
56
- .rotated {
57
- transform: rotate(90deg);
58
- }
@@ -1,59 +1,30 @@
1
- import { mount, shallow } from 'enzyme';
1
+ import '@testing-library/jest-dom';
2
+ import { configure, fireEvent, render, screen } from '@testing-library/react';
2
3
  import React from 'react';
3
- import { Button } from '../Buttons';
4
- import { IconName } from '../Icons';
5
4
  import { Accordion } from './Accordion';
6
5
  import { AccordionItem } from './AccordionItem/AccordionItem';
7
6
 
7
+ configure({ testIdAttribute: 'data-test-id' });
8
+
8
9
  describe('Accordion', () => {
9
10
  it('renders the component without crashing', () => {
10
- const wrapper = shallow(<Accordion />);
11
-
12
- expect(wrapper).toBeTruthy();
13
- });
11
+ render(<Accordion />);
14
12
 
15
- it('contains a wrapper', () => {
16
- const wrapper = shallow(<Accordion header={<b>Header</b>} />);
17
-
18
- const accWrapper = wrapper.find('.container > div');
19
-
20
- expect(accWrapper.hasClass('wrapper')).toBe(true);
13
+ expect(screen.getByTestId('accordion')).toBeInTheDocument();
21
14
  });
22
15
 
23
16
  it('renders the component header', () => {
24
- const wrapper = shallow(<Accordion header={<b>Header</b>} />);
25
-
26
- expect(wrapper.find('.header').exists()).toBeTruthy();
17
+ render(<Accordion header={<b>Header</b>} />);
18
+ expect(screen.getByTestId('accordion-header')).toBeInTheDocument();
27
19
  });
28
20
 
29
21
  it('does not render a header when the prop is not provided', () => {
30
- const wrapper = shallow(<Accordion />);
31
-
32
- expect(wrapper.find('.header').exists()).toBeFalsy();
33
- });
34
-
35
- it('populates toggleExpanded and isExpanded props of child AccordionItem components', () => {
36
- const wrapper = mount(
37
- <Accordion header={<b>Header</b>}>
38
- <div id="extra"></div>
39
- <AccordionItem header={<b>Item 1</b>}>
40
- <p>Content 1</p>
41
- </AccordionItem>
42
- </Accordion>,
43
- );
44
-
45
- const item = wrapper.find(AccordionItem);
46
- const extra = wrapper.find('#extra');
47
-
48
- expect(item.prop('isExpanded')).toBeDefined();
49
- expect(item.prop('toggleExpanded')).toBeDefined();
50
-
51
- expect(extra.prop('isExpanded')).toBeUndefined();
52
- expect(extra.prop('toggleExpanded')).toBeUndefined();
22
+ render(<Accordion />);
23
+ expect(screen.queryByTestId('accordion-header')).not.toBeInTheDocument();
53
24
  });
54
25
 
55
26
  it('expands / collapses all children when the button is clicked', () => {
56
- const wrapper = mount(
27
+ render(
57
28
  <Accordion header={<b>Header</b>}>
58
29
  <AccordionItem header={<b>Item 1</b>}>
59
30
  <p>Content 1</p>
@@ -67,26 +38,31 @@ describe('Accordion', () => {
67
38
  </Accordion>,
68
39
  );
69
40
 
70
- const button = wrapper.find('.header .button').first();
71
- button.simulate('click');
41
+ // Find the expand/collapse all button (assuming it's the first button in header)
42
+ const headerButton = screen.getByTestId('accordion-toggle-all');
43
+ fireEvent.click(headerButton);
72
44
 
73
- let items = wrapper.find(AccordionItem);
45
+ // All items should be expanded (content visible)
46
+ let rows = screen.getAllByTestId('accordion-item-content');
47
+ expect(rows).toHaveLength(3);
74
48
 
75
- items.forEach((item) => {
76
- expect(item.prop('isExpanded')).toBe(true);
49
+ rows.forEach((row) => {
50
+ expect(row).toHaveClass('expanded');
77
51
  });
78
52
 
79
- button.simulate('click');
53
+ fireEvent.click(headerButton);
80
54
 
81
- items = wrapper.find(AccordionItem);
55
+ // All items should be collapsed (content not visible)
56
+ rows = screen.getAllByTestId('accordion-item-content');
57
+ expect(rows).toHaveLength(3);
82
58
 
83
- items.forEach((item) => {
84
- expect(item.prop('isExpanded')).toBe(false);
59
+ rows.forEach((row) => {
60
+ expect(row).not.toHaveClass('expanded');
85
61
  });
86
62
  });
87
63
 
88
64
  it('displays rotated ChevronRight icon when one or more children are expanded', () => {
89
- const wrapper = mount(
65
+ render(
90
66
  <Accordion header={<b>Header</b>}>
91
67
  <AccordionItem header={<b>Item 1</b>}>
92
68
  <p>Content 1</p>
@@ -100,25 +76,29 @@ describe('Accordion', () => {
100
76
  </Accordion>,
101
77
  );
102
78
 
103
- let button = wrapper.find(Button).first();
104
-
105
- expect(button.prop('icon')).toBe(IconName.ChevronRight);
106
- expect(button.hasClass('rotated')).toBe(false);
79
+ // The button in the header should have the ChevronRight icon and not be rotated initially
80
+ const headerButton = screen.getByTestId('accordion-toggle-all');
81
+ expect(headerButton.querySelector('.rotated')).not.toBeInTheDocument();
107
82
 
108
- const item = wrapper.find(AccordionItem).last();
83
+ // Expand the last item
84
+ const lastItemButton = screen.getAllByRole('button')[2];
85
+ fireEvent.click(lastItemButton);
109
86
 
110
- item.find('button').simulate('click');
87
+ // Now the header button should have the rotated class
88
+ expect(headerButton).toHaveClass('rotated');
111
89
 
112
- button = wrapper.find(Button).first();
90
+ // Collapse the last item
91
+ fireEvent.click(lastItemButton);
113
92
 
114
- expect(button.prop('icon')).toBe(IconName.ChevronRight);
115
- expect(button.hasClass('rotated')).toBe(true);
116
-
117
- item.find('button').simulate('click');
93
+ // The header button should not have the rotated class anymore
94
+ expect(headerButton).not.toHaveClass('rotated');
95
+ });
118
96
 
119
- button = wrapper.find(Button).first();
97
+ it('disables the expand/collapse all button when there are no children', () => {
98
+ render(<Accordion header={<b>Header</b>} />);
120
99
 
121
- expect(button.prop('icon')).toBe(IconName.ChevronRight);
122
- expect(button.hasClass('rotated')).toBe(false);
100
+ // The button should be disabled when there are no children
101
+ const headerButton = screen.getByTestId('accordion-toggle-all');
102
+ expect(headerButton).toBeDisabled();
123
103
  });
124
104
  });
@@ -145,3 +145,11 @@ export const NestedSticky: StoryObj<typeof Accordion> = {
145
145
  },
146
146
  name: 'Nested Sticky',
147
147
  };
148
+
149
+ export const NoChildren: StoryObj<typeof Accordion> = {
150
+ args: {
151
+ ...Default.args,
152
+ children: undefined,
153
+ },
154
+ name: 'No children',
155
+ };
@@ -58,6 +58,7 @@ export const Accordion: React.FC<AccordionProps> = ({
58
58
  }) => {
59
59
  const expandAll = useExpand();
60
60
  const [expanded, setExpanded] = useState<ExpandedState>({});
61
+ const disabled = !React.Children.count(children);
61
62
 
62
63
  useEffect(() => {
63
64
  setExpanded((oldState) => {
@@ -110,8 +111,11 @@ export const Accordion: React.FC<AccordionProps> = ({
110
111
  }}
111
112
  className={clsx(classes.button, {
112
113
  [classes.rotated]: expandAll.isExpanded,
114
+ [classes.disabled]: disabled,
113
115
  })}
114
116
  buttonContext={ButtonContext.None}
117
+ disabled={disabled}
118
+ dataTestId="accordion-toggle-all"
115
119
  ></Button>
116
120
  {header}
117
121
  </div>
@@ -1,111 +1,73 @@
1
- import { mount, shallow } from 'enzyme';
1
+ import '@testing-library/jest-dom';
2
+ import { configure, fireEvent, render, screen } from '@testing-library/react';
2
3
  import React from 'react';
3
4
  import { AccordionItem } from './AccordionItem';
4
5
 
5
- describe('AccordionItem', () => {
6
- it('renders the component without crashing', () => {
7
- const wrapper = shallow(<AccordionItem header={<b>Item 1</b>} />);
8
-
9
- expect(wrapper).toBeTruthy();
10
- });
6
+ configure({ testIdAttribute: 'data-test-id' });
11
7
 
12
- it('renders expanded content', () => {
13
- const wrapper = shallow(
14
- <AccordionItem header={<b>Item 1</b>} isExpanded={true} />,
15
- );
16
-
17
- const content = wrapper.find('.expanded');
8
+ describe('AccordionItem', () => {
9
+ const header = <span>Header</span>;
10
+ const content = <div>Accordion Content</div>;
18
11
 
19
- expect(content).toHaveLength(1);
12
+ it('renders header and children', () => {
13
+ render(<AccordionItem header={header}>{content}</AccordionItem>);
14
+ expect(screen.getByText('Header')).toBeInTheDocument();
15
+ expect(screen.getByText('Accordion Content')).toBeInTheDocument();
20
16
  });
21
17
 
22
- it('does not render expanded content when isExpanded is false', () => {
23
- const wrapper = shallow(
24
- <AccordionItem header={<b>Item 1</b>} isExpanded={false} />,
18
+ it('calls toggleExpanded when row is clicked', () => {
19
+ const toggleExpanded = jest.fn();
20
+ render(
21
+ <AccordionItem header={header} toggleExpanded={toggleExpanded}>
22
+ {content}
23
+ </AccordionItem>,
25
24
  );
26
-
27
- const content = wrapper.find('.expanded');
28
-
29
- expect(content).toHaveLength(0);
25
+ fireEvent.click(screen.getByTestId('accordion-item-row'));
26
+ expect(toggleExpanded).toHaveBeenCalled();
30
27
  });
31
28
 
32
- it('triggers toggleExpanded callback when the expand button is pressed', () => {
33
- const spy = jest.fn();
34
- const wrapper = mount(
35
- <AccordionItem header={<b>Item 1</b>} toggleExpanded={spy} />,
36
- );
37
-
38
- const button = wrapper.find('button');
39
-
40
- button.simulate('click');
41
-
42
- expect(spy).toHaveBeenCalledTimes(1);
43
- });
44
-
45
- it('adds 50px spacing element by default', () => {
46
- const wrapper = shallow(
47
- <AccordionItem header={<b>Item 1</b>}>
48
- <div></div>
29
+ it('shows expanded styles and rotates icon when isExpanded is true', () => {
30
+ render(
31
+ <AccordionItem header={header} isExpanded>
32
+ {content}
49
33
  </AccordionItem>,
50
34
  );
51
-
52
- const contentStyles = wrapper
53
- .find('.content')
54
- .prop('style') as React.CSSProperties;
55
- const children = wrapper.find('.content > div');
56
-
57
- expect(contentStyles.gridTemplateColumns).toBeUndefined();
58
- expect(children).toHaveLength(2);
35
+ const row = screen.getByTestId('accordion-item-row');
36
+ expect(row.className).toMatch(/rowExpanded/);
37
+ const button = row.querySelector('button');
38
+ expect(button?.className).toMatch(/rotated/);
39
+ const contentDiv = screen.getByTestId('accordion-item-content');
40
+ expect(contentDiv.className).toMatch(/expanded/);
59
41
  });
60
42
 
61
- it(`doesn't add 50px spacing element if 'allowLeftSpacing' is set to false`, () => {
62
- const wrapper = shallow(
63
- <AccordionItem header={<b>Item 1</b>} allowLeftSpacing={false}>
64
- <div></div>
43
+ it('applies sticky class when sticky is true', () => {
44
+ render(
45
+ <AccordionItem header={header} sticky>
46
+ {content}
65
47
  </AccordionItem>,
66
48
  );
67
-
68
- const contentStyles = wrapper
69
- .find('.content')
70
- .prop('style') as React.CSSProperties;
71
- const children = wrapper.find('.content > div');
72
-
73
- expect(contentStyles.gridTemplateColumns).toBe('1fr');
74
- expect(children).toHaveLength(1);
49
+ const row = screen.getByTestId('accordion-item-row');
50
+ expect(row.className).toMatch(/sticky/);
75
51
  });
76
52
 
77
- it(`should set expanded class when 'isExpanded' is true`, () => {
78
- const wrapper = mount(
79
- <AccordionItem header={<b>Item 1</b>} isExpanded={true}>
80
- <div></div>
53
+ it('does not add left spacing when allowLeftSpacing is false', () => {
54
+ render(
55
+ <AccordionItem header={header} allowLeftSpacing={false}>
56
+ {content}
81
57
  </AccordionItem>,
82
58
  );
83
-
84
- const expanded = wrapper.find('.expanded');
85
-
86
- expect(expanded).toHaveLength(1);
59
+ const contentDiv = screen.getByText('Accordion Content').parentElement;
60
+ expect(contentDiv).toHaveStyle('grid-template-columns: 1fr');
87
61
  });
88
62
 
89
- it(`should not set expanded class when 'isExpanded' is true`, () => {
90
- const wrapper = mount(
91
- <AccordionItem header={<b>Item 1</b>} isExpanded={false}>
92
- <div></div>
63
+ it('applies custom className to root element', () => {
64
+ render(
65
+ <AccordionItem header={header} className="custom-class">
66
+ {content}
93
67
  </AccordionItem>,
94
68
  );
95
-
96
- const expanded = wrapper.find('.expanded');
97
-
98
- expect(expanded).toHaveLength(0);
99
- });
100
-
101
- it('creates a class based off of the className prop', () => {
102
- const mockClassName = 'test-class';
103
- const wrapper = shallow(
104
- <AccordionItem header={<b>Item 1</b>} className={mockClassName} />,
69
+ expect(screen.getByTestId('accordion-item').className).toContain(
70
+ 'custom-class',
105
71
  );
106
-
107
- const item = wrapper.find('.test-class');
108
-
109
- expect(item.hasClass(mockClassName)).toBe(true);
110
72
  });
111
73
  });
@@ -42,6 +42,7 @@ $accordion-item-text-color: $dark-gray;
42
42
  $accordion-item-hover-color: rgba($blue, 0.15);
43
43
  $accordion-item-border: 1px solid $light-gray;
44
44
  $accordion-item-arrow-color: $blue;
45
+ $accordion-item-arrow-disabled-color: $gray;
45
46
 
46
47
  /* Explorer vars */
47
48
  $explorer-background-color: #ffffff;