1- import { fireEvent , render , screen } from '@testing-library/react' ;
1+ import { render , screen } from '@testing-library/react' ;
2+ import userEvent from '@testing-library/user-event' ;
23
34import { mockSettings } from '../../__mocks__/state-mocks' ;
45import { AppContext } from '../../context/App' ;
6+ import type { SettingsState } from '../../types' ;
57import { OrganizationFilter } from './OrganizationFilter' ;
68
79const mockUpdateFilter = jest . fn ( ) ;
@@ -28,49 +30,101 @@ describe('components/filters/OrganizationFilter.tsx', () => {
2830 expect ( screen . getByText ( 'Exclude:' ) ) . toBeInTheDocument ( ) ;
2931 } ) ;
3032
31- it ( 'should handle organization includes' , ( ) => {
32- const props = {
33- updateFilter : mockUpdateFilter ,
34- settings : mockSettings ,
35- } ;
33+ describe ( 'Include organizations' , ( ) => {
34+ it ( 'should handle organization includes' , async ( ) => {
35+ const props = {
36+ updateFilter : mockUpdateFilter ,
37+ settings : mockSettings ,
38+ } ;
3639
37- render (
38- < AppContext . Provider value = { props } >
39- < OrganizationFilter />
40- </ AppContext . Provider > ,
41- ) ;
40+ render (
41+ < AppContext . Provider value = { props } >
42+ < OrganizationFilter />
43+ </ AppContext . Provider > ,
44+ ) ;
4245
43- const includeInput = screen . getByTitle ( 'Include organizations' ) ;
44- fireEvent . change ( includeInput , { target : { value : 'microsoft' } } ) ;
45- fireEvent . blur ( includeInput ) ;
46+ await userEvent . type (
47+ screen . getByTitle ( 'Include organizations' ) ,
48+ 'microsoft{enter}' ,
49+ ) ;
4650
47- expect ( mockUpdateFilter ) . toHaveBeenCalledWith (
48- 'filterIncludeOrganizations' ,
49- 'microsoft' ,
50- true ,
51- ) ;
51+ expect ( mockUpdateFilter ) . toHaveBeenCalledWith (
52+ 'filterIncludeOrganizations' ,
53+ 'microsoft' ,
54+ true ,
55+ ) ;
56+ } ) ;
57+
58+ it ( 'should not allow duplicate include organizations' , async ( ) => {
59+ const props = {
60+ updateFilter : mockUpdateFilter ,
61+ settings : {
62+ ...mockSettings ,
63+ filterIncludeOrganizations : [ 'microsoft' ] ,
64+ } as SettingsState ,
65+ } ;
66+
67+ render (
68+ < AppContext . Provider value = { props } >
69+ < OrganizationFilter />
70+ </ AppContext . Provider > ,
71+ ) ;
72+
73+ await userEvent . type (
74+ screen . getByTitle ( 'Include organizations' ) ,
75+ 'microsoft{enter}' ,
76+ ) ;
77+
78+ expect ( mockUpdateFilter ) . toHaveBeenCalledTimes ( 0 ) ;
79+ } ) ;
5280 } ) ;
5381
54- it ( 'should handle organization excludes' , ( ) => {
55- const props = {
56- updateFilter : mockUpdateFilter ,
57- settings : mockSettings ,
58- } ;
82+ describe ( 'Exclude organizations' , ( ) => {
83+ it ( 'should handle organization excludes' , async ( ) => {
84+ const props = {
85+ updateFilter : mockUpdateFilter ,
86+ settings : mockSettings ,
87+ } ;
5988
60- render (
61- < AppContext . Provider value = { props } >
62- < OrganizationFilter />
63- </ AppContext . Provider > ,
64- ) ;
89+ render (
90+ < AppContext . Provider value = { props } >
91+ < OrganizationFilter />
92+ </ AppContext . Provider > ,
93+ ) ;
6594
66- const excludeInput = screen . getByTitle ( 'Exclude organizations' ) ;
67- fireEvent . change ( excludeInput , { target : { value : 'github' } } ) ;
68- fireEvent . blur ( excludeInput ) ;
95+ await userEvent . type (
96+ screen . getByTitle ( 'Exclude organizations' ) ,
97+ 'github{enter}' ,
98+ ) ;
6999
70- expect ( mockUpdateFilter ) . toHaveBeenCalledWith (
71- 'filterExcludeOrganizations' ,
72- 'github' ,
73- true ,
74- ) ;
100+ expect ( mockUpdateFilter ) . toHaveBeenCalledWith (
101+ 'filterExcludeOrganizations' ,
102+ 'github' ,
103+ true ,
104+ ) ;
105+ } ) ;
106+
107+ it ( 'should not allow duplicate exclude organizations' , async ( ) => {
108+ const props = {
109+ updateFilter : mockUpdateFilter ,
110+ settings : {
111+ ...mockSettings ,
112+ filterExcludeOrganizations : [ 'github' ] ,
113+ } as SettingsState ,
114+ } ;
115+
116+ render (
117+ < AppContext . Provider value = { props } >
118+ < OrganizationFilter />
119+ </ AppContext . Provider > ,
120+ ) ;
121+
122+ await userEvent . type (
123+ screen . getByTitle ( 'Exclude organizations' ) ,
124+ 'github{enter}' ,
125+ ) ;
126+
127+ expect ( mockUpdateFilter ) . toHaveBeenCalledTimes ( 0 ) ;
128+ } ) ;
75129 } ) ;
76130} ) ;
0 commit comments