Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

refactor: adjust bridgechain transaction form validation #1730

Merged
merged 13 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('TransactionConfirmBridgechainRegistration', () => {
expect(wrapper.vm.apiPort).toBe(4003)
})

it('should return placeholder if no core-api port', () => {
it('should return null if no core-api port', () => {
createWrapper(null, {
asset: {
bridgechainRegistration: {
Expand All @@ -115,7 +115,7 @@ describe('TransactionConfirmBridgechainRegistration', () => {
}
})

expect(wrapper.vm.apiPort).toBe('-')
expect(wrapper.vm.apiPort).toBe(null)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('TransactionConfirmBridgechainUpdate', () => {
expect(wrapper.vm.apiPort).toBe(4003)
})

it('should return placeholder if no core-api port', () => {
it('should return null if no core-api port', () => {
createWrapper(null, {
asset: {
bridgechainUpdate: {
Expand All @@ -100,7 +100,7 @@ describe('TransactionConfirmBridgechainUpdate', () => {
}
})

expect(wrapper.vm.apiPort).toBe('-')
expect(wrapper.vm.apiPort).toBe(null)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,45 +588,26 @@ describe.each([
})
})

describe('seedNodeError', () => {
it('should return null if valid', () => {
wrapper.vm.$v.seedNode.$model = '5.5.5.5'

expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(false)
expect(wrapper.vm.seedNodeError).toBe(null)
})

it('should return null if not dirty', () => {
wrapper.vm.$v.seedNode.$model = ''
wrapper.vm.$v.seedNode.$reset()

expect(wrapper.vm.$v.seedNode.$dirty).toBe(false)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(false)
expect(wrapper.vm.seedNodeError).toBe(null)
})

it('should return error if invalid', () => {
wrapper.vm.$v.seedNode.$model = 'invalid seed node'
describe('hasSeedNodesError', () => {
it('should be true if there is an invalid seed node', () => {
wrapper.vm.invalidSeeds = [
{ ip: '0.5.5.5', isInvalid: true }
]

expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(true)
expect(wrapper.vm.seedNodeError).toBe('VALIDATION.INVALID_SEED')
expect(wrapper.vm.hasSeedNodesError).toBe(true)
})

it('should return error if duplicate', () => {
it('should be false if there are less than maximum seed nodes', () => {
wrapper.vm.$v.form.seedNodes.$model = [
{ ip: '5.5.5.5', isInvalid: false }
{ ip: '0.5.5.5', isInvalid: false }
]
wrapper.vm.$v.seedNode.$model = '5.5.5.5'

expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(true)
expect(wrapper.vm.seedNodeError).toBe('TRANSACTION.BRIDGECHAIN.ERROR_DUPLICATE')
expect(wrapper.vm.hasSeedNodesError).toBe(false)
})

it('should return error if too many', () => {
it('should be true if there are more than maximum seed nodes', () => {
wrapper.vm.$v.form.seedNodes.$model = [
{ ip: '0.5.5.5', isInvalid: false },
{ ip: '1.5.5.5', isInvalid: false },
{ ip: '2.5.5.5', isInvalid: false },
{ ip: '3.5.5.5', isInvalid: false },
Expand All @@ -638,59 +619,46 @@ describe.each([
{ ip: '9.5.5.5', isInvalid: false },
{ ip: '10.5.5.5', isInvalid: false }
]
wrapper.vm.$v.seedNode.$model = '6.6.6.6'

expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(true)
expect(wrapper.vm.seedNodeError).toBe('VALIDATION.TOO_MANY')
expect(wrapper.vm.hasSeedNodesError).toBe(true)
})
})

describe('seedNodesError', () => {
describe('seedNodeError', () => {
it('should return null if valid', () => {
wrapper.vm.$v.form.seedNodes.$model = [
{ ip: '5.5.5.5', isInvalid: false }
]
wrapper.vm.$v.seedNode.$model = '5.5.5.5'

expect(wrapper.vm.$v.form.seedNodes.$dirty).toBe(true)
expect(wrapper.vm.$v.form.seedNodes.$invalid).toBe(false)
expect(wrapper.vm.seedNodesError).toBe(null)
expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(false)
expect(wrapper.vm.seedNodeError).toBe(null)
})

it('should return null if not dirty', () => {
wrapper.vm.$v.form.seedNodes.$model = []
wrapper.vm.$v.form.seedNodes.$reset()
wrapper.vm.$v.seedNode.$model = ''
wrapper.vm.$v.seedNode.$reset()

expect(wrapper.vm.$v.form.seedNodes.$dirty).toBe(false)
expect(wrapper.vm.$v.form.seedNodes.$invalid).toBe(true)
expect(wrapper.vm.seedNodesError).toBe(null)
expect(wrapper.vm.$v.seedNode.$dirty).toBe(false)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(false)
expect(wrapper.vm.seedNodeError).toBe(null)
})

it('should return error if empty', () => {
wrapper.vm.$v.form.seedNodes.$model = []
it('should return error if invalid', () => {
wrapper.vm.$v.seedNode.$model = 'invalid seed node'

expect(wrapper.vm.$v.form.seedNodes.$dirty).toBe(true)
expect(wrapper.vm.$v.form.seedNodes.$invalid).toBe(true)
expect(wrapper.vm.seedNodesError).toBe('VALIDATION.REQUIRED')
expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(true)
expect(wrapper.vm.seedNodeError).toBe('VALIDATION.INVALID_SEED')
})

it('should return error if too many', () => {
it('should return error if duplicate', () => {
wrapper.vm.$v.form.seedNodes.$model = [
{ ip: '1.5.5.5', isInvalid: false },
{ ip: '2.5.5.5', isInvalid: false },
{ ip: '3.5.5.5', isInvalid: false },
{ ip: '4.5.5.5', isInvalid: false },
{ ip: '5.5.5.5', isInvalid: false },
{ ip: '6.5.5.5', isInvalid: false },
{ ip: '7.5.5.5', isInvalid: false },
{ ip: '8.5.5.5', isInvalid: false },
{ ip: '9.5.5.5', isInvalid: false },
{ ip: '10.5.5.5', isInvalid: false }
{ ip: '5.5.5.5', isInvalid: false }
]
wrapper.vm.$v.seedNode.$model = '5.5.5.5'

expect(wrapper.vm.$v.form.seedNodes.$dirty).toBe(true)
expect(wrapper.vm.$v.form.seedNodes.$invalid).toBe(true)
expect(wrapper.vm.seedNodesError).toBe('VALIDATION.TOO_MANY')
expect(wrapper.vm.$v.seedNode.$dirty).toBe(true)
expect(wrapper.vm.$v.seedNode.$invalid).toBe(true)
expect(wrapper.vm.seedNodeError).toBe('TRANSACTION.BRIDGECHAIN.ERROR_DUPLICATE')
})
})

Expand Down Expand Up @@ -743,7 +711,12 @@ describe.each([
wrapper.vm.$v.form.asset.bridgechainRepository.$reset()

expect(wrapper.vm.$v.form.asset.bridgechainRepository.$dirty).toBe(false)
expect(wrapper.vm.$v.form.asset.bridgechainRepository.$invalid).toBe(true)
if (componentName === 'TransactionFormBridgechainRegistration') {
expect(wrapper.vm.$v.form.asset.bridgechainRepository.$invalid).toBe(true)
} else {
expect(wrapper.vm.$v.form.asset.bridgechainRepository.$invalid).toBe(false)
}

expect(wrapper.vm.bridgechainRepositoryError).toBe(null)
})

Expand Down Expand Up @@ -892,7 +865,7 @@ describe.each([
wrapper.vm.$v.form.asset.bridgechainRepository.$model = 'https://github.com/arkecosystem/core.git'
wrapper.vm.$v.form.asset.bridgechainAssetRepository.$model = 'https://github.com/arkecosystem/core-assets.git'

const expectedAsset = {
let expectedAsset = {
name: 'bridgechain',
seedNodes: [
'1.1.1.1',
Expand All @@ -907,8 +880,9 @@ describe.each([
}

if (componentName === 'TransactionFormBridgechainUpdate') {
wrapper.vm.form.asset.bridgechainId = '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
expectedAsset.bridgechainId = '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
expectedAsset = {
bridgechainId: '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
}
}

expect(wrapper.vm.getTransactionData()).toEqual({
Expand Down Expand Up @@ -944,7 +918,7 @@ describe.each([
wrapper.vm.$v.form.asset.bridgechainRepository.$model = 'https://github.com/arkecosystem/core.git'
wrapper.vm.$v.form.asset.bridgechainAssetRepository.$model = 'https://github.com/arkecosystem/core-assets.git'

const expectedAsset = {
let expectedAsset = {
name: 'bridgechain',
seedNodes: [
'1.1.1.1',
Expand All @@ -959,8 +933,9 @@ describe.each([
}

if (componentName === 'TransactionFormBridgechainUpdate') {
wrapper.vm.form.asset.bridgechainId = '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
expectedAsset.bridgechainId = '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
expectedAsset = {
bridgechainId: '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'
}
}

expect(wrapper.vm.getTransactionData()).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Input/InputEditableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<div
v-if="requiredAndEmpty"
class="InputEditableList__no-items text-center"
class="InputEditableList__no-items"
>
{{ noItemsMessage }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
>
{{ transaction.asset.bridgechainRegistration.bridgechainRepository }}
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.bridgechainRegistration.bridgechainAssetRepository"
class="TransactionConfirmBridgechainRegistration__bridgechain-asset-repo"
:label="$t('WALLET_BUSINESS.BRIDGECHAIN.BRIDGECHAIN_ASSET_REPOSITORY')"
>
{{ transaction.asset.bridgechainRegistration.bridgechainAssetRepository }}
</ListDividedItem>
</ListDivided>
</template>

Expand Down Expand Up @@ -91,8 +99,14 @@ export default {
},

apiPort () {
if (!this.transaction.asset.bridgechainRegistration.ports['@arkecosystem/core-api']) {
return '-'
if (
!this.transaction.asset.bridgechainRegistration.ports ||
(
this.transaction.asset.bridgechainRegistration.ports &&
!this.transaction.asset.bridgechainRegistration.ports['@arkecosystem/core-api']
)
) {
return null
}

return this.transaction.asset.bridgechainRegistration.ports['@arkecosystem/core-api']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.bridgechainUpdate.bridgechainRepository"
class="TransactionConfirmBridgechainUpdate__bridgechain-repo"
:label="$t('WALLET_BUSINESS.BRIDGECHAIN.BRIDGECHAIN_REPOSITORY')"
>
{{ transaction.asset.bridgechainUpdate.bridgechainRepository }}
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.bridgechainUpdate.bridgechainAssetRepository"
class="TransactionConfirmBridgechainUpdate__bridgechain-asset-repo"
:label="$t('WALLET_BUSINESS.BRIDGECHAIN.BRIDGECHAIN_ASSET_REPOSITORY')"
>
{{ transaction.asset.bridgechainUpdate.bridgechainAssetRepository }}
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.bridgechainUpdate.seedNodes"
class="TransactionConfirmBridgechainUpdate__seed-nodes"
:label="$t('WALLET_BUSINESS.BRIDGECHAIN.SEED_NODES')"
>
Expand All @@ -29,6 +46,7 @@
</ListDividedItem>

<ListDividedItem
v-if="apiPort"
class="TransactionConfirmBridgechainUpdate__api-port"
:label="$t('WALLET_BUSINESS.BRIDGECHAIN.API_PORT')"
>
Expand Down Expand Up @@ -61,8 +79,14 @@ export default {
},

apiPort () {
if (!this.transaction.asset.bridgechainUpdate.ports['@arkecosystem/core-api']) {
return '-'
if (
!this.transaction.asset.bridgechainUpdate.ports ||
(
this.transaction.asset.bridgechainUpdate.ports &&
!this.transaction.asset.bridgechainUpdate.ports['@arkecosystem/core-api']
)
) {
return null
}

return this.transaction.asset.bridgechainUpdate.ports['@arkecosystem/core-api']
Expand Down
Loading