@@ -113,8 +113,8 @@ import {
113113} from '../shared/mocks' ;
114114import { ActionPayload , ContentTypeDragPayload } from '../shared/models' ;
115115import { UVEStore } from '../store/dot-uve.store' ;
116- import { SDK_EDITOR_SCRIPT_SOURCE , TEMPORAL_DRAG_ITEM } from '../utils' ;
117116import * as uveUtils from '../utils' ;
117+ import { SDK_EDITOR_SCRIPT_SOURCE , TEMPORAL_DRAG_ITEM } from '../utils' ;
118118
119119global . URL . createObjectURL = jest . fn (
120120 ( ) => 'blob:http://localhost:3000/12345678-1234-1234-1234-123456789012'
@@ -617,6 +617,350 @@ describe('EditEmaEditorComponent', () => {
617617 } ) ;
618618 } ) ;
619619
620+ describe ( 'checkAndResetActiveContentlet' , ( ) => {
621+ let resetActiveContentletSpy : jest . SpyInstance ;
622+
623+ beforeEach ( ( ) => {
624+ resetActiveContentletSpy = jest . spyOn ( store , 'resetActiveContentlet' ) ;
625+ } ) ;
626+
627+ afterEach ( ( ) => {
628+ resetActiveContentletSpy . mockClear ( ) ;
629+ } ) ;
630+
631+ describe ( 'on delete' , ( ) => {
632+ it ( 'should reset activeContentlet when deleting the active contentlet' , ( ) => {
633+ const activeContentlet : ActionPayload = {
634+ pageId : '123' ,
635+ language_id : '1' ,
636+ container : {
637+ identifier : 'container-1' ,
638+ uuid : 'uuid-1' ,
639+ acceptTypes : 'test' ,
640+ maxContentlets : 1 ,
641+ contentletsId : [ 'contentlet-1' ]
642+ } ,
643+ pageContainers : [
644+ {
645+ identifier : 'container-1' ,
646+ uuid : 'uuid-1' ,
647+ contentletsId : [ 'contentlet-1' ]
648+ }
649+ ] ,
650+ contentlet : {
651+ identifier : 'contentlet-1' ,
652+ inode : 'inode-1' ,
653+ title : 'Test' ,
654+ contentType : 'test'
655+ }
656+ } ;
657+
658+ store . setActiveContentlet ( activeContentlet ) ;
659+
660+ const payload : ActionPayload = {
661+ pageId : '123' ,
662+ language_id : '1' ,
663+ container : {
664+ identifier : 'container-1' ,
665+ uuid : 'uuid-1' ,
666+ acceptTypes : 'test' ,
667+ maxContentlets : 1 ,
668+ contentletsId : [ 'contentlet-1' ]
669+ } ,
670+ pageContainers : [
671+ {
672+ identifier : 'container-1' ,
673+ uuid : 'uuid-1' ,
674+ contentletsId : [ 'contentlet-1' ]
675+ }
676+ ] ,
677+ contentlet : {
678+ identifier : 'contentlet-1' ,
679+ inode : 'inode-1' ,
680+ title : 'Test' ,
681+ contentType : 'test'
682+ }
683+ } ;
684+
685+ store . setContentletArea ( {
686+ x : 100 ,
687+ y : 100 ,
688+ width : 500 ,
689+ height : 500 ,
690+ payload
691+ } ) ;
692+
693+ spectator . detectChanges ( ) ;
694+
695+ const confirmDialog = spectator . query ( byTestId ( 'confirm-dialog' ) ) ;
696+
697+ spectator . triggerEventHandler (
698+ DotUveContentletToolsComponent ,
699+ 'deleteContent' ,
700+ payload
701+ ) ;
702+
703+ spectator . detectComponentChanges ( ) ;
704+
705+ confirmDialog
706+ . querySelector ( '.p-confirm-dialog-accept' )
707+ . dispatchEvent ( new Event ( 'click' ) ) ;
708+
709+ expect ( resetActiveContentletSpy ) . toHaveBeenCalledTimes ( 1 ) ;
710+ } ) ;
711+
712+ it ( 'should not reset activeContentlet when deleting a different contentlet' , ( ) => {
713+ const activeContentlet : ActionPayload = {
714+ pageId : '123' ,
715+ language_id : '1' ,
716+ container : {
717+ identifier : 'container-1' ,
718+ uuid : 'uuid-1' ,
719+ acceptTypes : 'test' ,
720+ maxContentlets : 1 ,
721+ contentletsId : [ 'contentlet-1' , 'contentlet-2' ]
722+ } ,
723+ pageContainers : [
724+ {
725+ identifier : 'container-1' ,
726+ uuid : 'uuid-1' ,
727+ contentletsId : [ 'contentlet-1' , 'contentlet-2' ]
728+ }
729+ ] ,
730+ contentlet : {
731+ identifier : 'contentlet-1' ,
732+ inode : 'inode-1' ,
733+ title : 'Test' ,
734+ contentType : 'test'
735+ }
736+ } ;
737+
738+ store . setActiveContentlet ( activeContentlet ) ;
739+
740+ const payload : ActionPayload = {
741+ pageId : '123' ,
742+ language_id : '1' ,
743+ container : {
744+ identifier : 'container-1' ,
745+ uuid : 'uuid-1' ,
746+ acceptTypes : 'test' ,
747+ maxContentlets : 1 ,
748+ contentletsId : [ 'contentlet-1' , 'contentlet-2' ]
749+ } ,
750+ pageContainers : [
751+ {
752+ identifier : 'container-1' ,
753+ uuid : 'uuid-1' ,
754+ contentletsId : [ 'contentlet-1' , 'contentlet-2' ]
755+ }
756+ ] ,
757+ contentlet : {
758+ identifier : 'contentlet-2' ,
759+ inode : 'inode-2' ,
760+ title : 'Other' ,
761+ contentType : 'test'
762+ }
763+ } ;
764+
765+ store . setContentletArea ( {
766+ x : 100 ,
767+ y : 100 ,
768+ width : 500 ,
769+ height : 500 ,
770+ payload
771+ } ) ;
772+
773+ spectator . detectChanges ( ) ;
774+
775+ const confirmDialog = spectator . query ( byTestId ( 'confirm-dialog' ) ) ;
776+
777+ spectator . triggerEventHandler (
778+ DotUveContentletToolsComponent ,
779+ 'deleteContent' ,
780+ payload
781+ ) ;
782+
783+ spectator . detectComponentChanges ( ) ;
784+
785+ confirmDialog
786+ . querySelector ( '.p-confirm-dialog-accept' )
787+ . dispatchEvent ( new Event ( 'click' ) ) ;
788+
789+ expect ( resetActiveContentletSpy ) . not . toHaveBeenCalled ( ) ;
790+ } ) ;
791+ } ) ;
792+
793+ describe ( 'on move' , ( ) => {
794+ it ( 'should reset activeContentlet when moving it to a different container' , ( ) => {
795+ const contentlet = CONTENTLETS_MOCK_FOR_EDITOR [ 0 ] ;
796+ const activeContentlet : ActionPayload = {
797+ pageId : '123' ,
798+ language_id : '1' ,
799+ container : {
800+ identifier : 'container-1' ,
801+ uuid : 'uuid-1' ,
802+ acceptTypes : 'Banner,Activity' ,
803+ maxContentlets : 25 ,
804+ contentletsId : [ contentlet . identifier ]
805+ } ,
806+ pageContainers : [
807+ {
808+ identifier : 'container-1' ,
809+ uuid : 'uuid-1' ,
810+ contentletsId : [ contentlet . identifier ]
811+ }
812+ ] ,
813+ contentlet : {
814+ identifier : contentlet . identifier ,
815+ inode : contentlet . inode ,
816+ title : contentlet . title ,
817+ contentType : contentlet . contentType
818+ }
819+ } ;
820+
821+ store . setActiveContentlet ( activeContentlet ) ;
822+
823+ const savePageSpy = jest . spyOn ( store , 'savePage' ) ;
824+
825+ store . setEditorDragItem ( {
826+ baseType : contentlet . baseType ,
827+ contentType : contentlet . contentType ,
828+ draggedPayload : {
829+ item : {
830+ contentlet : {
831+ ...contentlet ,
832+ identifier : contentlet . identifier
833+ } ,
834+ container : {
835+ acceptTypes : 'Banner,Activity' ,
836+ identifier : 'container-1' ,
837+ maxContentlets : 25 ,
838+ uuid : 'uuid-1'
839+ }
840+ } ,
841+ type : 'contentlet' ,
842+ move : true
843+ }
844+ } ) ;
845+
846+ const drop = new Event ( 'drop' ) ;
847+
848+ Object . defineProperty ( drop , 'target' , {
849+ writable : false ,
850+ value : {
851+ dataset : {
852+ dropzone : 'true' ,
853+ position : 'before' ,
854+ payload : JSON . stringify ( {
855+ container : {
856+ acceptTypes : 'Banner,Activity' ,
857+ identifier : 'container-2' ,
858+ maxContentlets : 25 ,
859+ uuid : 'uuid-2'
860+ } ,
861+ contentlet : {
862+ identifier : '456' ,
863+ title : 'Pivot' ,
864+ inode : 'pivot-inode' ,
865+ contentType : 'Banner'
866+ }
867+ } )
868+ }
869+ }
870+ } ) ;
871+
872+ window . dispatchEvent ( drop ) ;
873+
874+ expect ( savePageSpy ) . toHaveBeenCalled ( ) ;
875+ expect ( resetActiveContentletSpy ) . toHaveBeenCalledTimes ( 1 ) ;
876+ } ) ;
877+
878+ it ( 'should not reset activeContentlet when moving it within the same container' , ( ) => {
879+ const contentlet = CONTENTLETS_MOCK_FOR_EDITOR [ 0 ] ;
880+ const activeContentlet : ActionPayload = {
881+ pageId : '123' ,
882+ language_id : '1' ,
883+ container : {
884+ identifier : 'container-1' ,
885+ uuid : 'uuid-1' ,
886+ acceptTypes : 'Banner,Activity' ,
887+ maxContentlets : 25 ,
888+ contentletsId : [ contentlet . identifier , '456' ]
889+ } ,
890+ pageContainers : [
891+ {
892+ identifier : 'container-1' ,
893+ uuid : 'uuid-1' ,
894+ contentletsId : [ contentlet . identifier , '456' ]
895+ }
896+ ] ,
897+ contentlet : {
898+ identifier : contentlet . identifier ,
899+ inode : contentlet . inode ,
900+ title : contentlet . title ,
901+ contentType : contentlet . contentType
902+ }
903+ } ;
904+
905+ store . setActiveContentlet ( activeContentlet ) ;
906+
907+ const savePageSpy = jest . spyOn ( store , 'savePage' ) ;
908+
909+ store . setEditorDragItem ( {
910+ baseType : contentlet . baseType ,
911+ contentType : contentlet . contentType ,
912+ draggedPayload : {
913+ item : {
914+ contentlet : {
915+ ...contentlet ,
916+ identifier : contentlet . identifier
917+ } ,
918+ container : {
919+ acceptTypes : 'Banner,Activity' ,
920+ identifier : 'container-1' ,
921+ maxContentlets : 25 ,
922+ uuid : 'uuid-1'
923+ }
924+ } ,
925+ type : 'contentlet' ,
926+ move : true
927+ }
928+ } ) ;
929+
930+ const drop = new Event ( 'drop' ) ;
931+
932+ Object . defineProperty ( drop , 'target' , {
933+ writable : false ,
934+ value : {
935+ dataset : {
936+ dropzone : 'true' ,
937+ position : 'before' ,
938+ payload : JSON . stringify ( {
939+ container : {
940+ acceptTypes : 'Banner,Activity' ,
941+ identifier : 'container-1' ,
942+ maxContentlets : 25 ,
943+ uuid : 'uuid-1'
944+ } ,
945+ contentlet : {
946+ identifier : '456' ,
947+ title : 'Pivot' ,
948+ inode : 'pivot-inode' ,
949+ contentType : 'Banner'
950+ }
951+ } )
952+ }
953+ }
954+ } ) ;
955+
956+ window . dispatchEvent ( drop ) ;
957+
958+ expect ( savePageSpy ) . toHaveBeenCalled ( ) ;
959+ expect ( resetActiveContentletSpy ) . not . toHaveBeenCalled ( ) ;
960+ } ) ;
961+ } ) ;
962+ } ) ;
963+
620964 describe ( 'edit' , ( ) => {
621965 beforeEach ( ( ) => {
622966 store . setIsClientReady ( true ) ;
0 commit comments