account balance is rendered dynamically on top of sidebar menu

This commit is contained in:
Moriz Wahl 2021-04-29 18:23:57 +02:00
parent b7301c1219
commit 7713b68855
4 changed files with 28 additions and 36 deletions

View File

@ -49,12 +49,13 @@ const communityAPI = {
}
return apiPost(CONFIG.COMMUNITY_API__URL + 'createCoins/', payload)
},*/
send: async (session_id, email, amount, memo) => {
send: async (session_id, email, amount, memo, target_date) => {
const payload = {
session_id,
email,
amount,
memo,
target_date,
auto_sign: true,
}
return apiPost(CONFIG.COMMUNITY_API_URL + 'sendCoins/', payload)

View File

@ -244,26 +244,26 @@ export default {
//event.preventDefault()
this.ajaxCreateData.email = this.form.email
this.ajaxCreateData.amount = this.form.amount
this.ajaxCreateData.target_date = Date.now()
const now = new Date(Date.now()).toISOString()
this.ajaxCreateData.target_date = now
this.ajaxCreateData.memo = this.form.memo
this.$emit('toggle-show-list', false)
this.row_check = true
this.row_thx = false
},
async sendTransaction() {
this.ajaxCreateData.amount = this.ajaxCreateData.amount * 10000
const result = await communityAPI.send(
this.$store.state.session_id,
this.ajaxCreateData.email,
this.ajaxCreateData.amount,
this.ajaxCreateData.amount * 10000,
this.ajaxCreateData.memo,
this.ajaxCreateData.target_date,
)
if (result.success) {
this.$emit('toggle-show-list', false)
this.row_check = false
this.row_thx = true
this.$emit('update-balance', { ammount: Number(this.ajaxCreateData.amount) })
this.$emit('update-balance', { ammount: this.ajaxCreateData.amount })
} else {
alert('error')
this.$emit('toggle-show-list', true)

View File

@ -9,7 +9,6 @@ describe('GddStatus', () => {
let state = {
user: {
balance: 1234,
balance_gdt: 9876,
},
}
@ -22,8 +21,12 @@ describe('GddStatus', () => {
$n: jest.fn((n) => n),
}
let propsData = {
balance: 1234,
}
const Wrapper = () => {
return mount(GddStatus, { localVue, store, mocks })
return mount(GddStatus, { localVue, store, mocks, propsData })
}
describe('mount', () => {

View File

@ -1,26 +1,17 @@
import { shallowMount } from '@vue/test-utils'
import KontoOverview from './KontoOverview'
import Vuex from 'vuex'
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 })
return shallowMount(KontoOverview, { localVue, mocks })
}
describe('shallow Mount', () => {
@ -44,37 +35,34 @@ describe('KontoOverview', () => {
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', () => {
describe('updateBalance method', () => {
beforeEach(async () => {
wrapper.find('gdd-send-stub').vm.$emit('change-rows', {
row_form: false,
row_check: true,
row_thx: true,
wrapper.find('gdd-send-stub').vm.$emit('update-balance', {
ammount: 42,
})
await wrapper.vm.$nextTick()
})
it('updates row_form data when change-rows is emitted', () => {
expect(wrapper.vm.row_form).toBeFalsy()
it('emmits updateBalance with correct value', () => {
expect(wrapper.emitted('update-balance')).toEqual([[42]])
})
})
describe('toggleShowList method', () => {
beforeEach(async () => {
wrapper.setProps({ showTransactionList: false })
wrapper.find('gdd-send-stub').vm.$emit('toggle-show-list', true)
await wrapper.vm.$nextTick()
})
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()
it('changes the value of property showTransactionList', () => {
expect(wrapper.vm.showTransactionList).toBeTruthy()
})
})
})