|
2 | 2 | /**
|
3 | 3 | * @jest-environment jsdom
|
4 | 4 | */
|
5 |
| - |
| 5 | +import mutations from "../../../src/store/mutations"; |
6 | 6 | import { mount, createLocalVue, shallowMount } from "@vue/test-utils";
|
7 |
| -import QBUTTON from "./demo/QBtn-demo.vue"; |
8 | 7 | import * as All from "quasar";
|
9 |
| -// import langEn from 'quasar/lang/en-us' // change to any language you wish! => this breaks wallaby :( |
10 | 8 | const { Quasar, date } = All;
|
11 | 9 |
|
12 |
| -const components = Object.keys(All).reduce((object, key) => { |
13 |
| - const val = All[key]; |
14 |
| - if (val && val.component && val.component.name != null) { |
15 |
| - object[key] = val; |
16 |
| - } |
17 |
| - return object; |
18 |
| -}, {}); |
19 |
| - |
20 |
| -describe("Test Suite - Delete from userActions and/or componentMap", () => { |
21 |
| - const localVue = createLocalVue(); |
22 |
| - localVue.use(Quasar, { components }); |
23 |
| - const testValue = false; |
24 |
| - it("does this produce the correct result ahahaha", () => { |
25 |
| - expect(testValue).toBe(false); |
| 10 | +describe("Test mutations + actions to remove action from component and userActions", () => { |
| 11 | + let state; |
| 12 | + beforeEach(() => { |
| 13 | + state = { |
| 14 | + componentMap: { |
| 15 | + component: { |
| 16 | + componentName: "App", |
| 17 | + children: ["HomeView"], |
| 18 | + htmlList: [], |
| 19 | + mapActions: ["action"] |
| 20 | + } |
| 21 | + }, |
| 22 | + activeComponent: "component", |
| 23 | + userActions: ["action"] |
| 24 | + }; |
26 | 25 | });
|
27 |
| -}); |
28 |
| - |
29 |
| -/** |
30 |
| - * @description: Tests for deleting state |
31 |
| - * @summary: |
32 |
| - * `deleteUserState` invokes removeStateFromComponent |
33 |
| - * `removeStateFromComponent` mutation that deletes state from userStore |
34 |
| - * `userStore` holds the user defined state objects |
35 |
| - * |
36 |
| - */ |
37 |
| - |
38 |
| -// describe("Test Suite - Delete from userState(?) and/or componentMap", () => { |
39 |
| -// const localVue = createLocalVue(); |
40 |
| -// localVue.use(Quasar, { components }); |
41 |
| -// const dumVal = false; |
42 |
| -// it("removeStateFromComponent deletes item from userStore", () => { |
43 | 26 |
|
44 |
| -// expect(dumVal).toBe(false); |
45 |
| -// }); |
46 |
| -// it("removeStateFromComponent deletes the appropriate item from userStore", () => { |
47 |
| -// expect(dumVal).toBe(false); |
48 |
| -// }); |
49 |
| -// it("removeStateFromComponent deletes the appropriate item from component in componentMap", () => { |
50 |
| -// expect(dumVal).toBe(false); |
51 |
| -// }); |
52 |
| -// it("deleteUserState invokes removeStateFromComponent", () => { |
53 |
| -// expect(dumVal).toBe(false); |
54 |
| -// }); |
55 |
| -// it("deleteUserState payload deletes the appropriate item from userStore", () => { |
56 |
| -// expect(dumVal).toBe(false); |
57 |
| -// }); |
58 |
| -// }); |
59 |
| -// describe('Mount Quasar', () => { |
60 |
| -// const localVue = createLocalVue() |
61 |
| -// localVue.use(Quasar, { components }) // , lang: langEn |
62 |
| - |
63 |
| -// const wrapper = mount(QBUTTON, { |
64 |
| -// localVue |
65 |
| -// }) |
66 |
| -// const vm = wrapper.vm |
67 |
| - |
68 |
| -// it('passes the sanity check and creates a wrapper', () => { |
69 |
| -// expect(wrapper.isVueInstance()).toBe(true) |
70 |
| -// }) |
| 27 | + it("deleting user action from state.userActions", () => { |
| 28 | + mutations.DELETE_USER_ACTIONS(state, "action"); |
| 29 | + expect(state.userActions.length).toBe(0); |
| 30 | + }); |
71 | 31 |
|
72 |
| -// it('has a created hook', () => { |
73 |
| -// expect(typeof vm.increment).toBe('function') |
74 |
| -// }) |
| 32 | + it('deleting "action" from componentMap', () => { |
| 33 | + mutations.REMOVE_ACTION_FROM_COMPONENT(state, "action"); |
| 34 | + expect(state.componentMap.component.mapActions.length).toBe(0); |
| 35 | + }); |
| 36 | +}); |
75 | 37 |
|
76 |
| -// it('accesses the shallowMount', () => { |
77 |
| -// expect(vm.$el.textContent).toContain('rocket muffin') |
78 |
| -// expect(wrapper.text()).toContain('rocket muffin') // easier |
79 |
| -// expect(wrapper.find('p').text()).toContain('rocket muffin') |
80 |
| -// }) |
| 38 | +describe("Adding actions and state to components", () => { |
| 39 | + let state; |
| 40 | + beforeEach(() => { |
| 41 | + state = { |
| 42 | + componentMap: { |
| 43 | + testComponent: { |
| 44 | + componentName: "testComponent", |
| 45 | + children: [], |
| 46 | + htmlList: [], |
| 47 | + componentActions: [], |
| 48 | + componentState: [] |
| 49 | + } |
| 50 | + }, |
| 51 | + activeComponent: "testComponent" |
| 52 | + }; |
| 53 | + }); |
| 54 | + describe("Adding actions to components", () => { |
| 55 | + it("should add a single action to active component", () => { |
| 56 | + mutations.ADD_TO_COMPONENT_ACTIONS(state, "testAction"); |
| 57 | + expect( |
| 58 | + state.componentMap[state.activeComponent].componentActions |
| 59 | + ).toEqual(["testAction"]); |
| 60 | + }); |
| 61 | + }); |
| 62 | + describe("Adding state to components", () => { |
| 63 | + it("should add a single state string to active component", () => { |
| 64 | + mutations.ADD_TO_COMPONENT_STATE(state, "testState"); |
| 65 | + expect(state.componentMap[state.activeComponent].componentState).toEqual([ |
| 66 | + "testState" |
| 67 | + ]); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
81 | 71 |
|
82 |
| -// it('sets the correct default data', () => { |
83 |
| -// expect(typeof vm.counter).toBe('number') |
84 |
| -// const defaultData2 = QBUTTON.data() |
85 |
| -// expect(defaultData2.counter).toBe(0) |
86 |
| -// }) |
| 72 | +describe("userActions mutation", () => { |
| 73 | + let actions; |
| 74 | + let store; |
| 75 | + beforeEach(() => { |
| 76 | + store = { |
| 77 | + userActions: [] |
| 78 | + }; |
| 79 | + }); |
| 80 | + it("should push user defined action to end of userActions array", () => { |
| 81 | + mutations.ADD_USER_ACTION(store, "actionnnn"); |
| 82 | + expect(store.userActions[store.userActions.length - 1]).toBe("actionnnn"); |
| 83 | + }); |
| 84 | + it("should only push to array if payload is of type string", () => { |
| 85 | + mutations.ADD_USER_ACTION(store, 66); |
| 86 | + expect(store.userActions).toStrictEqual([]); |
| 87 | + }); |
| 88 | +}); |
87 | 89 |
|
88 |
| -// it('correctly updates data when button is pressed', () => { |
89 |
| -// const button = wrapper.find('button') |
90 |
| -// button.trigger('click') |
91 |
| -// expect(vm.counter).toBe(1) |
92 |
| -// }) |
| 90 | +describe("userStore mutation", () => { |
| 91 | + let actions; |
| 92 | + let store; |
| 93 | + store = { |
| 94 | + userStore: {} |
| 95 | + }; |
| 96 | + it("should be able to update store with a key defined by the user and a value of type object", () => { |
| 97 | + mutations.ADD_TO_USER_STORE(store, { dummyKey: {} }); |
| 98 | + // console.log('store.userStore.dummyKey', store.userStore.dummyKey); |
| 99 | + expect(store.userStore.dummyKey).toStrictEqual({}); |
| 100 | + }); |
| 101 | + it("should update user store with a key value pair with value strictly equal to empty array", () => { |
| 102 | + mutations.ADD_TO_USER_STORE(store, { dummyKey: [] }); |
| 103 | + expect(store.userStore.dummyKey).toStrictEqual([]); |
| 104 | + }); |
| 105 | + it("should be able to store booleans in the store as the key", () => { |
| 106 | + mutations.ADD_TO_USER_STORE(store, { boolean: true }); |
| 107 | + expect(store.userStore.boolean).toBe(true); |
| 108 | + }); |
| 109 | + it("should add to userStore a key with a value of type number", () => { |
| 110 | + mutations.ADD_TO_USER_STORE(store, { number: 696 }); |
| 111 | + expect(store.userStore.number).toBe(696); |
| 112 | + }); |
93 | 113 |
|
94 |
| -// it('formats a date without throwing exception', () => { |
95 |
| -// // test will automatically fail if an exception is thrown |
96 |
| -// // MMMM and MMM require that a language is 'installed' in Quasar |
97 |
| -// let formattedString = date.formatDate(Date.now(), 'YYYY MMMM MMM DD') |
98 |
| -// console.log('formattedString', formattedString) |
99 |
| -// }) |
100 |
| -// }) |
| 114 | + it("should work with strings too", () => { |
| 115 | + mutations.ADD_TO_USER_STORE(store, { string: "string" }); |
| 116 | + expect(store.userStore.string).toBe("string"); |
| 117 | + }); |
| 118 | +}); |
0 commit comments