@@ -90,67 +90,71 @@ const TestComponent = () => {
9090 ) ;
9191} ;
9292
93- test ( 'switch between list and detail view' , async ( ) => {
94- jest . useFakeTimers ( ) ;
95- mockGetList . mockReturnValue ( [
96- { id : 1 , title : 'Article 1' , content : 'Content 1' } ,
97- { id : 2 , title : 'Article 2' , content : 'Content 2' } ,
98- ] ) ;
99- mockGet . mockReturnValue ( {
100- id : 1 ,
101- title : 'Article 1' ,
102- content : 'Content 1' ,
93+ describe ( 'Integration Garbage Collection Web' , ( ) => {
94+ it ( 'should render list view and detail view correctly' , async ( ) => {
95+ jest . useFakeTimers ( ) ;
96+ mockGetList . mockReturnValue ( [
97+ { id : 1 , title : 'Article 1' , content : 'Content 1' } ,
98+ { id : 2 , title : 'Article 2' , content : 'Content 2' } ,
99+ ] ) ;
100+ mockGet . mockReturnValue ( {
101+ id : 1 ,
102+ title : 'Article 1' ,
103+ content : 'Content 1' ,
104+ } ) ;
105+
106+ render ( < TestComponent /> ) ;
107+
108+ // Initial render, should show list view
109+ expect ( await screen . findByText ( 'Article 1' ) ) . toBeInTheDocument ( ) ;
110+
111+ // Switch to detail view
112+ act ( ( ) => {
113+ screen . getByText ( 'Article 1' ) . click ( ) ;
114+ } ) ;
115+
116+ // Detail view should render
117+ expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
118+
119+ // Jest time pass to trigger sweep but not expired
120+ act ( ( ) => {
121+ jest . advanceTimersByTime ( GC_INTERVAL ) ;
122+ } ) ;
123+
124+ // Switch back to list view
125+ act ( ( ) => {
126+ screen . getByText ( 'Home' ) . click ( ) ;
127+ } ) ;
128+
129+ // List view should instantly render
130+ expect ( await screen . findByText ( 'Article 1' ) ) . toBeInTheDocument ( ) ;
131+
132+ // Switch back to detail view
133+ act ( ( ) => {
134+ screen . getByText ( 'Article 1' ) . click ( ) ;
135+ } ) ;
136+
137+ // Jest time pass to expiry
138+ act ( ( ) => {
139+ jest . advanceTimersByTime (
140+ ArticleResource . getList . dataExpiryLength ?? 60000 ,
141+ ) ;
142+ } ) ;
143+ expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
144+
145+ // Re-render detail view to make sure it still renders
146+ act ( ( ) => {
147+ screen . getByText ( 'Toggle Re-render' ) . click ( ) ;
148+ } ) ;
149+ expect ( await screen . findByText ( 'Toggle state: true' ) ) . toBeInTheDocument ( ) ;
150+ expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
151+
152+ // Visit list view and see suspense fallback
153+ act ( ( ) => {
154+ screen . getByText ( 'Home' ) . click ( ) ;
155+ } ) ;
156+
157+ expect ( screen . getByText ( 'Loading...' ) ) . toBeInTheDocument ( ) ;
158+ jest . useRealTimers ( ) ;
103159 } ) ;
104-
105- render ( < TestComponent /> ) ;
106-
107- // Initial render, should show list view
108- expect ( await screen . findByText ( 'Article 1' ) ) . toBeInTheDocument ( ) ;
109-
110- // Switch to detail view
111- act ( ( ) => {
112- screen . getByText ( 'Article 1' ) . click ( ) ;
113- } ) ;
114-
115- // Detail view should render
116- expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
117-
118- // Jest time pass to trigger sweep but not expired
119- act ( ( ) => {
120- jest . advanceTimersByTime ( GC_INTERVAL ) ;
121- } ) ;
122-
123- // Switch back to list view
124- act ( ( ) => {
125- screen . getByText ( 'Home' ) . click ( ) ;
126- } ) ;
127-
128- // List view should instantly render
129- expect ( await screen . findByText ( 'Article 1' ) ) . toBeInTheDocument ( ) ;
130-
131- // Switch back to detail view
132- act ( ( ) => {
133- screen . getByText ( 'Article 1' ) . click ( ) ;
134- } ) ;
135-
136- // Jest time pass to expiry
137- act ( ( ) => {
138- jest . advanceTimersByTime ( ArticleResource . getList . dataExpiryLength ?? 60000 ) ;
139- } ) ;
140- expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
141-
142- // Re-render detail view to make sure it still renders
143- act ( ( ) => {
144- screen . getByText ( 'Toggle Re-render' ) . click ( ) ;
145- } ) ;
146- expect ( await screen . findByText ( 'Toggle state: true' ) ) . toBeInTheDocument ( ) ;
147- expect ( await screen . findByText ( 'Content 1' ) ) . toBeInTheDocument ( ) ;
148-
149- // Visit list view and see suspense fallback
150- act ( ( ) => {
151- screen . getByText ( 'Home' ) . click ( ) ;
152- } ) ;
153-
154- expect ( screen . getByText ( 'Loading...' ) ) . toBeInTheDocument ( ) ;
155- jest . useRealTimers ( ) ;
156160} ) ;
0 commit comments