@@ -52,6 +52,7 @@ test('Expect notification card to show notification title, description and close
52
52
53
53
const deleteButton = screen . getByRole ( 'button' , { name : 'Delete notification 1' } ) ;
54
54
expect ( deleteButton ) . toBeInTheDocument ( ) ;
55
+ expect ( deleteButton ) . toHaveAttribute ( 'title' , 'Delete notification' ) ;
55
56
56
57
await fireEvent . click ( deleteButton ) ;
57
58
@@ -66,16 +67,19 @@ test('Test info notification style and icon', () => {
66
67
body : 'Info notification description' ,
67
68
type : 'info' ,
68
69
} ;
69
- const { getAllByRole } = render ( NotificationCardItem , {
70
+ const { getByTitle } = render ( NotificationCardItem , {
70
71
notification,
71
72
} ) ;
72
- const icon = getAllByRole ( 'img' , { hidden : true } ) [ 0 ] ;
73
+ const iconTitle = getByTitle ( 'Notification icon' , { exact : false } ) ;
74
+ const icon = iconTitle . parentElement ;
73
75
// check icon shape
74
- const pdIconPath = icon . querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
76
+ const pdIconPath = icon ? .querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
75
77
const faIconPath = faCircleInfo . icon [ 4 ] ; // index 4 is the actual path as per FA IconDefinition
76
78
expect ( pdIconPath ) . toBe ( faIconPath ) ;
77
79
// check icon color
78
80
expect ( icon ) . toHaveClass ( 'text-[var(--pd-state-info)]' ) ;
81
+ // check icon title contains the text from nested title element
82
+ expect ( iconTitle . textContent ) . toBe ( 'Notification icon - info' ) ;
79
83
// check region top border
80
84
expect ( screen . getByRole ( 'region' , { name : 'id: 1' } ) ) . toHaveClass ( 'border-[var(--pd-state-info)]' ) ;
81
85
} ) ;
@@ -88,16 +92,19 @@ test('Test warning notification style and icon', () => {
88
92
body : 'Warning notification description' ,
89
93
type : 'warn' ,
90
94
} ;
91
- const { getAllByRole } = render ( NotificationCardItem , {
95
+ const { getByTitle } = render ( NotificationCardItem , {
92
96
notification,
93
97
} ) ;
94
- const icon = getAllByRole ( 'img' , { hidden : true } ) [ 0 ] ;
98
+ const iconTitle = getByTitle ( 'Notification icon' , { exact : false } ) ;
99
+ const icon = iconTitle . parentElement ;
95
100
// check icon shape
96
- const pdIconPath = icon . querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
101
+ const pdIconPath = icon ? .querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
97
102
const faIconPath = faExclamationTriangle . icon [ 4 ] ; // index 4 is the actual path as per FA IconDefinition
98
103
expect ( pdIconPath ) . toBe ( faIconPath ) ;
99
104
// check icon color
100
105
expect ( icon ) . toHaveClass ( 'text-[var(--pd-state-warning)]' ) ;
106
+ // check icon title
107
+ expect ( iconTitle . textContent ) . toBe ( 'Notification icon - warn' ) ;
101
108
// check region top border
102
109
expect ( screen . getByRole ( 'region' , { name : 'id: 1' } ) ) . toHaveClass ( 'border-[var(--pd-state-warning)]' ) ;
103
110
} ) ;
@@ -110,16 +117,19 @@ test('Test error notification style and icon', () => {
110
117
body : 'Error notification description' ,
111
118
type : 'error' ,
112
119
} ;
113
- const { getAllByRole } = render ( NotificationCardItem , {
120
+ const { getByTitle } = render ( NotificationCardItem , {
114
121
notification,
115
122
} ) ;
116
- const icon = getAllByRole ( 'img' , { hidden : true } ) [ 0 ] ;
123
+ const iconTitle = getByTitle ( 'Notification icon' , { exact : false } ) ;
124
+ const icon = iconTitle . parentElement ;
117
125
// check icon shape
118
- const pdIconPath = icon . querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
126
+ const pdIconPath = icon ? .querySelector ( 'path' ) ?. getAttribute ( 'd' ) ;
119
127
const faIconPath = faCircleExclamation . icon [ 4 ] ; // index 4 is the actual path as per FA IconDefinition
120
128
expect ( pdIconPath ) . toBe ( faIconPath ) ;
121
129
// check icon color
122
130
expect ( icon ) . toHaveClass ( 'text-[var(--pd-state-error)]' ) ;
131
+ // check icon title
132
+ expect ( iconTitle . textContent ) . toBe ( 'Notification icon - error' ) ;
123
133
// check region top border
124
134
expect ( screen . getByRole ( 'region' , { name : 'id: 1' } ) ) . toHaveClass ( 'border-[var(--pd-state-error)]' ) ;
125
135
} ) ;
0 commit comments