@@ -2,7 +2,11 @@ import { partialMockNotification } from '../../../__mocks__/partial-mocks';
22import { mockSettings } from '../../../__mocks__/state-mocks' ;
33import { defaultSettings } from '../../../context/App' ;
44import type { Link , SettingsState } from '../../../types' ;
5- import { filterNotifications , hasAnyFiltersSet } from './filter' ;
5+ import {
6+ filterBaseNotifications ,
7+ filterDetailedNotifications ,
8+ hasAnyFiltersSet ,
9+ } from './filter' ;
610
711describe ( 'renderer/utils/notifications/filters/filter.ts' , ( ) => {
812 afterEach ( ( ) => {
@@ -33,87 +37,91 @@ describe('renderer/utils/notifications/filters/filter.ts', () => {
3337 } ) ,
3438 ] ;
3539
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 ] ] ) ;
4451 } ) ;
4552
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+ } ) ;
4960
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 ] ] ) ;
5563 } ) ;
56-
57- expect ( result . length ) . toBe ( 1 ) ;
58- expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
5964 } ) ;
6065
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 ) ;
6679 } ) ;
6780
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+ } ) ;
7187
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 ] ] ) ;
7790 } ) ;
7891
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+ } ) ;
8298
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 ] ] ) ;
89101 } ) ;
90102
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+ } ) ;
94109
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 ] ] ) ;
101112 } ) ;
102113
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+ } ) ;
106121
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 ] ] ) ;
113124 } ) ;
114-
115- expect ( result . length ) . toBe ( 1 ) ;
116- expect ( result ) . toEqual ( [ mockNotifications [ 1 ] ] ) ;
117125 } ) ;
118126 } ) ;
119127
0 commit comments