@@ -3,20 +3,20 @@ import { render } from "@testing-library/react";
33
44import "@testing-library/jest-dom" ;
55
6- import { IconButton } from "../../../index" ;
6+ import { Badge } from "../../../index" ;
77import { CLASSPREFIX as eccgui } from "../../configuration/constants" ;
88
99describe ( "Badge" , ( ) => {
10- it ( "should render badge markup with correct content when used on an icon button " , ( ) => {
11- const { container } = render ( < IconButton name = "item-info" badge = { "badge content" } / >) ;
12- const badge = container . querySelector ( `.${ eccgui } -badge ` ) ;
10+ it ( "should shorten a number badge exceeding maxLength to a 9+ notation " , ( ) => {
11+ const { container } = render ( < Badge maxLength = { 2 } > { 42 } </ Badge > ) ;
12+ const badge = container . querySelector ( `.${ eccgui } -badge__tag ` ) ;
1313 expect ( badge ) . not . toBeNull ( ) ;
14- expect ( badge ) . toHaveTextContent ( "badge content " ) ;
14+ expect ( badge ) . toHaveTextContent ( "9+ " ) ;
1515 } ) ;
16- it ( "should render badge markup with correct content when batch displays a 0 (zero) number on an icon button " , ( ) => {
17- const { container } = render ( < IconButton name = "item-info" badge = { 0 } / >) ;
18- const badge = container . querySelector ( `.${ eccgui } -badge ` ) ;
19- expect ( badge ) . not . toBeNull ( ) ;
20- expect ( badge ) . toHaveTextContent ( "0 ") ;
16+ it ( "should apply maxWidth style to a string badge when maxLength is set " , ( ) => {
17+ const { container } = render ( < Badge maxLength = { 4 } > forty two </ Badge > ) ;
18+ const tag = container . querySelector ( `.${ eccgui } -badge__tag ` ) ;
19+ expect ( tag ) . not . toBeNull ( ) ;
20+ expect ( ( tag as HTMLElement ) . style . maxWidth ) . toBe ( "calc((3em + 3ch)/2) ") ;
2121 } ) ;
2222} ) ;
0 commit comments