@@ -6,31 +6,77 @@ describe('Index', () => {
66 cleanup ( )
77 } )
88
9- it ( 'should display SUBSCRIBED status when realtime connection is established' , async ( ) => {
10- const { getByTestId, unmount } = render ( < Index /> )
11-
12- // Initially, the text should be empty
13- expect ( getByTestId ( 'realtime_status' ) ) . toHaveTextContent ( '' )
14-
15- // Wait for the subscription status to be updated
16- await waitFor (
17- ( ) => {
18- const status = getByTestId ( 'realtime_status' ) . props . children
19- expect ( status ) . toBe ( 'SUBSCRIBED' )
20- } ,
21- {
22- timeout : 30000 , // 30 seconds timeout for waitFor
23- interval : 1000 , // Check every second
24- onTimeout : ( error ) => {
25- const currentStatus = getByTestId ( 'realtime_status' ) . props . children
26- throw new Error (
27- `Timeout waiting for SUBSCRIBED status. Current status: ${ currentStatus } . ${ error . message } `
28- )
29- } ,
30- }
31- )
32-
33- // Unmount the component to trigger cleanup.
34- unmount ( )
35- } , 35000 ) // 35 seconds timeout for the entire test
9+ const versions = [ { vsn : '1.0.0' } , { vsn : '2.0.0' } ]
10+
11+ versions . forEach ( ( { vsn } ) => {
12+ describe ( `Realtime with vsn: ${ vsn } ` , ( ) => {
13+ it ( 'should display SUBSCRIBED status when realtime connection is established' , async ( ) => {
14+ const { getByTestId, unmount } = render ( < Index vsn = { vsn } /> )
15+
16+ // Verify correct version is being used
17+ expect ( getByTestId ( 'vsn' ) ) . toHaveTextContent ( vsn )
18+
19+ // Initially, the status should be empty
20+ expect ( getByTestId ( 'realtime_status' ) ) . toHaveTextContent ( '' )
21+
22+ // Wait for the subscription status to be updated
23+ await waitFor (
24+ ( ) => {
25+ const status = getByTestId ( 'realtime_status' ) . props . children
26+ expect ( status ) . toBe ( 'SUBSCRIBED' )
27+ } ,
28+ {
29+ timeout : 30000 , // 30 seconds timeout for waitFor
30+ interval : 1000 , // Check every second
31+ onTimeout : ( error ) => {
32+ const currentStatus = getByTestId ( 'realtime_status' ) . props . children
33+ throw new Error (
34+ `Timeout waiting for SUBSCRIBED status with vsn ${ vsn } . Current status: ${ currentStatus } . ${ error . message } `
35+ )
36+ } ,
37+ }
38+ )
39+
40+ // Unmount the component to trigger cleanup
41+ unmount ( )
42+ } , 35000 ) // 35 seconds timeout for the entire test
43+
44+ it ( 'can broadcast and receive messages' , async ( ) => {
45+ const { getByTestId, unmount } = render ( < Index vsn = { vsn } /> )
46+
47+ // Wait for subscription
48+ await waitFor (
49+ ( ) => {
50+ const status = getByTestId ( 'realtime_status' ) . props . children
51+ expect ( status ) . toBe ( 'SUBSCRIBED' )
52+ } ,
53+ {
54+ timeout : 30000 ,
55+ interval : 1000 ,
56+ }
57+ )
58+
59+ // Wait for broadcast message to be received
60+ await waitFor (
61+ ( ) => {
62+ const message = getByTestId ( 'received_message' ) . props . children
63+ expect ( message ) . toBe ( 'Hello from Expo!' )
64+ } ,
65+ {
66+ timeout : 30000 ,
67+ interval : 1000 ,
68+ onTimeout : ( error ) => {
69+ const currentMessage = getByTestId ( 'received_message' ) . props . children
70+ throw new Error (
71+ `Timeout waiting for broadcast message with vsn ${ vsn } . Current message: ${ currentMessage } . ${ error . message } `
72+ )
73+ } ,
74+ }
75+ )
76+
77+ // Unmount the component to trigger cleanup
78+ unmount ( )
79+ } , 35000 ) // 35 seconds timeout for the entire test
80+ } )
81+ } )
3682} )
0 commit comments