Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Jul 22, 2021
1 parent bfb6de3 commit f450bf6
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/unit/src/components/Balance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Balance.vue', () => {
store: {
wallet: {
state: {
utxoInfo: [],
balance: {
available: '1',
locked: '10',
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Balance.vue', () => {
})

it('BalanceButtons event send should show the modal', async () => {
const wrapper = mount(
const wrapper = shallowMount(
Balance,
createComponentMocks({
store: {
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/src/components/CreateDataRequestForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import CreateDataRequestForm from '@/components/CreateDataRequestForm'

describe('CreateDataRequestForm.vue', () => {
describe('should render properly the form items', () => {
const mockGetUtxoInfo = jest.fn()
const wrapper = mount(
CreateDataRequestForm,
createComponentMocks({
router: true,
store: {
wallet: {
state: {
utxoInfo: [],
errors: {
createDataRequest: false,
getUtxoInfo: null,
},
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -56,19 +62,25 @@ describe('CreateDataRequestForm.vue', () => {
})

describe('should change input value on update', () => {
const mockGetUtxoInfo = jest.fn()
const wrapper = mount(
CreateDataRequestForm,
createComponentMocks({
router: true,
store: {
wallet: {
state: {
utxoInfo: [],
errors: {
getUtxoInfo: null,
createDataRequest: false,
},
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -118,6 +130,7 @@ describe('CreateDataRequestForm.vue', () => {
})

describe('should not allow change wit unit when clicking on the unit append', () => {
const mockGetUtxoInfo = jest.fn()
it('collateral field', async () => {
const wrapper = mount(
CreateDataRequestForm,
Expand All @@ -132,6 +145,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand All @@ -156,6 +172,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -184,6 +203,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -212,6 +234,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -240,6 +265,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand All @@ -266,6 +294,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '100000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand All @@ -282,6 +313,7 @@ describe('CreateDataRequestForm.vue', () => {
})

describe('should show an error id there is a problem creating the data request', () => {
const mockGetUtxoInfo = jest.fn()
it('should show the error', async () => {
const wrapper = mount(
CreateDataRequestForm,
Expand All @@ -296,6 +328,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand All @@ -307,6 +342,7 @@ describe('CreateDataRequestForm.vue', () => {
})

describe('should emit the event if the form has no errors', () => {
const mockGetUtxoInfo = jest.fn()
it('should emit create data request event', async () => {
const wrapper = mount(
CreateDataRequestForm,
Expand All @@ -321,6 +357,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -348,6 +387,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -377,6 +419,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down Expand Up @@ -409,6 +454,9 @@ describe('CreateDataRequestForm.vue', () => {
balance: { total: '400000000000' },
unit: 'nanoWit',
},
actions: {
getUtxoInfo: mockGetUtxoInfo,
},
},
},
}),
Expand Down
77 changes: 77 additions & 0 deletions tests/unit/src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,83 @@ describe('areSoftEqualArrays', () => {
})
})

describe('order alphabetically and by amount', () => {
it('should order alphabetically and by amount', () => {
const list = {
'0c6758e7c1ecc802fd33100c57b4db11b5c9c30f39369510390f453fe2291509:0': {
amount: '10000000000',
pkh: 'a',
time_lock: '0',
},
'2168c06914c62ee3c8a60eb10981f8643718df57463baa576628b0e3e26f7e2b:0': {
amount: '10000000000',
pkh: 'c',
time_lock: '0',
},
'2ced242a524500f0aca80c2140774d1540150d2ab96b29807c41ebc6aee72168:0': {
amount: '9999999990',
pkh: 'b',
time_lock: '0',
},
'60fa24e6daa2a9cd536a9de362d0418ecce9bd29f211df99640440cde3def171:0': {
amount: '6',
pkh: 'f',
time_lock: '0',
},
'7d03629698ea52da762297d301217bf0f88a627586d14e1fce81bad21a543beb:0': {
amount: '5',
pkh: 'f',
time_lock: '0',
},
'd06113e2a779c09a78fdfb93c9c933d044faceff0c3849442da1931a8093922d:0': {
amount: '1',
pkh: 'e',
time_lock: '0',
},
'd06113e2a779c09a78fdfb93c9c933d044faceff0c3849442da1931a8093922d:1': {
amount: '0',
pkh: 'e',
time_lock: '0',
},
}
const expected = [
[
'0c6758e7c1ecc802fd33100c57b4db11b5c9c30f39369510390f453fe2291509:0',
{ amount: '10000000000', pkh: 'a', time_lock: '0' },
],
[
'2ced242a524500f0aca80c2140774d1540150d2ab96b29807c41ebc6aee72168:0',
{ amount: '9999999990', pkh: 'b', time_lock: '0' },
],
[
'2168c06914c62ee3c8a60eb10981f8643718df57463baa576628b0e3e26f7e2b:0',
{ amount: '10000000000', pkh: 'c', time_lock: '0' },
],
[
'd06113e2a779c09a78fdfb93c9c933d044faceff0c3849442da1931a8093922d:1',
{ amount: '0', pkh: 'e', time_lock: '0' },
],
[
'd06113e2a779c09a78fdfb93c9c933d044faceff0c3849442da1931a8093922d:0',
{ amount: '1', pkh: 'e', time_lock: '0' },
],
[
'7d03629698ea52da762297d301217bf0f88a627586d14e1fce81bad21a543beb:0',
{ amount: '5', pkh: 'f', time_lock: '0' },
],
[
'60fa24e6daa2a9cd536a9de362d0418ecce9bd29f211df99640440cde3def171:0',
{ amount: '6', pkh: 'f', time_lock: '0' },
],
]
const result = Object.entries(list).sort(
(a1, a2) =>
a1[1].pkh.localeCompare(a2[1].pkh) || a1[1].amount - a2[1].amount,
)
expect(result).toStrictEqual(expected)
})
})

describe('standardizeTransactionResult', () => {
it('should end with "ago" copy', () => {
const result =
Expand Down

0 comments on commit f450bf6

Please sign in to comment.