1- import { expect , describe , it } from ' vitest' ;
1+ import { expect , describe , it } from " vitest" ;
22import React from "react" ;
33import { Provider } from "react-redux" ;
44import { createStore } from "redux" ;
55import { fireEvent , render } from "@testing-library/react" ;
6+ import { act } from "react-dom/test-utils" ;
67
78import configureStore from "redux-mock-store" ;
89
@@ -43,14 +44,8 @@ const setup = () => {
4344} ;
4445
4546const mockStore = configureStore ( [ ] ) ;
46-
4747const localization = config . localization . eng_pubmed ;
4848
49- /**
50- * Extra test suite for testing BASE data integration on real data, config and context.
51- *
52- * This file tests only the interactions. The structure is tested by snapshot test.
53- */
5449describe ( "List entries component - special BASE tests" , ( ) => {
5550 it ( "renders" , ( ) => {
5651 const store = setup ( ) ;
@@ -190,7 +185,7 @@ describe("List entries component - special BASE tests", () => {
190185 } ) ;
191186
192187 describe ( "search, filter and sort" , ( ) => {
193- it ( "searches the list for 'calcium homeostasis'" , ( ) => {
188+ it ( "searches the list for 'calcium homeostasis'" , async ( ) => {
194189 const store = setup ( ) ;
195190
196191 const result = render (
@@ -201,14 +196,15 @@ describe("List entries component - special BASE tests", () => {
201196 </ Provider >
202197 ) ;
203198
204- store . dispatch ( search ( "calcium homeostasis" ) ) ;
199+ await act ( async ( ) => {
200+ store . dispatch ( search ( "calcium homeostasis" ) ) ;
201+ } ) ;
205202
206203 const papers = result . container . querySelectorAll ( ".list_entry" ) ;
207-
208204 expect ( papers . length ) . toEqual ( 1 ) ;
209205 } ) ;
210206
211- it ( "filters the list for open access papers only" , ( ) => {
207+ it ( "filters the list for open access papers only" , async ( ) => {
212208 const store = setup ( ) ;
213209
214210 const result = render (
@@ -219,14 +215,15 @@ describe("List entries component - special BASE tests", () => {
219215 </ Provider >
220216 ) ;
221217
222- store . dispatch ( filter ( "open_access" ) ) ;
218+ await act ( async ( ) => {
219+ store . dispatch ( filter ( "open_access" ) ) ;
220+ } ) ;
223221
224222 const papers = result . container . querySelectorAll ( ".list_entry" ) ;
225-
226223 expect ( papers . length ) . toEqual ( 6 ) ;
227224 } ) ;
228225
229- it ( "sorts the list by year" , ( ) => {
226+ it ( "sorts the list by year" , async ( ) => {
230227 const store = setup ( ) ;
231228
232229 const result = render (
@@ -237,7 +234,9 @@ describe("List entries component - special BASE tests", () => {
237234 </ Provider >
238235 ) ;
239236
240- store . dispatch ( sort ( "year" ) ) ;
237+ await act ( async ( ) => {
238+ store . dispatch ( sort ( "year" ) ) ;
239+ } ) ;
241240
242241 const papers = result . container . querySelectorAll ( ".list_entry" ) ;
243242
@@ -256,9 +255,8 @@ describe("List entries component - special BASE tests", () => {
256255 ] ) ;
257256 } ) ;
258257
259- it ( "searches, filters and sorts at the same time" , ( ) => {
258+ it ( "searches, filters and sorts at the same time" , async ( ) => {
260259 const store = setup ( ) ;
261-
262260 const SEARCH_TEXT = "calcium silicate" ;
263261
264262 const result = render (
@@ -269,17 +267,23 @@ describe("List entries component - special BASE tests", () => {
269267 </ Provider >
270268 ) ;
271269
272- store . dispatch ( search ( SEARCH_TEXT ) ) ;
270+ await act ( async ( ) => {
271+ store . dispatch ( search ( SEARCH_TEXT ) ) ;
272+ } ) ;
273273
274274 let papers = result . container . querySelectorAll ( ".list_entry" ) ;
275275 expect ( papers . length ) . toEqual ( 4 ) ;
276276
277- store . dispatch ( filter ( "open_access" ) ) ;
277+ await act ( async ( ) => {
278+ store . dispatch ( filter ( "open_access" ) ) ;
279+ } ) ;
278280
279281 papers = result . container . querySelectorAll ( ".list_entry" ) ;
280282 expect ( papers . length ) . toEqual ( 2 ) ;
281283
282- store . dispatch ( sort ( "title" ) ) ;
284+ await act ( async ( ) => {
285+ store . dispatch ( sort ( "title" ) ) ;
286+ } ) ;
283287
284288 papers = result . container . querySelectorAll ( ".list_entry" ) ;
285289
0 commit comments