@nuskin/foundation-ui-components 1.0.0-develop.6 → 1.0.0-develop.8
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 +17 -12
- package/src/common/accordion/NsAccordion.tsx +30 -40
- package/src/common/accordion/NsAccordionHeader.tsx +27 -7
- package/src/common/accordion/NsAccordionItem.tsx +16 -4
- package/src/common/accordion/NsCollapse.tsx +71 -35
- package/src/common/accordion/NsToggleSection.tsx +14 -3
- package/src/common/accordion/ToggleSection.styled.tsx +11 -7
- package/src/common/accordion/colorMap.ts +117 -0
- package/src/common/accordion/enums.ts +8 -0
- package/src/common/accordion/index.ts +1 -0
- package/src/common/accordion/specs/NsAccordion.spec.tsx +100 -31
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +77 -10
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +23 -10
- package/src/common/accordion/specs/NsCollapse.spec.tsx +106 -17
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +46 -14
- package/src/common/accordion/stories/NsAccordion.stories.tsx +32 -14
- package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +4 -1
- package/src/common/accordion/stories/NsAccordionItem.stories.tsx +3 -3
- package/src/common/accordion/stories/NsCollapse.stories.tsx +3 -3
- package/src/common/accordion/stories/NsToggleSection.stories.tsx +2 -3
- package/src/common/accordion/stories/data.tsx +157 -19
- package/src/common/accordion/types.d.ts +56 -49
- package/src/common/alert/Header.tsx +29 -0
- package/src/common/alert/NsAlert.spec.tsx +46 -13
- package/src/common/alert/NsAlert.stories.tsx +3 -3
- package/src/common/alert/{NsAlert.styled.ts → NsAlert.styled.tsx} +22 -22
- package/src/common/alert/NsAlert.tsx +22 -87
- package/src/common/alert/types.d.ts +7 -7
- package/src/common/auth-dropdown/NsAuthDropdown.spec.tsx +23 -5
- package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +1 -1
- package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +11 -7
- package/src/common/auth-dropdown/NsAuthDropdown.tsx +4 -4
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +29 -6
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +1 -1
- package/src/common/autocomplete/NsAutocomplete.tsx +18 -8
- package/src/common/autocomplete/mock/MockUI.tsx +1 -0
- package/src/common/banner/NsBanner.spec.tsx +12 -3
- package/src/common/banner/NsBanner.stories.tsx +1 -1
- package/src/common/brand-components/NsBrand.stories.tsx +1 -1
- package/src/common/brand-components/NsBrandComponent.tsx +2 -2
- package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +8 -3
- package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +1 -1
- package/src/common/breadcrumb/data.ts +8 -5
- package/src/common/button/NsButton.spec.tsx +65 -49
- package/src/common/button/NsButton.stories.tsx +59 -2
- package/src/common/button/NsButton.styled.tsx +49 -66
- package/src/common/button/NsButton.tsx +1 -2
- package/src/common/button/helper.ts +82 -0
- package/src/common/button/types.d.ts +2 -0
- package/src/common/card/stories/NsBgCard.stories.tsx +1 -1
- package/src/common/card/stories/NsBrandProductCard.stories.tsx +1 -1
- package/src/common/card/stories/NsFfgCard.stories.tsx +5 -2
- package/src/common/card/styled/NsFfgStyled.tsx +1 -1
- package/src/common/carousal/stories/NSCarousal.stories.tsx +1 -1
- package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +1 -1
- package/src/common/cart-icon/NsCartIcon.stories.tsx +1 -1
- package/src/common/checkbox/NsCheckbox.stories.tsx +1 -1
- package/src/common/checkbox/NsCheckbox.styled.tsx +15 -16
- package/src/common/checkbox/NsCheckbox.tsx +1 -1
- package/src/common/column-control/stories/DivArray.stories.tsx +1 -1
- package/src/common/column-control/stories/NsColumnControl.stories.tsx +1 -1
- package/src/common/column-control/stories/NsFlexColumns.stories.tsx +1 -1
- package/src/common/column-control/stories/NsGridColumns.stories.tsx +1 -1
- package/src/common/column-control/styled/common.ts +1 -1
- package/src/common/column-control/utils.ts +4 -4
- package/src/common/common.types.d.ts +11 -1
- package/src/common/dropdown/NsDropdown.styled.tsx +23 -18
- package/src/common/dropdown/stories/NsDropdown.stories.tsx +1 -1
- package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +1 -1
- package/src/common/flag/NsFlag.stories.tsx +1 -1
- package/src/common/hooks/index.ts +2 -0
- package/src/common/hooks/specs/useWindowSize.spec.tsx +19 -0
- package/src/common/hooks/useAccordionMap.tsx +39 -0
- package/src/common/hooks/useWindowSize.tsx +30 -0
- package/src/common/icon/NsIcon.stories.tsx +1 -1
- package/src/common/icon/NsIconVariants.ts +1 -0
- package/src/common/image/NsImage.spec.tsx +56 -6
- package/src/common/image/NsImage.stories.tsx +1 -1
- package/src/common/image/NsImage.tsx +23 -11
- package/src/common/image/NsNextImage.stories.tsx +1 -1
- package/src/common/index.ts +6 -2
- package/src/common/input/InputWrapper.tsx +12 -7
- package/src/common/input/NsInputField.tsx +1 -1
- package/src/common/label/NsLabel.stories.tsx +1 -1
- package/src/common/link/NsLink.stories.tsx +1 -1
- package/src/common/modal/NsModal.spec.tsx +46 -0
- package/src/common/modal/NsModal.styled.tsx +28 -0
- package/src/common/modal/NsModal.tsx +37 -0
- package/src/common/modal/helper-component/NsModalContentBox.tsx +32 -0
- package/src/common/modal/helper-component/NsModalDefault.tsx +25 -0
- package/src/common/modal/helper-component/NsModalStatus.tsx +15 -0
- package/src/common/modal/helper-component/NsModalStatusIcon.tsx +14 -0
- package/src/common/modal/helper-component/NsModalTitle.tsx +26 -0
- package/src/common/modal/index.ts +2 -0
- package/src/common/modal/model/NsModalVariantMap.tsx +24 -0
- package/src/common/modal/stories/NsModal.stories.tsx +86 -0
- package/src/common/modal/stories/mock.tsx +46 -0
- package/src/common/modal/types.ts +56 -0
- package/src/common/nav-product-card/NsNavProductCard.stories.tsx +1 -1
- package/src/common/nav-tab/NsNavTab.stories.tsx +1 -1
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +24 -25
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +14 -32
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +17 -15
- package/src/common/radiogroup/NsRadioGroup.tsx +6 -5
- package/src/common/search-bar/NsSearchBar.tsx +1 -3
- package/src/common/select/NsSelect.spec.tsx +10 -17
- package/src/common/select/NsSelect.styled.tsx +53 -34
- package/src/common/select/stories/NsSelect.stories.tsx +11 -11
- package/src/common/select/types.d.ts +3 -3
- package/src/common/spinner/NsSpinner.spec.tsx +21 -0
- package/src/common/spinner/NsSpinner.stories.tsx +26 -0
- package/src/common/spinner/NsSpinner.styled.tsx +344 -0
- package/src/common/spinner/NsSpinner.tsx +14 -0
- package/src/common/spinner/icons/Spinner.tsx +161 -0
- package/src/common/spinner/index.ts +2 -0
- package/src/common/spinner/types.ts +5 -0
- package/src/common/table/NsTable.stories.tsx +1 -1
- package/src/common/table/NsTable.tsx +32 -49
- package/src/common/table/NsTableHeader.tsx +30 -51
- package/src/common/text-strip/NsTextStrip.stories.tsx +1 -1
- package/src/common/typography/NsTypography.stories.tsx +1 -1
- package/src/common/util.ts +1 -0
- package/src/common/utility/Show.tsx +13 -0
- package/src/common/utility/index.ts +1 -0
- package/src/common/videos/NsVideo.stories.tsx +1 -1
- package/src/common/videos/types.d.ts +1 -1
- /package/src/common/brand-components/{NsBrandContanier.styled.tsx → NsBrandContainer.styled.tsx} +0 -0
|
@@ -1,50 +1,55 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, fireEvent, screen } from '@/test-utils/index';
|
|
3
|
-
import { AccordionVariant, NsAccordion
|
|
3
|
+
import { AccordionItem, AccordionVariant, NsAccordion } from '@/common/index';
|
|
4
4
|
|
|
5
|
-
const generateContentArray = (count: number) => {
|
|
6
|
-
const arr = [] as
|
|
5
|
+
const generateContentArray = (count: number, isDefaultOpen = true) => {
|
|
6
|
+
const arr = [] as AccordionItem[];
|
|
7
7
|
for (let i = 1; i <= count; i++) {
|
|
8
|
-
arr
|
|
8
|
+
arr?.push({
|
|
9
9
|
title: `Title ${i}`,
|
|
10
|
-
|
|
11
|
-
isDefaultOpen
|
|
10
|
+
content: <div className="p-2">Content {i}</div>,
|
|
11
|
+
isDefaultOpen,
|
|
12
|
+
id: `Test ${i}`,
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
return arr;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
describe('NsAccordion', () => {
|
|
18
|
-
const
|
|
19
|
+
const items = generateContentArray(3);
|
|
19
20
|
const defaultProps = {
|
|
20
21
|
additionalProps: {
|
|
21
22
|
testid: 'test-accordion',
|
|
22
23
|
},
|
|
23
24
|
allowMultipleExpanded: false,
|
|
24
|
-
|
|
25
|
+
items,
|
|
25
26
|
variant: AccordionVariant.Basic,
|
|
27
|
+
invert: false,
|
|
28
|
+
level: 0,
|
|
26
29
|
};
|
|
27
30
|
|
|
28
|
-
it('renders without error', () => {
|
|
31
|
+
it('1. renders without error', () => {
|
|
29
32
|
const { getByTestId } = render(<NsAccordion {...defaultProps} />);
|
|
30
33
|
const accordion = getByTestId(defaultProps.additionalProps.testid);
|
|
31
34
|
expect(accordion).toBeInTheDocument();
|
|
32
35
|
});
|
|
33
36
|
|
|
34
|
-
it(`only first section should be visible when allowMultipleExpanded prop is false and multiple items have
|
|
35
|
-
|
|
37
|
+
it(`2. only first section should be visible when allowMultipleExpanded prop is false and multiple items have
|
|
38
|
+
isDefaultOpen true`, () => {
|
|
36
39
|
const { getAllByText } = render(<NsAccordion {...defaultProps} />);
|
|
37
40
|
const [title1, title2, title3] = getAllByText(/Title /i);
|
|
38
41
|
|
|
39
42
|
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
40
43
|
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
41
44
|
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
45
|
+
const [c1, c2, c3] = getAllByText(/Content /i);
|
|
46
|
+
expect(c1.parentNode).toHaveStyle('opacity: 1');
|
|
47
|
+
expect(c2.parentNode).toHaveStyle('opacity: 0');
|
|
48
|
+
expect(c3.parentNode).toHaveStyle('opacity: 0');
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
it(
|
|
51
|
+
it(`3. expands second section only when allowMultipleExpanded
|
|
52
|
+
prop is false and second title is clicked`, async () => {
|
|
48
53
|
const { getAllByText } = render(<NsAccordion {...defaultProps} />);
|
|
49
54
|
const [title1, title2, title3] = getAllByText(/Title /i);
|
|
50
55
|
const header = title2.closest('header');
|
|
@@ -54,40 +59,104 @@ describe('NsAccordion', () => {
|
|
|
54
59
|
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
55
60
|
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
56
61
|
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
57
|
-
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
62
|
+
const [c1, c2, c3] = getAllByText(/Content /i);
|
|
63
|
+
expect(c1.parentNode).toHaveStyle('opacity: 0');
|
|
64
|
+
expect(c2.parentNode).toHaveStyle('opacity: 1');
|
|
65
|
+
expect(c3.parentNode).toHaveStyle('opacity: 0');
|
|
60
66
|
}
|
|
61
67
|
});
|
|
62
68
|
|
|
63
|
-
it('expands multiple sections by default when allowMultipleExpanded prop is true', () => {
|
|
64
|
-
const
|
|
65
|
-
|
|
69
|
+
it('4. expands multiple sections by default when allowMultipleExpanded prop is true', () => {
|
|
70
|
+
const items = generateContentArray(3);
|
|
71
|
+
items[2].isDefaultOpen = false;
|
|
66
72
|
const defaultProps = {
|
|
67
|
-
additionalProps: {
|
|
68
|
-
testid: 'test-accordion',
|
|
69
|
-
},
|
|
70
73
|
allowMultipleExpanded: false,
|
|
71
|
-
|
|
74
|
+
items,
|
|
72
75
|
variant: AccordionVariant.Basic,
|
|
76
|
+
level: 0,
|
|
77
|
+
invert: false,
|
|
73
78
|
};
|
|
74
79
|
const { getAllByText } = render(<NsAccordion {...defaultProps} allowMultipleExpanded />);
|
|
80
|
+
const accordion = screen.getByTestId('ns-accordion-testid');
|
|
81
|
+
expect(accordion).toBeDefined();
|
|
75
82
|
const [title1, title2, title3] = getAllByText(/Title /i);
|
|
76
83
|
|
|
77
84
|
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
78
85
|
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
79
86
|
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(
|
|
87
|
+
|
|
88
|
+
const [c1, c2, c3] = getAllByText(/Content /i);
|
|
89
|
+
expect(c1.parentNode).toHaveStyle('opacity: 1');
|
|
90
|
+
expect(c2.parentNode).toHaveStyle('opacity: 1');
|
|
91
|
+
expect(c3.parentNode).toHaveStyle('opacity: 0');
|
|
83
92
|
|
|
84
93
|
fireEvent.click(title3);
|
|
85
94
|
|
|
86
95
|
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
87
96
|
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
88
97
|
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect(
|
|
98
|
+
|
|
99
|
+
const [c11, c12, c13] = getAllByText(/Content /i);
|
|
100
|
+
expect(c11.parentNode).toHaveStyle('opacity: 1');
|
|
101
|
+
expect(c12.parentNode).toHaveStyle('opacity: 1');
|
|
102
|
+
expect(c13.parentNode).toHaveStyle('opacity: 1');
|
|
103
|
+
});
|
|
104
|
+
it(`5. closes second section also when allowMultipleExpanded
|
|
105
|
+
prop is true and second title is clicked`, async () => {
|
|
106
|
+
const items = generateContentArray(3);
|
|
107
|
+
const defaultProps = {
|
|
108
|
+
additionalProps: {
|
|
109
|
+
testid: 'test-accordion',
|
|
110
|
+
},
|
|
111
|
+
allowMultipleExpanded: true,
|
|
112
|
+
items,
|
|
113
|
+
variant: AccordionVariant.Basic,
|
|
114
|
+
invert: false,
|
|
115
|
+
level: 0,
|
|
116
|
+
};
|
|
117
|
+
const { getAllByText } = render(<NsAccordion {...defaultProps} />);
|
|
118
|
+
const [title1, title2, title3] = getAllByText(/Title /i);
|
|
119
|
+
const header = title2.closest('header');
|
|
120
|
+
expect(header).toHaveAttribute('aria-expanded', 'true');
|
|
121
|
+
if (header) {
|
|
122
|
+
fireEvent.click(header);
|
|
123
|
+
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
124
|
+
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
125
|
+
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
126
|
+
|
|
127
|
+
const [c1, c2, c3] = getAllByText(/Content /i);
|
|
128
|
+
expect(c1.parentNode).toHaveStyle('opacity: 1');
|
|
129
|
+
expect(c2.parentNode).toHaveStyle('opacity: 0');
|
|
130
|
+
expect(c3.parentNode).toHaveStyle('opacity: 1');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
it(`6. closes second section also when allowMultipleExpanded
|
|
134
|
+
prop is true and second title is clicked`, async () => {
|
|
135
|
+
const items = generateContentArray(3, false);
|
|
136
|
+
items[1].isDefaultOpen = true;
|
|
137
|
+
const defaultProps = {
|
|
138
|
+
additionalProps: {
|
|
139
|
+
testid: 'test-accordion',
|
|
140
|
+
},
|
|
141
|
+
allowMultipleExpanded: false,
|
|
142
|
+
items,
|
|
143
|
+
variant: AccordionVariant.Compact,
|
|
144
|
+
level: 0,
|
|
145
|
+
invert: false,
|
|
146
|
+
};
|
|
147
|
+
const { getAllByText } = render(<NsAccordion {...defaultProps} />);
|
|
148
|
+
const [title1, title2, title3] = getAllByText(/Title /i);
|
|
149
|
+
const header = title2.closest('header');
|
|
150
|
+
expect(header).toHaveAttribute('aria-expanded', 'true');
|
|
151
|
+
if (header) {
|
|
152
|
+
fireEvent.click(header);
|
|
153
|
+
expect(title1.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
154
|
+
expect(title2.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
155
|
+
expect(title3.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
156
|
+
const [c1, c2, c3] = getAllByText(/Content /i);
|
|
157
|
+
expect(c1.parentNode).toHaveStyle('opacity: 0');
|
|
158
|
+
expect(c2.parentNode).toHaveStyle('opacity: 0');
|
|
159
|
+
expect(c3.parentNode).toHaveStyle('opacity: 0');
|
|
160
|
+
}
|
|
92
161
|
});
|
|
93
162
|
});
|
|
@@ -3,7 +3,7 @@ import { render, fireEvent } from '@/test-utils/index';
|
|
|
3
3
|
import { NsAccordionHeader, AccordionVariant } from '@/common/index';
|
|
4
4
|
|
|
5
5
|
describe('NsAccordionHeader', () => {
|
|
6
|
-
it('renders title correctly', () => {
|
|
6
|
+
it('1. renders title correctly', () => {
|
|
7
7
|
const onClick = jest.fn();
|
|
8
8
|
const title = 'Section Header';
|
|
9
9
|
const { getByText } = render(
|
|
@@ -11,19 +11,41 @@ describe('NsAccordionHeader', () => {
|
|
|
11
11
|
variant={AccordionVariant.Basic}
|
|
12
12
|
title={title}
|
|
13
13
|
onClick={onClick}
|
|
14
|
+
invert={false}
|
|
15
|
+
isOpen={true}
|
|
14
16
|
/>
|
|
15
17
|
);
|
|
16
|
-
|
|
18
|
+
const el = getByText(title);
|
|
19
|
+
expect(el).toBeInTheDocument();
|
|
20
|
+
expect(el.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
17
21
|
});
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
it('2. renders title correctly', () => {
|
|
23
|
+
const onClick = jest.fn();
|
|
24
|
+
const title = 'Section Header';
|
|
25
|
+
const { getByText } = render(
|
|
26
|
+
<NsAccordionHeader
|
|
27
|
+
variant={AccordionVariant.Compact}
|
|
28
|
+
title={<span>{title}</span>}
|
|
29
|
+
onClick={onClick}
|
|
30
|
+
invert={false}
|
|
31
|
+
isOpen={false}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
const el = getByText(title);
|
|
35
|
+
expect(el).toBeInTheDocument();
|
|
36
|
+
expect(el.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
37
|
+
});
|
|
38
|
+
it('3. calls onClick handler when clicked', () => {
|
|
20
39
|
const onClick = jest.fn();
|
|
21
40
|
const { container } = render(
|
|
22
41
|
<NsAccordionHeader
|
|
23
42
|
variant={AccordionVariant.Basic}
|
|
24
43
|
title="Section Header"
|
|
25
44
|
onClick={onClick}
|
|
26
|
-
|
|
45
|
+
invert={false}
|
|
46
|
+
isOpen={false}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
27
49
|
const header = container.querySelector('header');
|
|
28
50
|
if (header) {
|
|
29
51
|
fireEvent.click(header);
|
|
@@ -31,33 +53,78 @@ describe('NsAccordionHeader', () => {
|
|
|
31
53
|
}
|
|
32
54
|
});
|
|
33
55
|
|
|
34
|
-
it('renders with additional class name', () => {
|
|
56
|
+
it('4. renders with additional class name', () => {
|
|
35
57
|
const additionalClassName = 'custom-class';
|
|
36
58
|
const onClick = jest.fn();
|
|
37
59
|
const { container } = render(
|
|
38
60
|
<NsAccordionHeader
|
|
61
|
+
isOpen={false}
|
|
39
62
|
variant={AccordionVariant.Basic}
|
|
40
63
|
title="Section Header"
|
|
41
64
|
additionalProps={{ className: additionalClassName }}
|
|
42
65
|
onClick={onClick}
|
|
66
|
+
invert={false}
|
|
43
67
|
/>
|
|
44
68
|
);
|
|
45
69
|
expect(container.querySelector('header')).toHaveClass(`section-header ${additionalClassName}`);
|
|
46
70
|
});
|
|
47
71
|
|
|
48
|
-
it('renders with expanded class when isOpen is true', () => {
|
|
72
|
+
it('5. renders with expanded class when isOpen is true', () => {
|
|
49
73
|
const onClick = jest.fn();
|
|
50
74
|
const { container } = render(
|
|
51
|
-
<NsAccordionHeader
|
|
75
|
+
<NsAccordionHeader
|
|
76
|
+
variant={AccordionVariant.Basic}
|
|
77
|
+
title="Section Header"
|
|
78
|
+
isOpen
|
|
79
|
+
onClick={onClick}
|
|
80
|
+
invert={false}
|
|
81
|
+
/>
|
|
52
82
|
);
|
|
53
83
|
expect(container.querySelector('header')).toHaveClass('expanded');
|
|
54
84
|
});
|
|
55
85
|
|
|
56
|
-
it('renders with header icon', () => {
|
|
86
|
+
it('6. renders with header icon', () => {
|
|
57
87
|
const onClick = jest.fn();
|
|
58
88
|
const { getByTestId } = render(
|
|
59
|
-
<NsAccordionHeader
|
|
89
|
+
<NsAccordionHeader
|
|
90
|
+
variant={AccordionVariant.Basic}
|
|
91
|
+
title="Section Header"
|
|
92
|
+
onClick={onClick}
|
|
93
|
+
invert={false}
|
|
94
|
+
isOpen
|
|
95
|
+
/>
|
|
60
96
|
);
|
|
97
|
+
// this icon refers to end icon which is either arrowUp or arrowDown
|
|
61
98
|
expect(getByTestId('icon')).toBeInTheDocument();
|
|
62
99
|
});
|
|
100
|
+
it('7. renders with custom start icon', () => {
|
|
101
|
+
const onClick = jest.fn();
|
|
102
|
+
const { getByTestId } = render(
|
|
103
|
+
<NsAccordionHeader
|
|
104
|
+
variant={AccordionVariant.Basic}
|
|
105
|
+
title="Section Header"
|
|
106
|
+
onClick={onClick}
|
|
107
|
+
invert={false}
|
|
108
|
+
isOpen
|
|
109
|
+
startIcon={{ name: 'hamburgerIcon', testId: 'hamburger-test' }}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
expect(getByTestId('hamburger-test')).toBeInTheDocument();
|
|
113
|
+
});
|
|
114
|
+
it('8. does not render start icon, when invalid icon name is passed', () => {
|
|
115
|
+
const onClick = jest.fn();
|
|
116
|
+
const invalidIconName = 'hambur';
|
|
117
|
+
const testId = 'hamburger-test';
|
|
118
|
+
const { queryByTestId } = render(
|
|
119
|
+
<NsAccordionHeader
|
|
120
|
+
variant={AccordionVariant.Basic}
|
|
121
|
+
title="Section Header"
|
|
122
|
+
onClick={onClick}
|
|
123
|
+
invert={false}
|
|
124
|
+
isOpen
|
|
125
|
+
startIcon={{ name: invalidIconName as any, testId }}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
expect(queryByTestId(testId)).toBeNull();
|
|
129
|
+
});
|
|
63
130
|
});
|
|
@@ -5,21 +5,24 @@ import { NsAccordionItem, AccordionVariant } from '@/common/index';
|
|
|
5
5
|
describe('NsAccordionItem', () => {
|
|
6
6
|
const title = 'Accordion Section Title';
|
|
7
7
|
const content = 'Accordion Section Content';
|
|
8
|
-
|
|
9
|
-
it('renders title correctly', () => {
|
|
8
|
+
const contentElement = <div className="p-2">{content}</div>;
|
|
9
|
+
it('1. renders title correctly', () => {
|
|
10
10
|
const { getByText } = render(
|
|
11
11
|
<NsAccordionItem
|
|
12
12
|
variant={AccordionVariant.Basic}
|
|
13
13
|
isOpen={false}
|
|
14
14
|
toggleOpen={() => {}}
|
|
15
15
|
title={title}
|
|
16
|
-
content={
|
|
16
|
+
content={contentElement}
|
|
17
|
+
isChild={false}
|
|
18
|
+
invert={false}
|
|
19
|
+
level={1}
|
|
17
20
|
/>
|
|
18
21
|
);
|
|
19
22
|
expect(getByText(title)).toBeInTheDocument();
|
|
20
23
|
});
|
|
21
24
|
|
|
22
|
-
it('calls toggleOpen function when clicked on the section header', () => {
|
|
25
|
+
it('2. calls toggleOpen function when clicked on the section header', () => {
|
|
23
26
|
const toggleOpen = jest.fn();
|
|
24
27
|
const { getByText } = render(
|
|
25
28
|
<NsAccordionItem
|
|
@@ -27,36 +30,46 @@ describe('NsAccordionItem', () => {
|
|
|
27
30
|
isOpen={false}
|
|
28
31
|
toggleOpen={toggleOpen}
|
|
29
32
|
title={title}
|
|
30
|
-
content={
|
|
33
|
+
content={contentElement}
|
|
34
|
+
isChild={false}
|
|
35
|
+
invert={false}
|
|
36
|
+
level={1}
|
|
31
37
|
/>
|
|
32
38
|
);
|
|
33
39
|
fireEvent.click(getByText(title));
|
|
34
40
|
expect(toggleOpen).toHaveBeenCalledTimes(1);
|
|
35
41
|
});
|
|
36
42
|
|
|
37
|
-
it('renders content when isOpen is true', () => {
|
|
43
|
+
it('3. renders content when isOpen is true', () => {
|
|
38
44
|
const { getByText } = render(
|
|
39
45
|
<NsAccordionItem
|
|
40
46
|
variant={AccordionVariant.Basic}
|
|
41
47
|
isOpen={true}
|
|
42
48
|
toggleOpen={() => {}}
|
|
43
49
|
title={title}
|
|
44
|
-
content={
|
|
50
|
+
content={contentElement}
|
|
51
|
+
isChild={false}
|
|
52
|
+
invert={false}
|
|
53
|
+
level={1}
|
|
45
54
|
/>
|
|
46
55
|
);
|
|
47
56
|
expect(getByText(content)).toBeInTheDocument();
|
|
48
57
|
});
|
|
49
58
|
|
|
50
|
-
it('
|
|
59
|
+
it('4. when isOpen is false, renders jsx dom content within container with 0 height', () => {
|
|
51
60
|
const { queryByText } = render(
|
|
52
61
|
<NsAccordionItem
|
|
53
62
|
variant={AccordionVariant.Basic}
|
|
54
63
|
isOpen={false}
|
|
55
64
|
toggleOpen={() => {}}
|
|
56
65
|
title={title}
|
|
57
|
-
content={
|
|
66
|
+
content={contentElement}
|
|
67
|
+
isChild={false}
|
|
68
|
+
invert={false}
|
|
69
|
+
level={1}
|
|
58
70
|
/>
|
|
59
71
|
);
|
|
60
|
-
|
|
72
|
+
const bodyElement = queryByText(content);
|
|
73
|
+
expect(bodyElement?.parentNode).toHaveStyle('height:0px;');
|
|
61
74
|
});
|
|
62
75
|
});
|
|
@@ -1,36 +1,125 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@/test-utils/index';
|
|
3
|
-
import { NsCollapse, AccordionVariant } from '@/common/index';
|
|
3
|
+
import { NsCollapse, AccordionVariant, ItemContent } from '@/common/index';
|
|
4
|
+
import { createAccordionItem3_1, getTextContent } from '../stories/data';
|
|
4
5
|
|
|
5
6
|
describe('NsCollapse', () => {
|
|
6
|
-
it('renders children when isOpen is true', () => {
|
|
7
|
+
it('1. renders children when isOpen is true', () => {
|
|
7
8
|
const { getByText } = render(
|
|
8
|
-
<NsCollapse
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
<NsCollapse
|
|
10
|
+
isOpen
|
|
11
|
+
variant={AccordionVariant.Basic}
|
|
12
|
+
content={
|
|
13
|
+
<>
|
|
14
|
+
<div>Child 1</div>
|
|
15
|
+
<div>Child 2</div>
|
|
16
|
+
</>
|
|
17
|
+
}
|
|
18
|
+
isChild={false}
|
|
19
|
+
invert={false}
|
|
20
|
+
level={0}
|
|
21
|
+
/>
|
|
12
22
|
);
|
|
13
23
|
expect(getByText('Child 1')).toBeInTheDocument();
|
|
14
24
|
expect(getByText('Child 2')).toBeInTheDocument();
|
|
15
25
|
});
|
|
26
|
+
it('2. renders children when isOpen is true and isChild is true', () => {
|
|
27
|
+
const text = '1. Theme can be set';
|
|
28
|
+
const content = { ...getTextContent(text) };
|
|
29
|
+
const { getByText } = render(
|
|
30
|
+
<NsCollapse
|
|
31
|
+
isOpen
|
|
32
|
+
variant={AccordionVariant.Basic}
|
|
33
|
+
content={content}
|
|
34
|
+
isChild={true}
|
|
35
|
+
invert={false}
|
|
36
|
+
level={0}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
expect(getByText(text)).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
it('3. renders children when isOpen is true and variant is compact and content is of type accordion', () => {
|
|
42
|
+
const { getByText } = render(
|
|
43
|
+
<NsCollapse
|
|
44
|
+
isOpen
|
|
45
|
+
variant={AccordionVariant.Compact}
|
|
46
|
+
content={createAccordionItem3_1().content}
|
|
47
|
+
isChild={true}
|
|
48
|
+
invert={false}
|
|
49
|
+
level={0}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
expect(getByText('Example - 3.1.1')).toBeInTheDocument();
|
|
53
|
+
expect(getByText('Example - 3.1.2')).toBeInTheDocument();
|
|
54
|
+
});
|
|
16
55
|
|
|
17
|
-
it('does not render children when isOpen is false', () => {
|
|
56
|
+
it('4. does not render children when isOpen is false', () => {
|
|
57
|
+
render(
|
|
58
|
+
<NsCollapse
|
|
59
|
+
isOpen={false}
|
|
60
|
+
variant={AccordionVariant.Basic}
|
|
61
|
+
content={{
|
|
62
|
+
type: 'html',
|
|
63
|
+
data: '<h2>Lorem ipsum dolor sit amet.</h2>',
|
|
64
|
+
}}
|
|
65
|
+
isChild={false}
|
|
66
|
+
invert={true}
|
|
67
|
+
level={0}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
expect(screen.queryByText('Lorenm')).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
it('5. renders html children when isOpen is true', () => {
|
|
18
73
|
render(
|
|
19
|
-
<NsCollapse
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
74
|
+
<NsCollapse
|
|
75
|
+
isOpen={true}
|
|
76
|
+
variant={AccordionVariant.Compact}
|
|
77
|
+
content={{
|
|
78
|
+
type: 'html',
|
|
79
|
+
data: '<h2>Lorem ipsum dolor sit amet.</h2>',
|
|
80
|
+
}}
|
|
81
|
+
isChild={false}
|
|
82
|
+
invert={true}
|
|
83
|
+
level={0}
|
|
84
|
+
/>
|
|
23
85
|
);
|
|
24
|
-
expect(screen.queryByText('
|
|
86
|
+
expect(screen.queryByText('Lorem')).toBeDefined();
|
|
25
87
|
});
|
|
26
88
|
|
|
27
|
-
it('renders with additional class name', () => {
|
|
89
|
+
it('6. renders with additional class name', () => {
|
|
90
|
+
const additionalClassName = 'custom-class';
|
|
91
|
+
const { container } = render(
|
|
92
|
+
<NsCollapse
|
|
93
|
+
isOpen
|
|
94
|
+
variant={AccordionVariant.Gray}
|
|
95
|
+
content={
|
|
96
|
+
<>
|
|
97
|
+
<div>Child 1</div>
|
|
98
|
+
<div>Child 2</div>
|
|
99
|
+
</>
|
|
100
|
+
}
|
|
101
|
+
additionalProps={{ className: additionalClassName }}
|
|
102
|
+
isChild={false}
|
|
103
|
+
invert={false}
|
|
104
|
+
level={7}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
expect(container.querySelector('section')).toHaveClass(`ns-collapse ${additionalClassName}`);
|
|
108
|
+
});
|
|
109
|
+
it('7. skipping allowMultipleExpanded in child data', () => {
|
|
110
|
+
const { content } = createAccordionItem3_1();
|
|
111
|
+
delete (content as ItemContent).allowMultipleExpanded;
|
|
28
112
|
const additionalClassName = 'custom-class';
|
|
29
113
|
const { container } = render(
|
|
30
|
-
<NsCollapse
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
114
|
+
<NsCollapse
|
|
115
|
+
isOpen
|
|
116
|
+
variant={AccordionVariant.Gray}
|
|
117
|
+
content={content}
|
|
118
|
+
additionalProps={{ className: additionalClassName }}
|
|
119
|
+
isChild={false}
|
|
120
|
+
invert={true}
|
|
121
|
+
level={7}
|
|
122
|
+
/>
|
|
34
123
|
);
|
|
35
124
|
expect(container.querySelector('section')).toHaveClass(`ns-collapse ${additionalClassName}`);
|
|
36
125
|
});
|
|
@@ -6,33 +6,65 @@ import { render, fireEvent } from '@/test-utils/index';
|
|
|
6
6
|
|
|
7
7
|
describe('NsToggleSection', () => {
|
|
8
8
|
const title = 'Toggle Section Title';
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
it('renders title correctly', () => {
|
|
9
|
+
const contentText = 'Toggle Section Content';
|
|
10
|
+
const content = <div className="p-2">{contentText}</div>;
|
|
11
|
+
it('1. renders title correctly', () => {
|
|
12
12
|
const { getByText } = render(
|
|
13
|
-
<NsToggleSection
|
|
13
|
+
<NsToggleSection
|
|
14
|
+
variant={AccordionVariant.Basic}
|
|
15
|
+
title={title}
|
|
16
|
+
content={content}
|
|
17
|
+
invert={false}
|
|
18
|
+
isChild={false}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
expect(getByText(title)).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
it('2. renders title correctly', () => {
|
|
24
|
+
const { getByText } = render(
|
|
25
|
+
<NsToggleSection
|
|
26
|
+
variant={AccordionVariant.Compact}
|
|
27
|
+
title={title}
|
|
28
|
+
content={content}
|
|
29
|
+
invert={false}
|
|
30
|
+
isChild={false}
|
|
31
|
+
/>
|
|
14
32
|
);
|
|
15
33
|
expect(getByText(title)).toBeInTheDocument();
|
|
16
34
|
});
|
|
17
35
|
|
|
18
|
-
it('toggles content visibility when clicked on the section header', () => {
|
|
36
|
+
it('2. toggles content visibility when clicked on the section header', () => {
|
|
19
37
|
const { getByText, queryByText } = render(
|
|
20
|
-
<NsToggleSection
|
|
38
|
+
<NsToggleSection
|
|
39
|
+
variant={AccordionVariant.Basic}
|
|
40
|
+
title={title}
|
|
41
|
+
content={content}
|
|
42
|
+
invert={false}
|
|
43
|
+
isChild={false}
|
|
44
|
+
/>
|
|
21
45
|
);
|
|
22
|
-
|
|
46
|
+
const el = queryByText(contentText);
|
|
47
|
+
expect(el?.parentNode).toHaveStyle('opacity: 0;');
|
|
48
|
+
|
|
23
49
|
fireEvent.click(getByText(title));
|
|
24
|
-
expect(
|
|
50
|
+
expect(el?.parentNode).toHaveStyle('opacity: 1;');
|
|
51
|
+
|
|
25
52
|
fireEvent.click(getByText(title));
|
|
26
|
-
expect(
|
|
53
|
+
expect(el?.parentNode).toHaveStyle('opacity: 0;');
|
|
27
54
|
});
|
|
28
55
|
|
|
29
|
-
it('sets defaultOpen prop correctly', () => {
|
|
56
|
+
it('3. sets defaultOpen prop correctly', () => {
|
|
30
57
|
const { getByText } = render(
|
|
31
|
-
<NsToggleSection
|
|
32
|
-
{
|
|
33
|
-
|
|
58
|
+
<NsToggleSection
|
|
59
|
+
variant={AccordionVariant.Basic}
|
|
60
|
+
title={title}
|
|
61
|
+
content={content}
|
|
62
|
+
invert={false}
|
|
63
|
+
isChild={false}
|
|
64
|
+
defaultOpen
|
|
65
|
+
/>
|
|
34
66
|
);
|
|
35
67
|
|
|
36
|
-
expect(getByText(
|
|
68
|
+
expect(getByText(contentText)).toBeInTheDocument();
|
|
37
69
|
});
|
|
38
70
|
});
|