diff --git a/frontend/jest.config.js b/frontend/jest.config.js index a06ebb205..f1082faad 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -17,7 +17,7 @@ module.exports = { '^.+\\.(js|jsx)?$': 'babel-jest', '/node_modules/vee-validate/dist/rules': 'babel-jest', }, - setupFiles: ['/test/testSetup.js'], + setupFiles: ['/test/testSetup.js', 'jest-canvas-mock'], testMatch: ['**/?(*.)+(spec|test).js?(x)'], // snapshotSerializers: ['jest-serializer-vue'], transformIgnorePatterns: ['/node_modules/(?!vee-validate/dist/rules)'], diff --git a/frontend/package.json b/frontend/package.json index 545290f94..80450b49b 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -49,6 +49,7 @@ "google-maps": "^3.2.1", "identity-obj-proxy": "^3.0.0", "jest": "^26.6.3", + "jest-canvas-mock": "^2.3.1", "nouislider": "^12.1.0", "particles-bg-vue": "1.2.3", "perfect-scrollbar": "^1.3.0", diff --git a/frontend/src/views/KontoOverview.spec.js b/frontend/src/views/KontoOverview.spec.js new file mode 100644 index 000000000..0e60de370 --- /dev/null +++ b/frontend/src/views/KontoOverview.spec.js @@ -0,0 +1,82 @@ +import { shallowMount } from '@vue/test-utils' +import KontoOverview from './KontoOverview' +import Vuex from 'vuex' +import VueCookies from 'vue-cookies' + +const localVue = global.localVue + +describe('KontoOverview', () => { + let wrapper + + let actions = { + accountBalance: jest.fn(), + } + + let store = new Vuex.Store({ + actions, + }) + + let mocks = { + $t: jest.fn((t) => t), + } + + const Wrapper = () => { + return shallowMount(KontoOverview, { localVue, store, mocks }) + } + + describe('shallow Mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a header', () => { + expect(wrapper.find('base-header-stub').exists()).toBeTruthy() + }) + + it('has a status line', () => { + expect(wrapper.find('gdd-status-stub').exists()).toBeTruthy() + }) + + it('has a send field', () => { + expect(wrapper.find('gdd-send-stub').exists()).toBeTruthy() + }) + + it('has a transactions table', () => { + expect(wrapper.find('gdd-table-stub').exists()).toBeTruthy() + }) + + it('calls "accountBalance" action from store on creation', () => { + const spy = jest.spyOn(actions, 'accountBalance') + expect(spy).toHaveBeenCalled() + }) + + it('updates transctions data when change-transactions is emitted', async () => { + wrapper.find('gdd-table-stub').vm.$emit('change-transactions', [0, 1]) + await wrapper.vm.$nextTick() + expect(wrapper.vm.transactions).toEqual(expect.arrayContaining([0, 1])) + }) + + describe('setRows method', () => { + beforeEach(async () => { + wrapper.find('gdd-send-stub').vm.$emit('change-rows', { + row_form: false, + row_check: true, + row_thx: true, + }) + await wrapper.vm.$nextTick() + }) + + it('updates row_form data when change-rows is emitted', () => { + expect(wrapper.vm.row_form).toBeFalsy() + }) + + it('updates row_check data when change-rows is emitted', () => { + expect(wrapper.vm.row_check).toBeTruthy() + }) + + it('updates row_thx data when change-rows is emitted', () => { + expect(wrapper.vm.row_thx).toBeTruthy() + }) + }) + }) +}) diff --git a/frontend/src/views/KontoOverview/GddStatus.spec.js b/frontend/src/views/KontoOverview/GddStatus.spec.js new file mode 100644 index 000000000..524ba23a6 --- /dev/null +++ b/frontend/src/views/KontoOverview/GddStatus.spec.js @@ -0,0 +1,42 @@ +import { mount } from '@vue/test-utils' +import GddStatus from './GddStatus' +import Vuex from 'vuex' + +const localVue = global.localVue + +describe('GddStatus', () => { + let wrapper + + let state = { + user: { + balance: 1234, + balance_gdt: 9876, + }, + } + + let store = new Vuex.Store({ + state, + }) + + let mocks = { + $n: jest.fn((n) => n), + } + + const Wrapper = () => { + return mount(GddStatus, { localVue, store, mocks }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('it displays the ammount of GDD', () => { + expect(wrapper.findAll('div.card-body').at(0).text()).toEqual('1234 GDD') + }) + + it('it displays the ammount of GDT', () => { + expect(wrapper.findAll('div.card-body').at(1).text()).toEqual('9876 GDT') + }) + }) +}) diff --git a/frontend/test/testSetup.js b/frontend/test/testSetup.js index 8d0e01c1e..497f04e3e 100644 --- a/frontend/test/testSetup.js +++ b/frontend/test/testSetup.js @@ -14,6 +14,8 @@ import SideBar from '@/components/SidebarPlugin' import VueRouter from 'vue-router' import BaseDropdown from '@/components/BaseDropdown.vue' import VueQrcode from 'vue-qrcode' +import BaseHeader from '@/components/BaseHeader' +import StatsCard from '@/components/Cards/StatsCard.vue' import clickOutside from '@/directives/click-ouside.js' @@ -40,5 +42,7 @@ global.localVue.component('validation-provider', ValidationProvider) global.localVue.component('validation-observer', ValidationObserver) global.localVue.component(BaseButton.name, BaseButton) global.localVue.component(BaseDropdown.name, BaseDropdown) +global.localVue.component(BaseHeader.name, BaseHeader) +global.localVue.component(StatsCard.name, StatsCard) global.localVue.directive('click-outside', clickOutside) diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 136e6b7ee..65be5ba39 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -3918,7 +3918,7 @@ color-name@1.1.3: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= -color-name@^1.0.0, color-name@~1.1.4: +color-name@^1.0.0, color-name@^1.1.4, color-name@~1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== @@ -4356,6 +4356,11 @@ cssesc@^3.0.0: resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg== +cssfontparser@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/cssfontparser/-/cssfontparser-1.2.1.tgz#f4022fc8f9700c68029d542084afbaf425a3f3e3" + integrity sha1-9AIvyPlwDGgCnVQghK+69CWj8+M= + cssnano-preset-default@^4.0.0, cssnano-preset-default@^4.0.7: version "4.0.7" resolved "https://registry.yarnpkg.com/cssnano-preset-default/-/cssnano-preset-default-4.0.7.tgz#51ec662ccfca0f88b396dcd9679cdb931be17f76" @@ -7811,6 +7816,14 @@ javascript-stringify@^1.6.0: resolved "https://registry.yarnpkg.com/javascript-stringify/-/javascript-stringify-1.6.0.tgz#142d111f3a6e3dae8f4a9afd77d45855b5a9cce3" integrity sha1-FC0RHzpuPa6PSpr9d9RYVbWpzOM= +jest-canvas-mock@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/jest-canvas-mock/-/jest-canvas-mock-2.3.1.tgz#9535d14bc18ccf1493be36ac37dd349928387826" + integrity sha512-5FnSZPrX3Q2ZfsbYNE3wqKR3+XorN8qFzDzB5o0golWgt6EOX1+emBnpOc9IAQ+NXFj8Nzm3h7ZdE/9H0ylBcg== + dependencies: + cssfontparser "^1.2.1" + moo-color "^1.0.2" + jest-changed-files@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-24.9.0.tgz#08d8c15eb79a7fa3fc98269bc14b451ee82f8039" @@ -9403,6 +9416,13 @@ moment@^2.10.2, moment@^2.19.2: resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3" integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== +moo-color@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/moo-color/-/moo-color-1.0.2.tgz#837c40758d2d58763825d1359a84e330531eca64" + integrity sha512-5iXz5n9LWQzx/C2WesGFfpE6RLamzdHwsn3KpfzShwbfIqs7stnoEpaNErf/7+3mbxwZ4s8Foq7I0tPxw7BWHg== + dependencies: + color-name "^1.1.4" + move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"