diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e09bdf8b8..f4d48c5c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -344,7 +344,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 85 + min_coverage: 86 token: ${{ github.token }} ############################################################################## diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 20a06c2b8..afc6decec 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -48,7 +48,7 @@ describe('CommunityResolver', () => { describe('getCommunityInfo', () => { it('returns the default values', async () => { - expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({ + await expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({ data: { getCommunityInfo: { name: 'Gradido Entwicklung', @@ -68,7 +68,7 @@ describe('CommunityResolver', () => { }) it('returns three communities', async () => { - expect(query({ query: communities })).resolves.toMatchObject({ + await expect(query({ query: communities })).resolves.toMatchObject({ data: { communities: [ { @@ -104,7 +104,7 @@ describe('CommunityResolver', () => { }) it('returns one community', async () => { - expect(query({ query: communities })).resolves.toMatchObject({ + await expect(query({ query: communities })).resolves.toMatchObject({ data: { communities: [ { diff --git a/frontend/src/plugins/globalComponents.test.js b/frontend/src/plugins/globalComponents.test.js new file mode 100644 index 000000000..294c5d616 --- /dev/null +++ b/frontend/src/plugins/globalComponents.test.js @@ -0,0 +1,29 @@ +import GlobalComponents from './globalComponents.js' +import Vue from 'vue' +import 'vee-validate' + +jest.mock('vue') +jest.mock('vee-validate', () => { + const originalModule = jest.requireActual('vee-validate') + return { + __esModule: true, + ...originalModule, + ValidationProvider: 'mocked validation provider', + ValidationObserver: 'mocked validation observer', + } +}) + +const vueComponentMock = jest.fn() +Vue.component = vueComponentMock + +describe('global Components', () => { + GlobalComponents.install(Vue) + + it('installs the validation provider', () => { + expect(vueComponentMock).toBeCalledWith('validation-provider', 'mocked validation provider') + }) + + it('installs the validation observer', () => { + expect(vueComponentMock).toBeCalledWith('validation-observer', 'mocked validation observer') + }) +}) diff --git a/frontend/src/views/Pages/SendOverview/GddSend/QrCode.spec.js b/frontend/src/views/Pages/SendOverview/GddSend/QrCode.spec.js new file mode 100644 index 000000000..66da5748d --- /dev/null +++ b/frontend/src/views/Pages/SendOverview/GddSend/QrCode.spec.js @@ -0,0 +1,70 @@ +import { mount } from '@vue/test-utils' +import QrCode from './QrCode' + +const localVue = global.localVue + +describe('QrCode', () => { + let wrapper + + const mocks = { + $t: jest.fn((t) => t), + } + + const stubs = { + QrcodeStream: true, + QrcodeCapture: true, + } + + const Wrapper = () => { + return mount(QrCode, { localVue, mocks, stubs }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the component', () => { + expect(wrapper.find('div.alert').exists()).toBeTruthy() + }) + + describe('scanning', () => { + beforeEach(async () => { + wrapper.find('a').trigger('click') + }) + + it('has a scanning stream', () => { + expect(wrapper.findComponent({ name: 'QrcodeStream' }).exists()).toBeTruthy() + }) + + describe('decode', () => { + beforeEach(async () => { + await wrapper + .findComponent({ name: 'QrcodeStream' }) + .vm.$emit('decode', '[{"email": "user@example.org", "amount": 10.0}]') + }) + + it('emits set transaction', () => { + expect(wrapper.emitted()['set-transaction']).toEqual([ + [ + { + email: 'user@example.org', + amount: 10, + }, + ], + ]) + }) + }) + + describe('detect', () => { + beforeEach(async () => { + await wrapper.find('div.row > *').vm.$emit('detect') + }) + + it('calls onDetect', () => { + expect(wrapper.vm.detect).toBeTruthy() + }) + }) + }) + }) +}) diff --git a/frontend/src/views/Pages/SendOverview/GddSend/QrCode.vue b/frontend/src/views/Pages/SendOverview/GddSend/QrCode.vue index edf027aef..0146621ed 100644 --- a/frontend/src/views/Pages/SendOverview/GddSend/QrCode.vue +++ b/frontend/src/views/Pages/SendOverview/GddSend/QrCode.vue @@ -44,6 +44,7 @@ export default { data() { return { scan: false, + detect: false, } }, methods: { @@ -55,6 +56,10 @@ export default { this.$emit('set-transaction', { email: arr[0].email, amount: arr[0].amount }) this.scan = false }, + async onDetect() { + // TODO: what is this for? I added the detect data to test that the method is called + this.detect = !this.detect + }, }, }