@@ -150,58 +150,66 @@ test('renders with inherited element props spread to the component', () => {
150150} ) ;
151151
152152describe ( '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` , ( ) => {
154154 render ( < Truncate maxCharsDisplayed = { 0 } data-testid = "truncate-component" content = "Test content" /> ) ;
155155
156- expect ( screen . getByTestId ( 'truncate-component' ) ) . not . toHaveClass ( 'class-tbd' ) ;
156+ expect ( screen . getByTestId ( 'truncate-component' ) ) . not . toHaveClass ( styles . modifiers . fixed ) ;
157157 } ) ;
158158
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` , ( ) => {
160160 render ( < Truncate maxCharsDisplayed = { 1 } data-testid = "truncate-component" content = "Test content" /> ) ;
161161
162- expect ( screen . getByTestId ( 'truncate-component' ) ) . toHaveClass ( 'class-tbd' ) ;
162+ expect ( screen . getByTestId ( 'truncate-component' ) ) . toHaveClass ( styles . modifiers . fixed ) ;
163163 } ) ;
164164
165165 test ( 'Renders with hidden truncated content at end by default when maxCharsDisplayed is passed' , ( ) => {
166166 render ( < Truncate content = "Default end position content truncated" maxCharsDisplayed = { 6 } /> ) ;
167167
168- expect ( screen . getByText ( 'Defaul' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
168+ expect ( screen . getByText ( 'Defaul' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
169169 expect ( screen . getByText ( 't end position content truncated' ) ) . toHaveClass ( 'pf-v6-screen-reader' ) ;
170170 } ) ;
171171
172172 test ( 'Renders with hidden truncated content at middle position when maxCharsDisplayed is passed and position="middle"' , ( ) => {
173173 render ( < Truncate position = "middle" content = "Middle position contents being truncated" maxCharsDisplayed = { 10 } /> ) ;
174174
175- expect ( screen . getByText ( 'Middl' ) ) . not . toHaveClass ( 'pf-v6-screen-reader' ) ;
175+ expect ( screen . getByText ( 'Middl' ) ) . toHaveClass ( ` ${ styles . truncate } __text` , { exact : true } ) ;
176176 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 } ) ;
178178 } ) ;
179179
180180 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 } /> ) ;
182182
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 } ) ;
185185 } ) ;
186186
187187 test ( 'Renders full content when maxCharsDisplayed exceeds the length of the content' , ( ) => {
188188 render ( < Truncate content = "This full content is rendered" maxCharsDisplayed = { 90 } /> ) ;
189189
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 } ) ;
191191 } ) ;
192192
193193 test ( 'Renders ellipsis as omission content by default' , ( ) => {
194194 render ( < Truncate content = "Test truncation content" maxCharsDisplayed = { 5 } /> ) ;
195195
196+ expect ( screen . getByText ( '\u2026' ) ) . toHaveClass ( `${ styles . truncate } __omission` , { exact : true } ) ;
196197 expect ( screen . getByText ( '\u2026' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
197198 } ) ;
198199
199200 test ( 'Renders custom omission content when omissionContent is passed' , ( ) => {
200201 render ( < Truncate omissionContent = "---" content = "Test truncation content" maxCharsDisplayed = { 5 } /> ) ;
201202
203+ expect ( screen . getByText ( '---' ) ) . toHaveClass ( `${ styles . truncate } __omission` , { exact : true } ) ;
202204 expect ( screen . getByText ( '---' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
203205 } ) ;
204206
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+
205213 test ( 'Matches snapshot with default position' , ( ) => {
206214 const { asFragment } = render ( < Truncate content = "Test truncation content" maxCharsDisplayed = { 3 } /> ) ;
207215
0 commit comments