1+ import { mount , shallowMount } from "@vue/test-utils" ;
2+ import { createApp } from "vue" ;
3+ import * as All from "quasar" ;
4+ const { Quasar, date } = All ;
5+ import actions from "../../../src/store/actions" ;
6+ import mutations from "../../../src/store/mutations" ;
7+ import * as types from "../../../src/store/types" ;
8+ import Vuex from "vuex" ;
9+
10+ describe ( "Tests for copy and pasting" , ( ) => {
11+ const App = { }
12+ const app = createApp ( App ) ;
13+ app . use ( Quasar , Vuex ) ;
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+ } ) ;
38+
39+ test ( '"[types.copyActiveComponent]" action to commit COPY_ACTIVE_COMPONENT' , ( ) => {
40+ const commit = jest . fn ( ) ;
41+ actions [ types . copyActiveComponent ] ( { commit } ) ;
42+ expect ( commit ) . toHaveBeenCalledWith ( types . COPY_ACTIVE_COMPONENT ) ;
43+ } ) ;
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 ) ;
56+ } ) ;
57+
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+ } ) ;
62+
63+ } ) ;
0 commit comments