Merge pull request #396 from gradido/pending-balance

feat: Dash is Shown When Balance is Loading
This commit is contained in:
Moriz Wahl 2021-05-12 13:49:01 +02:00 committed by GitHub
commit d1b6c90db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 175 additions and 18 deletions

View File

@ -0,0 +1,117 @@
import { mount, RouterLinkStub } from '@vue/test-utils'
import SideBar from './SideBar'
const localVue = global.localVue
describe('SideBar', () => {
let wrapper
const stubs = {
RouterLink: RouterLinkStub,
}
const propsData = {
balance: 1234.56,
}
const mocks = {
$store: {
state: {
email: 'test@example.org',
},
},
$i18n: {
locale: 'en',
},
$t: jest.fn((t) => t),
$n: jest.fn((n) => n),
}
const Wrapper = () => {
return mount(SideBar, { localVue, mocks, stubs, propsData })
}
describe('mount', () => {
beforeEach(() => {
wrapper = Wrapper()
})
it('renders the component', () => {
expect(wrapper.find('#sidenav-main').exists()).toBeTruthy()
})
describe('balance', () => {
it('shows em-dash as balance while loading', () => {
expect(wrapper.find('div.row.text-center').text()).toBe('— GDD')
})
it('shows the when loaded', async () => {
wrapper.setProps({
pending: false,
})
await wrapper.vm.$nextTick()
expect(wrapper.find('div.row.text-center').text()).toBe('1234.56 GDD')
})
})
describe('navbar button', () => {
it('has a navbar button', () => {
expect(wrapper.find('button.navbar-toggler').exists()).toBeTruthy()
})
it('calls showSidebar when clicked', async () => {
const spy = jest.spyOn(wrapper.vm.$sidebar, 'displaySidebar')
wrapper.find('button.navbar-toggler').trigger('click')
await wrapper.vm.$nextTick()
expect(spy).toHaveBeenCalledWith(true)
})
})
describe('close siedbar', () => {
it('calls closeSidebar when clicked', async () => {
const spy = jest.spyOn(wrapper.vm.$sidebar, 'displaySidebar')
wrapper.find('#sidenav-collapse-main').find('button.navbar-toggler').trigger('click')
await wrapper.vm.$nextTick()
expect(spy).toHaveBeenCalledWith(false)
})
})
describe('static menu items', () => {
describe("member's area", () => {
it('has a link to the elopage', () => {
expect(wrapper.findAll('li').at(0).text()).toBe('members_area')
})
it('links to the elopage', () => {
expect(wrapper.findAll('li').at(0).find('a').attributes('href')).toBe(
'https://elopage.com/s/gradido/sign_in?locale=en',
)
})
describe('with locale="de"', () => {
beforeEach(() => {
mocks.$i18n.locale = 'de'
})
it('links to the German elopage when locale is set to de', () => {
expect(wrapper.findAll('li').at(0).find('a').attributes('href')).toBe(
'https://elopage.com/s/gradido/sign_in?locale=de',
)
})
})
})
describe('logout', () => {
it('has a logout button', () => {
expect(wrapper.findAll('li').at(1).text()).toBe('logout')
})
it('emits logout when logout is clicked', async () => {
wrapper.findAll('li').at(1).find('a').trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.emitted('logout')).toEqual([[]])
})
})
})
})
})

View File

@ -10,7 +10,7 @@
<img :src="logo" class="navbar-brand-img" alt="..." /> <img :src="logo" class="navbar-brand-img" alt="..." />
</div> </div>
<b-row class="text-center"> <b-row class="text-center">
<b-col>{{ $n(balance) }} GDD</b-col> <b-col>{{ pending ? '—' : $n(balance) }} GDD</b-col>
</b-row> </b-row>
<slot name="mobile-right"> <slot name="mobile-right">
<ul class="nav align-items-center d-md-none"> <ul class="nav align-items-center d-md-none">
@ -93,6 +93,10 @@ export default {
type: Number, type: Number,
default: 0, default: 0,
}, },
pending: {
type: Boolean,
default: true,
},
}, },
provide() { provide() {
return { return {

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="wrapper"> <div class="wrapper">
<notifications></notifications> <notifications></notifications>
<side-bar @logout="logout" :balance="balance"> <side-bar @logout="logout" :balance="balance" :pending="pending">
<template slot="links"> <template slot="links">
<b-nav-item href="#!" to="/overview"> <b-nav-item href="#!" to="/overview">
<b-nav-text class="p-0 text-lg text-muted">{{ $t('send') }}</b-nav-text> <b-nav-text class="p-0 text-lg text-muted">{{ $t('send') }}</b-nav-text>
@ -10,15 +10,15 @@
<b-nav-text class="p-0 text-lg text-muted">{{ $t('transactions') }}</b-nav-text> <b-nav-text class="p-0 text-lg text-muted">{{ $t('transactions') }}</b-nav-text>
</b-nav-item> </b-nav-item>
<!-- <!--
<b-nav-item href="#!" to="/profile"> <b-nav-item href="#!" to="/profile">
<b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.my-profil') }}</b-nav-text> <b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.my-profil') }}</b-nav-text>
</b-nav-item> </b-nav-item>
<b-nav-item href="#!" to="/profileedit"> <b-nav-item href="#!" to="/profileedit">
<b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.settings') }}</b-nav-text> <b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.settings') }}</b-nav-text>
</b-nav-item> </b-nav-item>
<b-nav-item href="#!" to="/activity"> <b-nav-item href="#!" to="/activity">
<b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.activity') }}</b-nav-text> <b-nav-text class="p-0 text-lg text-muted">{{ $t('site.navbar.activity') }}</b-nav-text>
</b-nav-item> </b-nav-item>
--> -->
</template> </template>
</side-bar> </side-bar>
@ -33,6 +33,7 @@
:gdt-balance="GdtBalance" :gdt-balance="GdtBalance"
:transactions="transactions" :transactions="transactions"
:transactionCount="transactionCount" :transactionCount="transactionCount"
:pending="pending"
@update-balance="updateBalance" @update-balance="updateBalance"
@update-transactions="updateTransactions" @update-transactions="updateTransactions"
></router-view> ></router-view>
@ -83,6 +84,7 @@ export default {
transactions: [], transactions: [],
bookedBalance: 0, bookedBalance: 0,
transactionCount: 0, transactionCount: 0,
pending: true,
} }
}, },
methods: { methods: {
@ -99,6 +101,7 @@ export default {
this.$router.push('/login') this.$router.push('/login')
}, },
async updateTransactions() { async updateTransactions() {
this.pending = true
const result = await communityAPI.transactions(this.$store.state.sessionId) const result = await communityAPI.transactions(this.$store.state.sessionId)
if (result.success) { if (result.success) {
this.GdtBalance = Number(result.result.data.gdtSum) this.GdtBalance = Number(result.result.data.gdtSum)
@ -106,7 +109,9 @@ export default {
this.balance = Number(result.result.data.decay) this.balance = Number(result.result.data.decay)
this.bookedBalance = Number(result.result.data.balance) this.bookedBalance = Number(result.result.data.balance)
this.transactionCount = result.result.data.count this.transactionCount = result.result.data.count
this.pending = false
} else { } else {
this.pending = true
// what to do when loading balance fails? // what to do when loading balance fails?
} }
}, },

View File

@ -2,7 +2,12 @@
<div> <div>
<base-header class="pb-4 pt-2 bg-transparent"></base-header> <base-header class="pb-4 pt-2 bg-transparent"></base-header>
<b-container fluid class="p-2 mt-5"> <b-container fluid class="p-2 mt-5">
<gdd-status v-if="showContext" :balance="balance" :gdt-balance="GdtBalance" /> <gdd-status
v-if="showContext"
:pending="pending"
:balance="balance"
:gdt-balance="GdtBalance"
/>
<br /> <br />
<gdd-send :currentTransactionStep="currentTransactionStep"> <gdd-send :currentTransactionStep="currentTransactionStep">
<template #transaction-form> <template #transaction-form>
@ -78,6 +83,10 @@ export default {
default: () => [], default: () => [],
}, },
transactionCount: { type: Number, default: 0 }, transactionCount: { type: Number, default: 0 },
pending: {
type: Boolean,
default: true,
},
}, },
computed: { computed: {
showContext() { showContext() {

View File

@ -24,12 +24,30 @@ describe('GddStatus', () => {
wrapper = Wrapper() wrapper = Wrapper()
}) })
it('it displays the ammount of GDD', () => { describe('balance is loading', () => {
expect(wrapper.findAll('div.card-body').at(0).text()).toEqual('1234 GDD') it('it displays em-dash as the ammount of GDD', () => {
expect(wrapper.findAll('div.card-body').at(0).text()).toEqual('— GDD')
})
it('it displays em-dash as the ammount of GDT', () => {
expect(wrapper.findAll('div.card-body').at(1).text()).toEqual('— GDT')
})
}) })
it('it displays the ammount of GDT', () => { describe('balance is loaded', () => {
expect(wrapper.findAll('div.card-body').at(1).text()).toEqual('9876 GDT') beforeEach(() => {
wrapper.setProps({
pending: false,
})
})
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')
})
}) })
}) })
}) })

View File

@ -8,7 +8,7 @@
class="mb-4 h1" class="mb-4 h1"
style="background-color: #ebebeba3 !important" style="background-color: #ebebeba3 !important"
> >
{{ $n(balance) }} GDD {{ pending ? '—' : $n(balance) }} GDD
</stats-card> </stats-card>
</b-col> </b-col>
<b-col> <b-col>
@ -18,7 +18,7 @@
class="mb-4 h1" class="mb-4 h1"
style="background-color: #ebebeba3 !important" style="background-color: #ebebeba3 !important"
> >
{{ $n(GdtBalance) }} GDT {{ pending ? '—' : $n(GdtBalance) }} GDT
</stats-card> </stats-card>
</b-col> </b-col>
</b-row> </b-row>
@ -31,6 +31,10 @@ export default {
props: { props: {
balance: { type: Number, default: 0 }, balance: { type: Number, default: 0 },
GdtBalance: { type: Number, default: 0 }, GdtBalance: { type: Number, default: 0 },
pending: {
type: Boolean,
default: true,
},
}, },
} }
</script> </script>