11import { mockNotificationWithSubject } from '../../../__mocks__/notifications-mocks' ;
22import { partialMockNotification } from '../../../__mocks__/partial-mocks' ;
33import { mockSettings } from '../../../__mocks__/state-mocks' ;
4- import { checkSuiteHandler , getCheckSuiteAttributes } from './checkSuite' ;
4+ import type { StateType } from '../../../typesGitHub' ;
5+ import { createCheckSuiteHandler , getCheckSuiteAttributes } from './checkSuite' ;
56
67describe ( 'renderer/utils/notifications/handlers/checkSuite.ts' , ( ) => {
78 describe ( 'enrich' , ( ) => {
@@ -11,10 +12,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
1112 type : 'CheckSuite' ,
1213 } ) ;
1314
14- const result = await checkSuiteHandler . enrich (
15- mockNotification ,
16- mockSettings ,
17- ) ;
15+ const handler = createCheckSuiteHandler ( mockNotification ) ;
16+ const result = await handler . enrich ( mockSettings ) ;
1817
1918 expect ( result ) . toEqual ( {
2019 state : 'cancelled' ,
@@ -28,10 +27,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
2827 type : 'CheckSuite' ,
2928 } ) ;
3029
31- const result = await checkSuiteHandler . enrich (
32- mockNotification ,
33- mockSettings ,
34- ) ;
30+ const handler = createCheckSuiteHandler ( mockNotification ) ;
31+ const result = await handler . enrich ( mockSettings ) ;
3532
3633 expect ( result ) . toEqual ( {
3734 state : 'failure' ,
@@ -45,10 +42,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
4542 type : 'CheckSuite' ,
4643 } ) ;
4744
48- const result = await checkSuiteHandler . enrich (
49- mockNotification ,
50- mockSettings ,
51- ) ;
45+ const handler = createCheckSuiteHandler ( mockNotification ) ;
46+ const result = await handler . enrich ( mockSettings ) ;
5247
5348 expect ( result ) . toEqual ( {
5449 state : 'failure' ,
@@ -62,10 +57,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
6257 type : 'CheckSuite' ,
6358 } ) ;
6459
65- const result = await checkSuiteHandler . enrich (
66- mockNotification ,
67- mockSettings ,
68- ) ;
60+ const handler = createCheckSuiteHandler ( mockNotification ) ;
61+ const result = await handler . enrich ( mockSettings ) ;
6962
7063 expect ( result ) . toEqual ( {
7164 state : 'failure' ,
@@ -79,10 +72,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
7972 type : 'CheckSuite' ,
8073 } ) ;
8174
82- const result = await checkSuiteHandler . enrich (
83- mockNotification ,
84- mockSettings ,
85- ) ;
75+ const handler = createCheckSuiteHandler ( mockNotification ) ;
76+ const result = await handler . enrich ( mockSettings ) ;
8677
8778 expect ( result ) . toEqual ( {
8879 state : 'skipped' ,
@@ -96,10 +87,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
9687 type : 'CheckSuite' ,
9788 } ) ;
9889
99- const result = await checkSuiteHandler . enrich (
100- mockNotification ,
101- mockSettings ,
102- ) ;
90+ const handler = createCheckSuiteHandler ( mockNotification ) ;
91+ const result = await handler . enrich ( mockSettings ) ;
10392
10493 expect ( result ) . toEqual ( {
10594 state : 'success' ,
@@ -113,10 +102,8 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
113102 type : 'CheckSuite' ,
114103 } ) ;
115104
116- const result = await checkSuiteHandler . enrich (
117- mockNotification ,
118- mockSettings ,
119- ) ;
105+ const handler = createCheckSuiteHandler ( mockNotification ) ;
106+ const result = await handler . enrich ( mockSettings ) ;
120107
121108 expect ( result ) . toBeNull ( ) ;
122109 } ) ;
@@ -127,57 +114,29 @@ describe('renderer/utils/notifications/handlers/checkSuite.ts', () => {
127114 type : 'CheckSuite' ,
128115 } ) ;
129116
130- const result = await checkSuiteHandler . enrich (
131- mockNotification ,
132- mockSettings ,
133- ) ;
117+ const handler = createCheckSuiteHandler ( mockNotification ) ;
118+ const result = await handler . enrich ( mockSettings ) ;
134119
135120 expect ( result ) . toBeNull ( ) ;
136121 } ) ;
137122 } ) ;
138123
139- it ( 'iconType' , ( ) => {
140- expect (
141- checkSuiteHandler . iconType (
142- mockNotificationWithSubject ( { type : 'CheckSuite' , state : null } ) ,
143- ) . displayName ,
144- ) . toBe ( 'RocketIcon' ) ;
145-
146- expect (
147- checkSuiteHandler . iconType (
148- mockNotificationWithSubject ( {
149- type : 'CheckSuite' ,
150- state : 'cancelled' ,
151- } ) ,
152- ) . displayName ,
153- ) . toBe ( 'StopIcon' ) ;
154-
155- expect (
156- checkSuiteHandler . iconType (
157- mockNotificationWithSubject ( {
158- type : 'CheckSuite' ,
159- state : 'failure' ,
160- } ) ,
161- ) . displayName ,
162- ) . toBe ( 'XIcon' ) ;
163-
164- expect (
165- checkSuiteHandler . iconType (
166- mockNotificationWithSubject ( {
167- type : 'CheckSuite' ,
168- state : 'skipped' ,
169- } ) ,
170- ) . displayName ,
171- ) . toBe ( 'SkipIcon' ) ;
172-
173- expect (
174- checkSuiteHandler . iconType (
175- mockNotificationWithSubject ( {
176- type : 'CheckSuite' ,
177- state : 'success' ,
178- } ) ,
179- ) . displayName ,
180- ) . toBe ( 'CheckIcon' ) ;
124+ describe ( 'iconType' , ( ) => {
125+ const cases : Array < [ StateType , string ] > = [
126+ [ null , 'RocketIcon' ] ,
127+ [ 'cancelled' , 'StopIcon' ] ,
128+ [ 'failure' , 'XIcon' ] ,
129+ [ 'skipped' , 'SkipIcon' ] ,
130+ [ 'success' , 'CheckIcon' ] ,
131+ ] ;
132+
133+ it . each ( cases ) ( 'returns expected icon for %s' , ( state , expectedIcon ) => {
134+ const handler = createCheckSuiteHandler (
135+ mockNotificationWithSubject ( { type : 'CheckSuite' , state } ) ,
136+ ) ;
137+
138+ expect ( handler . iconType ( ) . displayName ) . toBe ( expectedIcon ) ;
139+ } ) ;
181140 } ) ;
182141
183142 describe ( 'getCheckSuiteState' , ( ) => {
0 commit comments