|
1 | 1 | import React from 'react'; |
2 | 2 | import { render, screen } from '@testing-library/react'; |
3 | 3 | import { DescriptionList } from '../DescriptionList'; |
4 | | -import { DescriptionListGroup } from '../DescriptionListGroup'; |
5 | | -import { DescriptionListTerm } from '../DescriptionListTerm'; |
6 | | -import { DescriptionListDescription } from '../DescriptionListDescription'; |
7 | | -import { DescriptionListTermHelpText } from '../DescriptionListTermHelpText'; |
8 | | -import { DescriptionListTermHelpTextButton } from '../DescriptionListTermHelpTextButton'; |
9 | 4 |
|
10 | 5 | import styles from '@patternfly/react-styles/css/components/DescriptionList/description-list'; |
11 | 6 |
|
12 | | -test('renders to match snapshot', () => { |
13 | | - const { asFragment } = render(<DescriptionList aria-label="list" />); |
14 | | - expect(screen.getByLabelText('list')).toBeInTheDocument(); |
| 7 | +test('Renders to match snapshot', () => { |
| 8 | + const { asFragment } = render(<DescriptionList />); |
15 | 9 | expect(asFragment()).toMatchSnapshot(); |
16 | 10 | }); |
17 | 11 |
|
18 | | -test('renders custom className', () => { |
19 | | - render(<DescriptionList aria-label="list" className="custom" />); |
20 | | - expect(screen.getByLabelText('list')).toHaveClass('custom'); |
| 12 | +test(`Renders default class ${styles.descriptionList}`, () => { |
| 13 | + render(<DescriptionList aria-label="list" />); |
| 14 | + expect(screen.getByLabelText('list')).toHaveClass(styles.descriptionList); |
21 | 15 | }); |
22 | 16 |
|
23 | | -test('renders 1Col on all breakpoints', () => { |
24 | | - render( |
25 | | - <DescriptionList |
26 | | - aria-label="list" |
27 | | - columnModifier={{ default: '1Col', sm: '1Col', md: '1Col', lg: '1Col', xl: '1Col', '2xl': '1Col' }} |
28 | | - /> |
29 | | - ); |
30 | | - expect(screen.getByLabelText('list')).toHaveClass( |
31 | | - styles.modifiers['1Col'], |
32 | | - styles.modifiers['1ColOnSm'], |
33 | | - styles.modifiers['1ColOnMd'], |
34 | | - styles.modifiers['1ColOnLg'], |
35 | | - styles.modifiers['1ColOnXl'], |
36 | | - styles.modifiers['1ColOn_2xl'] |
37 | | - ); |
38 | | -}); |
39 | | - |
40 | | -test('renders 2Col on all breakpoints', () => { |
41 | | - render( |
42 | | - <DescriptionList |
43 | | - aria-label="list" |
44 | | - columnModifier={{ default: '2Col', sm: '2Col', md: '2Col', lg: '2Col', xl: '2Col', '2xl': '2Col' }} |
45 | | - /> |
46 | | - ); |
47 | | - expect(screen.getByLabelText('list')).toHaveClass( |
48 | | - styles.modifiers['2Col'], |
49 | | - styles.modifiers['2ColOnSm'], |
50 | | - styles.modifiers['2ColOnMd'], |
51 | | - styles.modifiers['2ColOnLg'], |
52 | | - styles.modifiers['2ColOnXl'], |
53 | | - styles.modifiers['2ColOn_2xl'] |
54 | | - ); |
55 | | -}); |
56 | | - |
57 | | -test('renders 3Col on all breakpoints', () => { |
58 | | - render( |
59 | | - <DescriptionList |
60 | | - aria-label="list" |
61 | | - columnModifier={{ default: '3Col', sm: '3Col', md: '3Col', lg: '3Col', xl: '3Col', '2xl': '3Col' }} |
62 | | - /> |
63 | | - ); |
64 | | - expect(screen.getByLabelText('list')).toHaveClass( |
65 | | - styles.modifiers['3Col'], |
66 | | - styles.modifiers['3ColOnSm'], |
67 | | - styles.modifiers['3ColOnMd'], |
68 | | - styles.modifiers['3ColOnLg'], |
69 | | - styles.modifiers['3ColOnXl'], |
70 | | - styles.modifiers['3ColOn_2xl'] |
71 | | - ); |
| 17 | +test('Renders custom className', () => { |
| 18 | + render(<DescriptionList aria-label="list" className="custom" />); |
| 19 | + expect(screen.getByLabelText('list')).toHaveClass('custom'); |
72 | 20 | }); |
73 | 21 |
|
74 | | -test(`renders ${styles.modifiers.horizontal} when isHorizontal = true`, () => { |
| 22 | +Object.values(['1Col', '2Col', '3Col']).forEach((_col) => { |
| 23 | + const col = _col as '1Col' | '2Col' | '3Col'; |
| 24 | + test(`Renders ${col} on all breakpoints`, () => { |
| 25 | + render( |
| 26 | + <DescriptionList |
| 27 | + aria-label="list" |
| 28 | + columnModifier={{ default: col, sm: col, md: col, lg: col, xl: col, '2xl': col }} |
| 29 | + /> |
| 30 | + ); |
| 31 | + expect(screen.getByLabelText('list')).toHaveClass( |
| 32 | + styles.modifiers[col], |
| 33 | + styles.modifiers[`${col}OnSm`], |
| 34 | + styles.modifiers[`${col}OnMd`], |
| 35 | + styles.modifiers[`${col}OnLg`], |
| 36 | + styles.modifiers[`${col}OnXl`], |
| 37 | + styles.modifiers[`${col}On_2xl`] |
| 38 | + ); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +test(`Renders ${styles.modifiers.horizontal} when isHorizontal = true`, () => { |
75 | 43 | render(<DescriptionList aria-label="list" isHorizontal />); |
76 | 44 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.horizontal); |
77 | 45 | }); |
78 | 46 |
|
79 | | -test(`renders ${styles.modifiers.compact} when isCompact = true`, () => { |
| 47 | +test(`Renders ${styles.modifiers.compact} when isCompact = true`, () => { |
80 | 48 | render(<DescriptionList aria-label="list" isCompact />); |
81 | 49 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.compact); |
82 | 50 | }); |
83 | 51 |
|
84 | | -test(`renders ${styles.modifiers.horizontal} and ${styles.modifiers.fluid} when isFluid = true`, () => { |
| 52 | +test(`Renders ${styles.modifiers.horizontal} and ${styles.modifiers.fluid} when isFluid = true`, () => { |
85 | 53 | render(<DescriptionList aria-label="list" isFluid />); |
86 | 54 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.fluid, styles.modifiers.horizontal); |
87 | 55 | }); |
88 | 56 |
|
89 | | -test('renders alignment breakpoints', () => { |
90 | | - render( |
91 | | - <DescriptionList |
92 | | - aria-label="list" |
93 | | - isHorizontal |
94 | | - orientation={{ |
95 | | - sm: 'horizontal', |
96 | | - md: 'vertical', |
97 | | - lg: 'horizontal', |
98 | | - xl: 'vertical', |
99 | | - '2xl': 'horizontal' |
100 | | - }} |
101 | | - /> |
102 | | - ); |
103 | | - expect(screen.getByLabelText('list')).toHaveClass( |
104 | | - styles.modifiers.horizontal, |
105 | | - styles.modifiers.horizontalOnSm, |
106 | | - styles.modifiers.verticalOnMd, |
107 | | - styles.modifiers.horizontalOnLg, |
108 | | - styles.modifiers.verticalOnXl, |
109 | | - styles.modifiers.horizontalOn_2xl |
110 | | - ); |
111 | | -}); |
112 | | - |
113 | | -test(`renders ${styles.modifiers.autoColumnWidths} when isAutoColumnWidths = true`, () => { |
| 57 | +Object.values(['horizontal', 'vertical']).forEach((_align) => { |
| 58 | + const align = _align as 'horizontal' | 'vertical'; |
| 59 | + test(`Renders ${align} on all breakpoints`, () => { |
| 60 | + render( |
| 61 | + <DescriptionList |
| 62 | + aria-label="list" |
| 63 | + orientation={{ |
| 64 | + sm: align, |
| 65 | + md: align, |
| 66 | + lg: align, |
| 67 | + xl: align, |
| 68 | + '2xl': align |
| 69 | + }} |
| 70 | + /> |
| 71 | + ); |
| 72 | + expect(screen.getByLabelText('list')).toHaveClass( |
| 73 | + styles.modifiers[`${align}OnSm`], |
| 74 | + styles.modifiers[`${align}OnMd`], |
| 75 | + styles.modifiers[`${align}OnLg`], |
| 76 | + styles.modifiers[`${align}OnXl`], |
| 77 | + styles.modifiers[`${align}On_2xl`] |
| 78 | + ); |
| 79 | + }); |
| 80 | +}); |
| 81 | + |
| 82 | +test(`Renders ${styles.modifiers.autoColumnWidths} when isAutoColumnWidths = true`, () => { |
114 | 83 | render(<DescriptionList aria-label="list" isAutoColumnWidths />); |
115 | 84 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.autoColumnWidths); |
116 | 85 | }); |
117 | 86 |
|
118 | | -test(`renders ${styles.modifiers.inlineGrid} when isInlineGrid = true`, () => { |
| 87 | +test(`Renders ${styles.modifiers.inlineGrid} when isInlineGrid = true`, () => { |
119 | 88 | render(<DescriptionList aria-label="list" isInlineGrid />); |
120 | 89 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.inlineGrid); |
121 | 90 | }); |
122 | 91 |
|
123 | | -test(`renders ${styles.modifiers.autoFit} when isAutoFit = true`, () => { |
| 92 | +test(`Renders ${styles.modifiers.autoFit} when isAutoFit = true`, () => { |
124 | 93 | render(<DescriptionList aria-label="list" isAutoFit />); |
125 | 94 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.autoFit); |
126 | 95 | }); |
127 | 96 |
|
128 | | -test(`renders ${styles.modifiers.fillColumns} when isFillColumns = true`, () => { |
| 97 | +test(`Renders ${styles.modifiers.fillColumns} when isFillColumns = true`, () => { |
129 | 98 | render(<DescriptionList aria-label="list" isFillColumns />); |
130 | 99 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.fillColumns); |
131 | 100 | }); |
132 | 101 |
|
133 | | -test(`renders ${styles.modifiers.displayLg} when displaySize = lg`, () => { |
| 102 | +test(`Renders ${styles.modifiers.displayLg} when displaySize = lg`, () => { |
134 | 103 | render(<DescriptionList aria-label="list" displaySize="lg" />); |
135 | 104 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.displayLg); |
136 | 105 | }); |
137 | 106 |
|
138 | | -test(`renders ${styles.modifiers.display_2xl} when displaySize = 2xl`, () => { |
| 107 | +test(`Renders ${styles.modifiers.display_2xl} when displaySize = 2xl`, () => { |
139 | 108 | render(<DescriptionList aria-label="list" displaySize="2xl" />); |
140 | 109 | expect(screen.getByLabelText('list')).toHaveClass(styles.modifiers.display_2xl); |
141 | 110 | }); |
142 | | - |
143 | | -test('DescriptionListTerm renders to match snapshot', () => { |
144 | | - const { asFragment } = render( |
145 | | - <DescriptionListTerm key="term-id-1" aria-labelledby="term-1"> |
146 | | - test |
147 | | - </DescriptionListTerm> |
148 | | - ); |
149 | | - expect(asFragment()).toMatchSnapshot(); |
150 | | -}); |
151 | | - |
152 | | -test('DescriptionListTerm renders custom className', () => { |
153 | | - render(<DescriptionListTerm className="custom">test</DescriptionListTerm>); |
154 | | - expect(screen.getByText('test').parentElement).toHaveClass('custom'); |
155 | | -}); |
156 | | - |
157 | | -test('DescriptionListTerm renders icon', () => { |
158 | | - render(<DescriptionListTerm icon={<div>icon</div>}>test</DescriptionListTerm>); |
159 | | - expect(screen.getByText('icon').parentElement).toHaveClass(styles.descriptionListTermIcon); |
160 | | -}); |
161 | | - |
162 | | -test('DescriptioinListTermHelpText renders to match snapshot', () => { |
163 | | - const { asFragment } = render( |
164 | | - <DescriptionListTermHelpText> |
165 | | - <DescriptionListTermHelpTextButton>test</DescriptionListTermHelpTextButton> |
166 | | - </DescriptionListTermHelpText> |
167 | | - ); |
168 | | - expect(asFragment()).toMatchSnapshot(); |
169 | | -}); |
170 | | - |
171 | | -test('DescriptioinListTermHelpText renders custom className', () => { |
172 | | - render( |
173 | | - <DescriptionListTermHelpText className="custom" aria-label="help-text"> |
174 | | - <DescriptionListTermHelpTextButton>test</DescriptionListTermHelpTextButton> |
175 | | - </DescriptionListTermHelpText> |
176 | | - ); |
177 | | - expect(screen.getByLabelText('help-text')).toHaveClass('custom'); |
178 | | -}); |
179 | | - |
180 | | -test('DescriptioinListTermHelpTextButton renders custom className', () => { |
181 | | - render( |
182 | | - <DescriptionListTermHelpText> |
183 | | - <DescriptionListTermHelpTextButton className="custom">test</DescriptionListTermHelpTextButton> |
184 | | - </DescriptionListTermHelpText> |
185 | | - ); |
186 | | - expect(screen.getByText('test')).toHaveClass('custom'); |
187 | | -}); |
188 | | - |
189 | | -test('DescriptionListGroup renders to match snapshot', () => { |
190 | | - const { asFragment } = render(<DescriptionListGroup>test</DescriptionListGroup>); |
191 | | - expect(asFragment()).toMatchSnapshot(); |
192 | | -}); |
193 | | - |
194 | | -test('DescriptionListGroup renders custom className', () => { |
195 | | - render(<DescriptionListGroup className="custom">test</DescriptionListGroup>); |
196 | | - expect(screen.getByText('test')).toHaveClass('custom'); |
197 | | -}); |
198 | | - |
199 | | -test('DescriptionListDescription renders to match snapshot', () => { |
200 | | - const { asFragment } = render(<DescriptionListDescription>test</DescriptionListDescription>); |
201 | | - expect(asFragment()).toMatchSnapshot(); |
202 | | -}); |
203 | | - |
204 | | -test('DescriptionListDescription renders custom className', () => { |
205 | | - render(<DescriptionListDescription className="custom">test</DescriptionListDescription>); |
206 | | - expect(screen.getByText('test').parentElement).toHaveClass('custom'); |
207 | | -}); |
0 commit comments