This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
/
ProfileAll.spec.js
175 lines (158 loc) · 5.6 KB
/
ProfileAll.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { createLocalVue, mount } from '@vue/test-utils'
import VueRouter from 'vue-router'
import { useI18n } from '../../__utils__/i18n'
import router from '@/router'
import CurrencyMixin from '@/mixins/currency'
import ProfileAll from '@/pages/Profile/ProfileAll'
import BigNumber from '@/plugins/bignumber.js'
const localVue = createLocalVue()
const i18n = useI18n(localVue)
localVue.use(VueRouter)
describe('pages > ProfileAll', () => {
let wrapper
let networks
let profiles
let wallets
let ledgerWallets
const mountPage = () => {
const networkBy = (attr, value) => networks.find(network => network[attr] === value)
return mount(ProfileAll, {
localVue,
router,
i18n,
mixins: [CurrencyMixin],
stubs: {
ProfileAvatar: true
},
mocks: {
$store: {
getters: {
'ledger/wallets': ledgerWallets,
'network/byId': id => networkBy('id', id),
'network/byToken': token => networkBy('token', token),
'network/bySymbol': symbol => networkBy('symbol', symbol),
'profile/all': profiles,
'profile/balanceWithLedger': _id => 13700000,
'wallet/byProfileId': id => wallets[id]
}
},
formatter_networkCurrency: jest.fn(),
session_network: {
id: 'main'
}
}
})
}
beforeEach(() => {
networks = [
{ id: 'main', symbol: 'm', token: 'MAI', subunit: 'mainito', fractionDigits: 8 },
{ id: 'other', symbol: 'o', token: 'OTH', subunit: 'another', fractionDigits: 8 },
{ id: 'dev', symbol: 'd', token: 'DEV', subunit: 'devin', fractionDigits: 8 }
]
profiles = [
{ id: 'p1', networkId: 'main' },
{ id: 'p2', networkId: 'other' },
{ id: 'p3', networkId: 'main' },
{ id: 'p4', networkId: 'dev' }
]
wallets = {
p1: [
{ address: 'M0', balance: 1000 },
{ address: 'M1', balance: 15089900 }
],
p2: [
{ address: 'O0', balance: 12000000 },
{ address: 'O1', balance: 190000 }
],
p3: [
{ address: 'M2', balance: 0 },
{ address: 'M3', balance: 50000000000 }
],
p4: [
{ address: 'D0', balance: 1110000 },
{ address: 'D1', balance: 50900000 }
]
}
ledgerWallets = []
})
it('should render component', () => {
wrapper = mountPage()
expect(wrapper.contains('.ProfileAll')).toBeTruthy()
})
describe('aggregatedBalances', () => {
it('should aggregate the sum of the balances of all profiles by network', () => {
wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(50015090900))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
})
describe('when there are profiles with the same wallets', () => {
beforeEach(() => {
wallets.p3[1] = wallets.p1[0]
})
it('should include those wallets only 1 time', () => {
wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(15090900))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
})
})
describe('when the Ledger has wallets on the current network', () => {
beforeEach(() => {
ledgerWallets = [
{ address: 'MxLedger0', balance: 9883102007 },
{ address: 'MxLedger1', balance: 6723900701 }
]
})
it('should include their balances', () => {
wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(66622093608))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
})
describe('when they are included as non-Ledger wallets', () => {
beforeEach(() => {
ledgerWallets[1] = wallets.p1[1]
})
it('should include those wallets only 1 time', () => {
wrapper = mountPage()
expect(wrapper.vm.aggregatedBalances).toHaveProperty('main', new BigNumber(59898192907))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('other', new BigNumber(12190000))
expect(wrapper.vm.aggregatedBalances).toHaveProperty('dev', new BigNumber(52010000))
})
})
})
})
describe('totalBalances', () => {
it('should return the sum of balances per network, using their symbols, sorted by quantity descently', () => {
wrapper = mountPage()
expect(wrapper.vm.totalBalances).toEqual([
'm 500.150909',
'd 0.5201',
'o 0.1219'
])
})
describe('when the Ledger has wallets on the current network', () => {
beforeEach(() => {
ledgerWallets = [
{ address: 'MxLedger0', balance: 9883102007 },
{ address: 'MxLedger1', balance: 6723900701 }
]
})
it('should include their balances, sorted by quantity descently', () => {
wrapper = mountPage()
expect(wrapper.vm.totalBalances).toEqual([
'm 666.22093608',
'd 0.5201',
'o 0.1219'
])
})
})
})
describe('profileBalance', () => {
it('should return the formatted balance of a profile, using the network symbol', () => {
wrapper = mountPage()
expect(wrapper.vm.profileBalance(profiles[0])).toEqual('m 0.137')
})
})
})