feat: Raise Test Coverage Frontend

This commit is contained in:
Moriz Wahl 2021-11-16 13:06:53 +01:00
parent b54558fa68
commit e8859544f7
3 changed files with 76 additions and 1 deletions

View File

@ -344,7 +344,7 @@ jobs:
report_name: Coverage Frontend report_name: Coverage Frontend
type: lcov type: lcov
result_path: ./coverage/lcov.info result_path: ./coverage/lcov.info
min_coverage: 85 min_coverage: 86
token: ${{ github.token }} token: ${{ github.token }}
############################################################################## ##############################################################################

View File

@ -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()
})
})
})
})
})

View File

@ -44,6 +44,7 @@ export default {
data() { data() {
return { return {
scan: false, scan: false,
detect: false,
} }
}, },
methods: { methods: {
@ -55,6 +56,10 @@ export default {
this.$emit('set-transaction', { email: arr[0].email, amount: arr[0].amount }) this.$emit('set-transaction', { email: arr[0].email, amount: arr[0].amount })
this.scan = false this.scan = false
}, },
async onDetect() {
// what is this for? I added the detect data to test that the method is called
this.detect = !this.detect
},
}, },
} }
</script> </script>