@@ -150,58 +150,66 @@ test('renders with inherited element props spread to the component', () => {
150
150
} ) ;
151
151
152
152
describe ( 'Truncation with maxCharsDisplayed' , ( ) => {
153
- test ( `Does not render with class class-tbd when maxCharsDisplayed is 0` , ( ) => {
153
+ test ( `Does not render with class ${ styles . modifiers . fixed } when maxCharsDisplayed is 0` , ( ) => {
154
154
render ( < Truncate maxCharsDisplayed = { 0 } data-testid = "truncate-component" content = "Test content" /> ) ;
155
155
156
- expect ( screen . getByTestId ( 'truncate-component' ) ) . not . toHaveClass ( 'class-tbd' ) ;
156
+ expect ( screen . getByTestId ( 'truncate-component' ) ) . not . toHaveClass ( styles . modifiers . fixed ) ;
157
157
} ) ;
158
158
159
- test ( `Renders with class class-tbd when maxCharsDisplayed is greater than 0` , ( ) => {
159
+ test ( `Renders with class ${ styles . modifiers . fixed } when maxCharsDisplayed is greater than 0` , ( ) => {
160
160
render ( < Truncate maxCharsDisplayed = { 1 } data-testid = "truncate-component" content = "Test content" /> ) ;
161
161
162
- expect ( screen . getByTestId ( 'truncate-component' ) ) . toHaveClass ( 'class-tbd' ) ;
162
+ expect ( screen . getByTestId ( 'truncate-component' ) ) . toHaveClass ( styles . modifiers . fixed ) ;
163
163
} ) ;
164
164
165
165
test ( 'Renders with hidden truncated content at end by default when maxCharsDisplayed is passed' , ( ) => {
166
166
render ( < Truncate content = "Default end position content truncated" maxCharsDisplayed = { 6 } /> ) ;
167
167
168
- expect ( screen . getByText ( 'Defaul' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
168
+ expect ( screen . getByText ( 'Defaul' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
169
169
expect ( screen . getByText ( 't end position content truncated' ) ) . toHaveClass ( 'pf-v6-screen-reader' ) ;
170
170
} ) ;
171
171
172
172
test ( 'Renders with hidden truncated content at middle position when maxCharsDisplayed is passed and position="middle"' , ( ) => {
173
173
render ( < Truncate position = "middle" content = "Middle position contents being truncated" maxCharsDisplayed = { 10 } /> ) ;
174
174
175
- expect ( screen . getByText ( 'Middl' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
175
+ expect ( screen . getByText ( 'Middl' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
176
176
expect ( screen . getByText ( 'e position contents being trun' ) ) . toHaveClass ( 'pf-v6-screen-reader' ) ;
177
- expect ( screen . getByText ( 'cated' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
177
+ expect ( screen . getByText ( 'cated' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
178
178
} ) ;
179
179
180
180
test ( 'Renders with hidden truncated content at start when maxCharsDisplayed is passed and position="start"' , ( ) => {
181
- render ( < Truncate content = "Start position content truncated" maxCharsDisplayed = { 4 } /> ) ;
181
+ render ( < Truncate position = "start" content = "Start position content truncated" maxCharsDisplayed = { 6 } /> ) ;
182
182
183
- expect ( screen . getByText ( 'Star ' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
184
- expect ( screen . getByText ( 't position content truncated ' ) ) . toHaveClass ( 'pf-v6-screen-reader' ) ;
183
+ expect ( screen . getByText ( 'Start position content tru ' ) ) . toHaveClass ( 'pf-v6-screen-reader' ) ;
184
+ expect ( screen . getByText ( 'ncated ' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
185
185
} ) ;
186
186
187
187
test ( 'Renders full content when maxCharsDisplayed exceeds the length of the content' , ( ) => {
188
188
render ( < Truncate content = "This full content is rendered" maxCharsDisplayed = { 90 } /> ) ;
189
189
190
- expect ( screen . getByText ( 'This full content is rendered' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
190
+ expect ( screen . getByText ( 'This full content is rendered' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
191
191
} ) ;
192
192
193
193
test ( 'Renders ellipsis as omission content by default' , ( ) => {
194
194
render ( < Truncate content = "Test truncation content" maxCharsDisplayed = { 5 } /> ) ;
195
195
196
+ expect ( screen . getByText ( '\u2026' ) ) . toHaveClass ( `${ styles . truncate } __omission` , { exact : true } ) ;
196
197
expect ( screen . getByText ( '\u2026' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
197
198
} ) ;
198
199
199
200
test ( 'Renders custom omission content when omissionContent is passed' , ( ) => {
200
201
render ( < Truncate omissionContent = "---" content = "Test truncation content" maxCharsDisplayed = { 5 } /> ) ;
201
202
203
+ expect ( screen . getByText ( '---' ) ) . toHaveClass ( `${ styles . truncate } __omission` , { exact : true } ) ;
202
204
expect ( screen . getByText ( '---' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
203
205
} ) ;
204
206
207
+ test ( 'Does not render omission content when maxCharsDisplayed exceeds the length of the content ' , ( ) => {
208
+ render ( < Truncate content = "Test truncation content" maxCharsDisplayed = { 99 } /> ) ;
209
+
210
+ expect ( screen . queryByText ( '\u2026' ) ) . not . toBeInTheDocument ( ) ;
211
+ } ) ;
212
+
205
213
test ( 'Matches snapshot with default position' , ( ) => {
206
214
const { asFragment } = render ( < Truncate content = "Test truncation content" maxCharsDisplayed = { 3 } /> ) ;
207
215
0 commit comments