@@ -6,24 +6,58 @@ import actions from "../../../src/store/actions";
66import mutations from "../../../src/store/mutations" ;
77import * as types from "../../../src/store/types" ;
88import Vuex from "vuex" ;
9- import store from "../../../src/store/state/index" ;
109
1110describe ( "Tests for copy and pasting" , ( ) => {
1211 const App = { }
1312 const app = createApp ( App ) ;
1413 app . use ( Quasar , Vuex ) ;
15- const state = { ...store }
14+ let state ;
15+ beforeEach ( ( ) => {
16+ state = {
17+ componentMap : {
18+ testComp : {
19+ componentName : "testComp" ,
20+ children : [ ] ,
21+ htmlList : [ ] ,
22+ componentActions : [ ] ,
23+ state : [ "state1" , "state2" ] ,
24+ actions : [ "action1" , "action2" ]
25+ }
26+ } ,
27+ activeComponent : "test" ,
28+ userState : [ 'state1' , 'state2' ] ,
29+ userActions : [ 'action1' , 'action2' ] ,
30+ userProps : [ 'prop1' , 'prop2' ] ,
31+ routes : {
32+ HomeView : [ { componentName : 'testComp' , parent : [ ] } ] ,
33+ } ,
34+ activeRoute : 'HomeView' ,
35+ pasteTimer : 0 ,
36+ } ;
37+ } ) ;
1638
1739 test ( '"[types.copyActiveComponent]" action to commit COPY_ACTIVE_COMPONENT' , ( ) => {
1840 const commit = jest . fn ( ) ;
19- actions [ types . copyActiveComponent ] ( { commit } , { } ) ;
20- expect ( commit ) . toHaveBeenCalledWith ( types . COPY_ACTIVE_COMPONENT , { } ) ;
41+ actions [ types . copyActiveComponent ] ( { commit } ) ;
42+ expect ( commit ) . toHaveBeenCalledWith ( types . COPY_ACTIVE_COMPONENT ) ;
2143 } ) ;
22- test ( '"[types.pasteActiveComponent]" action to commit PASTE_ACTIVE_COMPONENT' , ( ) => {
23- const commit = jest . fn ( ) ;
24- actions [ types . pasteActiveComponent ] ( { commit } , { } ) ;
25- expect ( commit ) . toHaveBeenCalledWith ( types . PASTE_ACTIVE_COMPONENT , { } ) ;
44+
45+ test ( '"[types.COPY_ACTIVE_COMPONENT]" to update state successfully' , ( ) => {
46+ mutations [ types . SET_ACTIVE_COMPONENT ] ( state , 'testComp' ) ;
47+ mutations [ types . COPY_ACTIVE_COMPONENT ] ( state ) ;
48+ expect ( state . copiedComponent . componentName ) . toBe ( 'testComp' ) ;
49+ } )
50+
51+ test ( '"[types.PASTE_ACTIVE_COMPONENT]" to update state successfully' , ( ) => {
52+ mutations [ types . SET_ACTIVE_COMPONENT ] ( state , 'testComp' ) ;
53+ mutations [ types . COPY_ACTIVE_COMPONENT ] ( state ) ;
54+ mutations [ types . PASTE_ACTIVE_COMPONENT ] ( state ) ;
55+ expect ( Object . keys ( state . componentMap ) . length ) . toBe ( 2 ) ;
2656 } ) ;
2757
58+ test ( '"[types.PASTE_ACTIVE_COMPONENT]" to throttle via state paste timer' , ( ) => {
59+ mutations [ types . UPDATE_PASTE_TIMER ] ( state ) ;
60+ expect ( state . pasteTimer ) . not . toBe ( 0 ) ;
61+ } ) ;
2862
2963} ) ;
0 commit comments