@@ -514,6 +514,36 @@ describe('Find composition', () => {
514514 expect ( findComposition && findComposition . data . value ) . toContainEqual ( changedTestModel ) ;
515515 } ) ;
516516
517+ it ( 'should keep order of items when handling "update" events' , async ( ) => {
518+ expect . assertions ( 3 ) ;
519+
520+ // given
521+ const emitter = eventHelper ( ) ;
522+ const feathersMock = {
523+ service : ( ) => ( {
524+ find : jest . fn ( ( ) => [ additionalTestModel2 , testModel , additionalTestModel ] ) ,
525+ on : emitter . on ,
526+ off : jest . fn ( ) ,
527+ } ) ,
528+ on : jest . fn ( ) ,
529+ off : jest . fn ( ) ,
530+ } as unknown as Application ;
531+ const useFind = useFindOriginal ( feathersMock ) ;
532+ let findComposition = null as UseFind < TestModel > | null ;
533+ mountComposition ( ( ) => {
534+ findComposition = useFind ( 'testModels' ) ;
535+ } ) ;
536+ await nextTick ( ) ;
537+
538+ // when
539+ emitter . emit ( 'updated' , changedTestModel ) ;
540+
541+ // then
542+ expect ( findComposition ) . toBeTruthy ( ) ;
543+ expect ( findComposition && findComposition . data . value ) . toHaveLength ( 3 ) ;
544+ expect ( findComposition && findComposition . data . value [ 1 ] ) . toStrictEqual ( changedTestModel ) ;
545+ } ) ;
546+
517547 it ( 'should listen to "patch" & "update" events when query is matching' , async ( ) => {
518548 expect . assertions ( 2 ) ;
519549
@@ -606,6 +636,39 @@ describe('Find composition', () => {
606636 expect ( findComposition && findComposition . data . value . length ) . toBe ( 0 ) ;
607637 } ) ;
608638
639+ it ( 'should listen to "patch" & "update" events and add item from list when query is matching now' , async ( ) => {
640+ expect . assertions ( 4 ) ;
641+
642+ // given
643+ const emitter = eventHelper ( ) ;
644+ const feathersMock = {
645+ service : ( ) => ( {
646+ find : jest . fn ( ( ) => [ ] ) ,
647+ on : emitter . on ,
648+ off : jest . fn ( ) ,
649+ } ) ,
650+ on : jest . fn ( ) ,
651+ off : jest . fn ( ) ,
652+ } as unknown as Application ;
653+ const useFind = useFindOriginal ( feathersMock ) ;
654+ let findComposition = null as UseFind < TestModel > | null ;
655+ mountComposition ( ( ) => {
656+ findComposition = useFind ( 'testModels' , ref ( { query : { category : changedTestModel . category } } ) ) ;
657+ } ) ;
658+
659+ // before then to ensure that the previous loading procedure is completed
660+ await nextTick ( ) ;
661+ expect ( findComposition && findComposition . isLoading . value ) . toBeFalsy ( ) ;
662+ expect ( findComposition && findComposition . data . value . length ) . toBe ( 0 ) ;
663+
664+ // when
665+ emitter . emit ( 'updated' , changedTestModel ) ;
666+
667+ // then
668+ expect ( findComposition ) . toBeTruthy ( ) ;
669+ expect ( findComposition && findComposition . data . value ) . toStrictEqual ( [ changedTestModel ] ) ;
670+ } ) ;
671+
609672 it ( 'should listen to "remove" events' , async ( ) => {
610673 expect . assertions ( 2 ) ;
611674
0 commit comments