@@ -5,7 +5,7 @@ import { DriverRatingBadge } from './DriverRatingBadge';
55describe ( 'DriverRatingBadge' , ( ) => {
66 it ( 'renders with default props' , ( ) => {
77 const { container } = render ( < DriverRatingBadge /> ) ;
8- expect ( container . textContent ) . toBe ( 'R 0.0k' ) ;
8+ expect ( container . textContent ) . toBe ( 'R 0.0 0. 0k' ) ;
99 } ) ;
1010
1111 it ( 'renders with license A and rating 5000' , ( ) => {
@@ -54,27 +54,41 @@ describe('DriverRatingBadge', () => {
5454 const { container } = render (
5555 < DriverRatingBadge license = { undefined } rating = { undefined } />
5656 ) ;
57- expect ( container . textContent ) . toBe ( 'R 0.0k' ) ;
57+ expect ( container . textContent ) . toBe ( 'R 0.0 0.0k' ) ;
58+ } ) ;
59+
60+ it ( 'rounds rating to 1 decimal place' , ( ) => {
61+ const { container } = render (
62+ < DriverRatingBadge license = "C 3.141592654" rating = { 5000.123 } />
63+ ) ;
64+ expect ( container . textContent ) . toBe ( 'C 3.1 5.0k' ) ;
5865 } ) ;
5966
6067 it ( 'removes leading zeros from license number when before non-zero digit' , ( ) => {
6168 const { container } = render (
6269 < DriverRatingBadge license = "A 02.99" rating = { 5000 } />
6370 ) ;
64- expect ( container . textContent ) . toBe ( 'A 2.99 5.0k' ) ;
71+ expect ( container . textContent ) . toBe ( 'A 3.0 5.0k' ) ;
6572 } ) ;
6673
6774 it ( 'keeps single zero before decimal point' , ( ) => {
6875 const { container } = render (
6976 < DriverRatingBadge license = "A 0.99" rating = { 5000 } />
7077 ) ;
71- expect ( container . textContent ) . toBe ( 'A 0.99 5.0k' ) ;
78+ expect ( container . textContent ) . toBe ( 'A 1.0 5.0k' ) ;
7279 } ) ;
7380
7481 it ( 'handles multiple leading zeros' , ( ) => {
7582 const { container } = render (
7683 < DriverRatingBadge license = "B 0003.45" rating = { 5000 } />
7784 ) ;
78- expect ( container . textContent ) . toBe ( 'B 3.45 5.0k' ) ;
85+ expect ( container . textContent ) . toBe ( 'B 3.5 5.0k' ) ;
86+ } ) ;
87+
88+ it ( 'should handle invalid license strings' , ( ) => {
89+ const { container } = render (
90+ < DriverRatingBadge license = "Oh no" rating = { 5000 } />
91+ ) ;
92+ expect ( container . textContent ) . toBe ( 'Oh no 5.0k' ) ;
7993 } ) ;
8094} ) ;
0 commit comments