mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
moved to QrCode folder
This commit is contained in:
parent
a8f228f3a9
commit
8e4628c220
@ -1,70 +0,0 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -1,72 +0,0 @@
|
||||
<template>
|
||||
<b-alert show variant="secondary">
|
||||
<!-- eslint-disable-next-line @intlify/vue-i18n/no-v-html -->
|
||||
<span class="alert-text" v-html="$t('form.scann_code')"></span>
|
||||
<b-col v-show="!scan" lg="12" class="text-right">
|
||||
<a @click="toggle" class="nav-link pointer">
|
||||
<img src="img/icons/gradido/qr-scan-pure.png" height="50" />
|
||||
</a>
|
||||
</b-col>
|
||||
|
||||
<div v-if="scan">
|
||||
<b-row>
|
||||
<qrcode-capture @detect="onDetect" capture="user"></qrcode-capture>
|
||||
</b-row>
|
||||
|
||||
<qrcode-stream class="mt-3" @decode="onDecode" @detect="onDetect"></qrcode-stream>
|
||||
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col lg="8">
|
||||
<b-alert show variant="secondary">
|
||||
<!-- eslint-disable-next-line @intlify/vue-i18n/no-v-html -->
|
||||
<span class="alert-text" v-html="$t('form.scann_code')"></span>
|
||||
</b-alert>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</div>
|
||||
<div @click="toggle">
|
||||
<b-alert v-show="scan" show variant="primary" class="pointer text-center">
|
||||
<span class="alert-text">
|
||||
<strong>{{ $t('form.cancel') }}</strong>
|
||||
</span>
|
||||
</b-alert>
|
||||
</div>
|
||||
</b-alert>
|
||||
</template>
|
||||
<script>
|
||||
import { QrcodeStream } from 'vue-qrcode-reader'
|
||||
|
||||
export default {
|
||||
name: 'QrCode',
|
||||
components: {
|
||||
QrcodeStream,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
scan: false,
|
||||
detect: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggle() {
|
||||
this.scan = !this.scan
|
||||
},
|
||||
async onDecode(decodedString) {
|
||||
const arr = JSON.parse(decodedString)
|
||||
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
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user