77 act ,
88 within ,
99} from "@testing-library/react" ;
10+ import userEvent from "@testing-library/user-event" ;
1011import { describe , it , expect , vi , beforeEach } from "vitest" ;
1112import { QueryClient , QueryClientProvider } from "@tanstack/react-query" ;
1213import OpeningSubmissionTrend from "../../../components/OpeningSubmissionTrend" ;
@@ -168,6 +169,7 @@ describe("OpeningSubmissionTrend Component", () => {
168169 } ) ;
169170
170171 it ( "should update org units and trigger data fetch" , async ( ) => {
172+ const user = userEvent . setup ( ) ;
171173 (
172174 API . UserActionsEndpointService . getOpeningsSubmissionTrends as vi . Mock
173175 ) . mockResolvedValueOnce ( [ ] ) ;
@@ -185,16 +187,21 @@ describe("OpeningSubmissionTrend Component", () => {
185187 expect ( within ( container ! ) . getByText ( "District" ) ) . toBeInTheDocument ( ) ;
186188 } ) ;
187189
190+ // Find the FilterableMultiSelect input field
188191 const districtInput = document . getElementById (
189192 "district-dropdown-input"
190193 ) as HTMLInputElement ;
191194 expect ( districtInput ) . toBeInTheDocument ( ) ;
192195
193- fireEvent . change ( districtInput , { target : { value : "District A" } } ) ;
196+ // Click on the input to open the menu
197+ await user . click ( districtInput ) ;
194198
195- expect (
196- screen . getByRole ( "option" , { name : "DAS - District A" } )
197- ) . toBeInTheDocument ( ) ;
199+ // Wait for and verify the option appears
200+ await waitFor ( ( ) => {
201+ expect (
202+ screen . getByRole ( "option" , { name : "DAS - District A" } )
203+ ) . toBeInTheDocument ( ) ;
204+ } ) ;
198205 } ) ;
199206
200207 it ( "should show loading spinner when fetching" , async ( ) => {
0 commit comments