@@ -1682,7 +1682,7 @@ describe(`Electric Integration`, () => {
16821682      ) 
16831683    } ) 
16841684
1685-     it ( `should request incremental snapshots in progressive mode when syncMore is called` ,  async  ( )  =>  { 
1685+     it ( `should request incremental snapshots in progressive mode when syncMore is called before sync completes ` ,  async  ( )  =>  { 
16861686      vi . clearAllMocks ( ) 
16871687
16881688      const  config  =  { 
@@ -1700,14 +1700,26 @@ describe(`Electric Integration`, () => {
17001700
17011701      const  testCollection  =  createCollection ( electricCollectionOptions ( config ) ) 
17021702
1703-       // Send up-to-date to mark collection as ready  
1703+       // Send initial data with snapshot-end (but not  up-to-date yet - still syncing)  
17041704      subscriber ( [ 
17051705        { 
1706-           headers : {  control : `up-to-date`  } , 
1706+           key : `1` , 
1707+           value : {  id : 1 ,  name : `Test User`  } , 
1708+           headers : {  operation : `insert`  } , 
1709+         } , 
1710+         { 
1711+           headers : { 
1712+             control : `snapshot-end` , 
1713+             xmin : `100` , 
1714+             xmax : `110` , 
1715+             xip_list : [ ] , 
1716+           } , 
17071717        } , 
17081718      ] ) 
17091719
1710-       // In progressive mode, calling syncMore should request a snapshot 
1720+       expect ( testCollection . status ) . toBe ( `loading` )  // Not ready yet 
1721+ 
1722+       // In progressive mode, calling syncMore should request a snapshot BEFORE full sync completes 
17111723      await  testCollection . syncMore ( {  limit : 20  } ) 
17121724
17131725      // Verify requestSnapshot was called 
@@ -1769,23 +1781,133 @@ describe(`Electric Integration`, () => {
17691781
17701782      const  testCollection  =  createCollection ( electricCollectionOptions ( config ) ) 
17711783
1772-       // Send initial data and  up-to-date 
1784+       // Send initial data with snapshot-end (but not  up-to-date - still syncing)  
17731785      subscriber ( [ 
17741786        { 
17751787          key : `1` , 
17761788          value : {  id : 1 ,  name : `Initial User`  } , 
17771789          headers : {  operation : `insert`  } , 
17781790        } , 
1791+         { 
1792+           headers : { 
1793+             control : `snapshot-end` , 
1794+             xmin : `100` , 
1795+             xmax : `110` , 
1796+             xip_list : [ ] , 
1797+           } , 
1798+         } , 
1799+       ] ) 
1800+ 
1801+       // Collection should have data but not be ready yet 
1802+       expect ( testCollection . status ) . toBe ( `loading` ) 
1803+       expect ( testCollection . has ( 1 ) ) . toBe ( true ) 
1804+ 
1805+       // Should be able to request more data incrementally before full sync completes 
1806+       await  testCollection . syncMore ( {  limit : 10  } ) 
1807+       expect ( mockRequestSnapshot ) . toHaveBeenCalled ( ) 
1808+ 
1809+       // Now send up-to-date to complete the sync 
1810+       subscriber ( [ 
17791811        { 
17801812          headers : {  control : `up-to-date`  } , 
17811813        } , 
17821814      ] ) 
17831815
1784-       // Collection should be ready with initial data 
17851816      expect ( testCollection . status ) . toBe ( `ready` ) 
1817+     } ) 
1818+ 
1819+     it ( `should stop requesting snapshots in progressive mode after first up-to-date` ,  async  ( )  =>  { 
1820+       vi . clearAllMocks ( ) 
1821+ 
1822+       const  config  =  { 
1823+         id : `progressive-stop-after-sync-test` , 
1824+         shapeOptions : { 
1825+           url : `http://test-url` , 
1826+           params : { 
1827+             table : `test_table` , 
1828+           } , 
1829+         } , 
1830+         syncMode : `progressive`  as  const , 
1831+         getKey : ( item : Row )  =>  item . id  as  number , 
1832+         startSync : true , 
1833+       } 
1834+ 
1835+       const  testCollection  =  createCollection ( electricCollectionOptions ( config ) ) 
1836+ 
1837+       // Send initial data with snapshot-end (not up-to-date yet) 
1838+       subscriber ( [ 
1839+         { 
1840+           key : `1` , 
1841+           value : {  id : 1 ,  name : `User 1`  } , 
1842+           headers : {  operation : `insert`  } , 
1843+         } , 
1844+         { 
1845+           headers : { 
1846+             control : `snapshot-end` , 
1847+             xmin : `100` , 
1848+             xmax : `110` , 
1849+             xip_list : [ ] , 
1850+           } , 
1851+         } , 
1852+       ] ) 
1853+ 
1854+       expect ( testCollection . status ) . toBe ( `loading` )  // Not ready yet in progressive 
17861855      expect ( testCollection . has ( 1 ) ) . toBe ( true ) 
17871856
1788-       // Should still be able to request more data incrementally 
1857+       // Should be able to request more data before up-to-date 
1858+       vi . clearAllMocks ( ) 
1859+       await  testCollection . syncMore ( {  limit : 10  } ) 
1860+       expect ( mockRequestSnapshot ) . toHaveBeenCalledTimes ( 1 ) 
1861+ 
1862+       // Now send up-to-date to complete the full sync 
1863+       subscriber ( [ 
1864+         { 
1865+           headers : {  control : `up-to-date`  } , 
1866+         } , 
1867+       ] ) 
1868+ 
1869+       expect ( testCollection . status ) . toBe ( `ready` ) 
1870+ 
1871+       // Try to request more data - should NOT make a request since full sync is complete 
1872+       vi . clearAllMocks ( ) 
1873+       await  testCollection . syncMore ( {  limit : 10  } ) 
1874+       expect ( mockRequestSnapshot ) . not . toHaveBeenCalled ( ) 
1875+     } ) 
1876+ 
1877+     it ( `should allow snapshots in on-demand mode even after up-to-date` ,  async  ( )  =>  { 
1878+       vi . clearAllMocks ( ) 
1879+ 
1880+       const  config  =  { 
1881+         id : `on-demand-after-sync-test` , 
1882+         shapeOptions : { 
1883+           url : `http://test-url` , 
1884+           params : { 
1885+             table : `test_table` , 
1886+           } , 
1887+         } , 
1888+         syncMode : `on-demand`  as  const , 
1889+         getKey : ( item : Row )  =>  item . id  as  number , 
1890+         startSync : true , 
1891+       } 
1892+ 
1893+       const  testCollection  =  createCollection ( electricCollectionOptions ( config ) ) 
1894+ 
1895+       // Send initial data with up-to-date 
1896+       subscriber ( [ 
1897+         { 
1898+           key : `1` , 
1899+           value : {  id : 1 ,  name : `User 1`  } , 
1900+           headers : {  operation : `insert`  } , 
1901+         } , 
1902+         { 
1903+           headers : {  control : `up-to-date`  } , 
1904+         } , 
1905+       ] ) 
1906+ 
1907+       expect ( testCollection . status ) . toBe ( `ready` ) 
1908+ 
1909+       // Should STILL be able to request more data in on-demand mode 
1910+       vi . clearAllMocks ( ) 
17891911      await  testCollection . syncMore ( {  limit : 10  } ) 
17901912      expect ( mockRequestSnapshot ) . toHaveBeenCalled ( ) 
17911913    } ) 
0 commit comments