1
1
import * as React from 'react' ;
2
+ import { render , screen } from '@testing-library/react' ;
2
3
3
4
import { ComponentClassNames } from '../../shared' ;
4
5
import { Rating } from '../Rating' ;
5
- import { render , screen } from '@testing-library/react' ;
6
6
7
- describe ( 'Rating: ' , ( ) => {
8
- let customIcon ;
9
- beforeEach ( ( ) => {
10
- customIcon = ( className ) => {
11
- return < svg className = { className } > </ svg > ;
12
- } ;
13
- } ) ;
7
+ const CustomIcon = ( { className } : { className : string } ) => (
8
+ < svg className = { className } > </ svg >
9
+ ) ;
14
10
11
+ describe ( 'Rating' , ( ) => {
15
12
it ( 'should render a classname for Rating' , async ( ) => {
16
13
render ( < Rating testId = "testId" className = "my-rating-component" /> ) ;
17
14
@@ -53,27 +50,27 @@ describe('Rating: ', () => {
53
50
expect ( rating . dataset [ 'size' ] ) . toBe ( 'small' ) ;
54
51
} ) ;
55
52
56
- it ( 'should render the empty icon color' , async ( ) => {
53
+ it ( 'should render the empty icon color' , ( ) => {
57
54
const { container } = render ( < Rating testId = "testId" emptyColor = "red" /> ) ;
58
55
59
56
const emptyIcon = container . getElementsByClassName (
60
57
'amplify-rating-icon-empty'
61
58
) [ 0 ] ;
62
- expect ( emptyIcon [ 'style' ] . color ) . toBe ( 'red' ) ;
59
+ expect ( ( emptyIcon [ 'style' ] as React . CSSProperties ) . color ) . toBe ( 'red' ) ;
63
60
} ) ;
64
61
65
- it ( 'should render the filled icon color' , async ( ) => {
62
+ it ( 'should render the filled icon color' , ( ) => {
66
63
const { container } = render (
67
64
< Rating testId = "testId" value = { 2 } fillColor = "blue" />
68
65
) ;
69
66
70
67
const filledIcon = container . getElementsByClassName (
71
68
'amplify-rating-icon-filled'
72
69
) [ 0 ] ;
73
- expect ( filledIcon [ 'style' ] . color ) . toBe ( 'blue' ) ;
70
+ expect ( ( filledIcon [ 'style' ] as React . CSSProperties ) . color ) . toBe ( 'blue' ) ;
74
71
} ) ;
75
72
76
- it ( 'should render filled icons when the value prop is used' , async ( ) => {
73
+ it ( 'should render filled icons when the value prop is used' , ( ) => {
77
74
const { container } = render ( < Rating testId = "testId" value = { 2 } /> ) ;
78
75
79
76
const filledIcons = container . getElementsByClassName (
@@ -82,7 +79,7 @@ describe('Rating: ', () => {
82
79
expect ( filledIcons . length ) . toBe ( 2 ) ;
83
80
} ) ;
84
81
85
- it ( 'should render 2 filled and 3 empty icons' , async ( ) => {
82
+ it ( 'should render 2 filled and 3 empty icons' , ( ) => {
86
83
const { container } = render ( < Rating value = { 2 } /> ) ;
87
84
const filledIcons = container . getElementsByClassName (
88
85
'amplify-rating-icon-filled'
@@ -94,33 +91,40 @@ describe('Rating: ', () => {
94
91
expect ( emptyIcons . length ) . toBe ( 3 ) ;
95
92
} ) ;
96
93
97
- it ( 'should render 7 icons when the maxValue is set to 7' , async ( ) => {
94
+ it ( 'should render 7 icons when the maxValue is set to 7' , ( ) => {
98
95
const { container } = render ( < Rating maxValue = { 7 } /> ) ;
99
96
const emptyIcons = container . getElementsByClassName (
100
97
'amplify-rating-icon-empty'
101
98
) ;
102
99
expect ( emptyIcons . length ) . toBe ( 7 ) ;
103
100
} ) ;
104
101
105
- it ( 'should render the passed in icon component' , async ( ) => {
106
- const icon = customIcon ( 'my-custom-component' ) ;
107
- const { container } = render ( < Rating icon = { icon } /> ) ;
102
+ it ( 'should render the passed in icon component' , ( ) => {
103
+ const { container } = render (
104
+ < Rating icon = { < CustomIcon className = "my-custom-component" /> } />
105
+ ) ;
108
106
const emptyIcons = container . getElementsByClassName ( 'my-custom-component' ) ;
109
107
expect ( emptyIcons . length ) . toBe ( 5 ) ;
110
108
} ) ;
111
109
112
- it ( 'should render the passed in empty icon' , async ( ) => {
113
- const emptyIcon = customIcon ( 'my-custom-empty-icon' ) ;
114
- const { container } = render ( < Rating emptyIcon = { emptyIcon } value = { 3 } /> ) ;
110
+ it ( 'should render the passed in empty icon' , ( ) => {
111
+ const { container } = render (
112
+ < Rating
113
+ emptyIcon = { < CustomIcon className = "my-custom-empty-icon" /> }
114
+ value = { 3 }
115
+ />
116
+ ) ;
115
117
const emptyIcons = container . getElementsByClassName ( 'my-custom-empty-icon' ) ;
116
118
expect ( emptyIcons . length ) . toBe ( 2 ) ;
117
119
} ) ;
118
120
119
- it ( 'should render both the passed in icon and empty icons' , async ( ) => {
120
- const filledIcon = customIcon ( 'my-custom-filled-icon' ) ;
121
- const emptyIcon = customIcon ( 'my-custom-empty-icon' ) ;
121
+ it ( 'should render both the passed in icon and empty icons' , ( ) => {
122
122
const { container } = render (
123
- < Rating icon = { filledIcon } emptyIcon = { emptyIcon } value = { 3 } />
123
+ < Rating
124
+ icon = { < CustomIcon className = "my-custom-filled-icon" /> }
125
+ emptyIcon = { < CustomIcon className = "my-custom-empty-icon" /> }
126
+ value = { 3 }
127
+ />
124
128
) ;
125
129
const emptyIcons = container . getElementsByClassName ( 'my-custom-empty-icon' ) ;
126
130
const filledIcons = container . getElementsByClassName (
0 commit comments