@@ -2,7 +2,11 @@ import { partialMockNotification } from '../../../__mocks__/partial-mocks';
2
2
import { mockSettings } from '../../../__mocks__/state-mocks' ;
3
3
import { defaultSettings } from '../../../context/App' ;
4
4
import type { Link , SettingsState } from '../../../types' ;
5
- import { filterNotifications , hasAnyFiltersSet } from './filter' ;
5
+ import {
6
+ filterBaseNotifications ,
7
+ filterDetailedNotifications ,
8
+ hasAnyFiltersSet ,
9
+ } from './filter' ;
6
10
7
11
describe ( 'renderer/utils/notifications/filters/filter.ts' , ( ) => {
8
12
afterEach ( ( ) => {
@@ -33,87 +37,91 @@ describe('renderer/utils/notifications/filters/filter.ts', () => {
33
37
} ) ,
34
38
] ;
35
39
36
- it ( 'should ignore user type, handle filters and state filters if detailed notifications not enabled' , async ( ) => {
37
- const result = filterNotifications ( mockNotifications , {
38
- ...mockSettings ,
39
- detailedNotifications : false ,
40
- filterUserTypes : [ 'Bot' ] ,
41
- filterIncludeHandles : [ 'github-user' ] ,
42
- filterExcludeHandles : [ 'github-bot' ] ,
43
- filterStates : [ 'merged' ] ,
40
+ describe ( 'filterBaseNotifications' , ( ) => {
41
+ it ( 'should filter notifications by subject type when provided' , async ( ) => {
42
+ mockNotifications [ 0 ] . subject . type = 'Issue' ;
43
+ mockNotifications [ 1 ] . subject . type = 'PullRequest' ;
44
+ const result = filterBaseNotifications ( mockNotifications , {
45
+ ...mockSettings ,
46
+ filterSubjectTypes : [ 'Issue' ] ,
47
+ } ) ;
48
+
49
+ expect ( result . length ) . toBe ( 1 ) ;
50
+ expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
44
51
} ) ;
45
52
46
- expect ( result . length ) . toBe ( 2 ) ;
47
- expect ( result ) . toEqual ( mockNotifications ) ;
48
- } ) ;
53
+ it ( 'should filter notifications by reasons when provided' , async ( ) => {
54
+ mockNotifications [ 0 ] . reason = 'subscribed' ;
55
+ mockNotifications [ 1 ] . reason = 'manual' ;
56
+ const result = filterBaseNotifications ( mockNotifications , {
57
+ ...mockSettings ,
58
+ filterReasons : [ 'manual' ] ,
59
+ } ) ;
49
60
50
- it ( 'should filter notifications by user type provided' , async ( ) => {
51
- const result = filterNotifications ( mockNotifications , {
52
- ...mockSettings ,
53
- detailedNotifications : true ,
54
- filterUserTypes : [ 'Bot' ] ,
61
+ expect ( result . length ) . toBe ( 1 ) ;
62
+ expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
55
63
} ) ;
56
-
57
- expect ( result . length ) . toBe ( 1 ) ;
58
- expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
59
64
} ) ;
60
65
61
- it ( 'should filter notifications that match include user handle' , async ( ) => {
62
- const result = filterNotifications ( mockNotifications , {
63
- ...mockSettings ,
64
- detailedNotifications : true ,
65
- filterIncludeHandles : [ 'github-user' ] ,
66
+ describe ( 'filterDetailedNotifications' , ( ) => {
67
+ it ( 'should ignore user type, handle filters and state filters if detailed notifications not enabled' , async ( ) => {
68
+ const result = filterDetailedNotifications ( mockNotifications , {
69
+ ...mockSettings ,
70
+ detailedNotifications : false ,
71
+ filterUserTypes : [ 'Bot' ] ,
72
+ filterIncludeHandles : [ 'github-user' ] ,
73
+ filterExcludeHandles : [ 'github-bot' ] ,
74
+ filterStates : [ 'merged' ] ,
75
+ } ) ;
76
+
77
+ expect ( result . length ) . toBe ( 2 ) ;
78
+ expect ( result ) . toEqual ( mockNotifications ) ;
66
79
} ) ;
67
80
68
- expect ( result . length ) . toBe ( 1 ) ;
69
- expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
70
- } ) ;
81
+ it ( 'should filter notifications by user type provided' , async ( ) => {
82
+ const result = filterDetailedNotifications ( mockNotifications , {
83
+ ...mockSettings ,
84
+ detailedNotifications : true ,
85
+ filterUserTypes : [ 'Bot' ] ,
86
+ } ) ;
71
87
72
- it ( 'should filter notifications that match exclude user handle' , async ( ) => {
73
- const result = filterNotifications ( mockNotifications , {
74
- ...mockSettings ,
75
- detailedNotifications : true ,
76
- filterExcludeHandles : [ 'github-bot' ] ,
88
+ expect ( result . length ) . toBe ( 1 ) ;
89
+ expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
77
90
} ) ;
78
91
79
- expect ( result . length ) . toBe ( 1 ) ;
80
- expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
81
- } ) ;
92
+ it ( 'should filter notifications that match include user handle' , async ( ) => {
93
+ const result = filterDetailedNotifications ( mockNotifications , {
94
+ ...mockSettings ,
95
+ detailedNotifications : true ,
96
+ filterIncludeHandles : [ 'github-user' ] ,
97
+ } ) ;
82
98
83
- it ( 'should filter notifications by subject type when provided' , async ( ) => {
84
- mockNotifications [ 0 ] . subject . type = 'Issue' ;
85
- mockNotifications [ 1 ] . subject . type = 'PullRequest' ;
86
- const result = filterNotifications ( mockNotifications , {
87
- ...mockSettings ,
88
- filterSubjectTypes : [ 'Issue' ] ,
99
+ expect ( result . length ) . toBe ( 1 ) ;
100
+ expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
89
101
} ) ;
90
102
91
- expect ( result . length ) . toBe ( 1 ) ;
92
- expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
93
- } ) ;
103
+ it ( 'should filter notifications that match exclude user handle' , async ( ) => {
104
+ const result = filterDetailedNotifications ( mockNotifications , {
105
+ ...mockSettings ,
106
+ detailedNotifications : true ,
107
+ filterExcludeHandles : [ 'github-bot' ] ,
108
+ } ) ;
94
109
95
- it ( 'should filter notifications by state when provided' , async ( ) => {
96
- mockNotifications [ 0 ] . subject . state = 'open' ;
97
- mockNotifications [ 1 ] . subject . state = 'closed' ;
98
- const result = filterNotifications ( mockNotifications , {
99
- ...mockSettings ,
100
- filterStates : [ 'closed' ] ,
110
+ expect ( result . length ) . toBe ( 1 ) ;
111
+ expect ( result ) . toEqual ( [ mockNotifications [ 0 ] ] ) ;
101
112
} ) ;
102
113
103
- expect ( result . length ) . toBe ( 1 ) ;
104
- expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
105
- } ) ;
114
+ it ( 'should filter notifications by state when provided' , async ( ) => {
115
+ mockNotifications [ 0 ] . subject . state = 'open' ;
116
+ mockNotifications [ 1 ] . subject . state = 'closed' ;
117
+ const result = filterDetailedNotifications ( mockNotifications , {
118
+ ...mockSettings ,
119
+ filterStates : [ 'closed' ] ,
120
+ } ) ;
106
121
107
- it ( 'should filter notifications by reasons when provided' , async ( ) => {
108
- mockNotifications [ 0 ] . reason = 'subscribed' ;
109
- mockNotifications [ 1 ] . reason = 'manual' ;
110
- const result = filterNotifications ( mockNotifications , {
111
- ...mockSettings ,
112
- filterReasons : [ 'manual' ] ,
122
+ expect ( result . length ) . toBe ( 1 ) ;
123
+ expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
113
124
} ) ;
114
-
115
- expect ( result . length ) . toBe ( 1 ) ;
116
- expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
117
125
} ) ;
118
126
} ) ;
119
127
0 commit comments