From ee97098839d2189e885ae147c9eab13fe1b83cfc Mon Sep 17 00:00:00 2001 From: Edgar Goetzendorff Date: Mon, 9 Mar 2020 14:21:44 +0100 Subject: [PATCH] refactor: adjust business transaction form validation (#1736) * refactor: adjust business transaction form validation * refactor: only show available fields in business confirmation modal * test: adjust unit tests * test: adjust unit tests * fix: require vat and repository on update and if already set on business * fix: delete property if equal on update or if empty * fix: typo * fix: hasSameVat and hasSameRepository check * fix: optional bridgechain asset repository handling * feat: show bridgechain asset repository in bridgechain details * test: adjust unit tests * test: adjust unit tests Co-authored-by: Breno Polanski Co-authored-by: Brian Faust --- .../TransactionFormBridgechain/mixin.spec.js | 18 ++--- .../TransactionFormBusinessUpdate.spec.js | 2 +- .../TransactionFormBusiness/mixin.spec.js | 74 ++++++++++++------- .../TransactionConfirmBusinessUpdate.vue | 2 + .../TransactionFormBridgechain/mixin.vue | 12 ++- .../TransactionFormBusiness/mixin.vue | 72 +++++++++++++++++- .../WalletBusinessShowBridgechain.vue | 29 ++++++++ 7 files changed, 166 insertions(+), 43 deletions(-) diff --git a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.spec.js b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.spec.js index 6103956174..0623aedfd7 100644 --- a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.spec.js +++ b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.spec.js @@ -774,17 +774,17 @@ describe.each([ expect(wrapper.vm.bridgechainAssetRepositoryError).toBe(null) }) - it('should return null if not dirty', () => { - wrapper.vm.$v.form.asset.bridgechainAssetRepository.$model = '' - wrapper.vm.$v.form.asset.bridgechainAssetRepository.$reset() - - expect(wrapper.vm.$v.form.asset.bridgechainAssetRepository.$dirty).toBe(false) - expect(wrapper.vm.$v.form.asset.bridgechainAssetRepository.$invalid).toBe(false) - expect(wrapper.vm.bridgechainAssetRepositoryError).toBe(null) - }) - if (componentName === 'TransactionFormBridgechainRegistration') { describe('TransactionFormBridgechainRegistration', () => { + it('should return null if not dirty', () => { + wrapper.vm.$v.form.asset.bridgechainAssetRepository.$model = '' + wrapper.vm.$v.form.asset.bridgechainAssetRepository.$reset() + + expect(wrapper.vm.$v.form.asset.bridgechainAssetRepository.$dirty).toBe(false) + expect(wrapper.vm.$v.form.asset.bridgechainAssetRepository.$invalid).toBe(false) + expect(wrapper.vm.bridgechainAssetRepositoryError).toBe(null) + }) + it('should not return error if valid', () => { wrapper.vm.$v.form.asset.bridgechainAssetRepository.$model = 'https://github.com/arkecosystem/desktop-wallet.git' diff --git a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate.spec.js b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate.spec.js index 1970a2dc31..248dfccc95 100644 --- a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate.spec.js +++ b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate.spec.js @@ -153,7 +153,7 @@ describe('TransactionFormBusinessUpdate', () => { it('should be enabled if form is valid', async () => { wrapper.vm.$v.form.fee.$model = (0.1 * 1e8).toString() wrapper.vm.$v.form.passphrase.$model = 'passphrase' - wrapper.vm.$v.form.asset.name.$model = 'business' + wrapper.vm.$v.form.asset.name.$model = 'new business' wrapper.vm.$v.form.asset.website.$model = 'https://ark.io' wrapper.vm.$v.form.asset.vat.$model = 'GB12345678' wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git' diff --git a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.spec.js b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.spec.js index ddc107d649..2d2ecfb0ac 100644 --- a/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.spec.js +++ b/__tests__/unit/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.spec.js @@ -5,6 +5,7 @@ import installI18n from '../../../../__utils__/i18n' import TransactionFormBusinessRegistration from '@/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessRegistration' import TransactionFormBusinessUpdate from '@/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate' import CurrencyMixin from '@/mixins/currency' +import StringMixin from '@/mixins/strings' import BigNumber from '@/plugins/bignumber' const localVue = createLocalVue() @@ -42,6 +43,7 @@ const createWrapper = (component, wallet_fromRoute) => { i18n, localVue, sync: false, + mixins: [StringMixin], mocks: { $client: { buildBusinessRegistration: jest.fn((transactionData) => transactionData), @@ -195,7 +197,7 @@ describe.each([ it('should be enabled if form is valid', async () => { wrapper.vm.$v.form.fee.$model = (0.1 * 1e8).toString() wrapper.vm.$v.form.passphrase.$model = 'passphrase' - wrapper.vm.$v.form.asset.name.$model = 'business' + wrapper.vm.$v.form.asset.name.$model = 'new business' wrapper.vm.$v.form.asset.website.$model = 'https://ark.io' wrapper.vm.$v.form.asset.vat.$model = 'GB12345678' wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git' @@ -348,20 +350,24 @@ describe.each([ }) it('should return null if not dirty', () => { - wrapper.vm.$v.form.asset.vat.$model = '' - wrapper.vm.$v.form.asset.vat.$reset() + if (componentName === 'TransactionFormBusinessRegistration') { + wrapper.vm.$v.form.asset.vat.$model = '' + wrapper.vm.$v.form.asset.vat.$reset() - expect(wrapper.vm.$v.form.asset.vat.$dirty).toBe(false) - expect(wrapper.vm.$v.form.asset.vat.$invalid).toBe(false) - expect(wrapper.vm.vatError).toBe(null) + expect(wrapper.vm.$v.form.asset.vat.$dirty).toBe(false) + expect(wrapper.vm.$v.form.asset.vat.$invalid).toBe(false) + expect(wrapper.vm.vatError).toBe(null) + } }) it('should return null if empty as not required', () => { - wrapper.vm.$v.form.asset.vat.$model = '' + if (componentName === 'TransactionFormBusinessRegistration') { + wrapper.vm.$v.form.asset.vat.$model = '' - expect(wrapper.vm.$v.form.asset.vat.$dirty).toBe(true) - expect(wrapper.vm.$v.form.asset.vat.$invalid).toBe(false) - expect(wrapper.vm.vatError).toBe(null) + expect(wrapper.vm.$v.form.asset.vat.$dirty).toBe(true) + expect(wrapper.vm.$v.form.asset.vat.$invalid).toBe(false) + expect(wrapper.vm.vatError).toBe(null) + } }) it('should not return error if shorter than max (15)', () => { @@ -437,12 +443,14 @@ describe.each([ }) it('should return null if not dirty', () => { - wrapper.vm.$v.form.asset.repository.$model = '' - wrapper.vm.$v.form.asset.repository.$reset() + if (componentName === 'TransactionFormBusinessRegistration') { + wrapper.vm.$v.form.asset.repository.$model = '' + wrapper.vm.$v.form.asset.repository.$reset() - expect(wrapper.vm.$v.form.asset.repository.$dirty).toBe(false) - expect(wrapper.vm.$v.form.asset.repository.$invalid).toBe(false) - expect(wrapper.vm.repositoryError).toBe(null) + expect(wrapper.vm.$v.form.asset.repository.$dirty).toBe(false) + expect(wrapper.vm.$v.form.asset.repository.$invalid).toBe(false) + expect(wrapper.vm.repositoryError).toBe(null) + } }) it('should not return error if longer than min (12)', () => { @@ -497,14 +505,20 @@ describe.each([ wrapper.vm.$v.form.asset.vat.$model = 'GB12345678' wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git' + let expectedAsset = { + name: 'business', + website: 'https://ark.io', + vat: 'GB12345678', + repository: 'https://github.com/arkecosystem/desktop-wallet.git' + } + + if (componentName === 'TransactionFormBusinessUpdate') { + expectedAsset = {} + } + expect(wrapper.vm.getTransactionData()).toEqual({ address: 'address-1', - asset: { - name: 'business', - website: 'https://ark.io', - vat: 'GB12345678', - repository: 'https://github.com/arkecosystem/desktop-wallet.git' - }, + asset: expectedAsset, passphrase: 'passphrase', fee: new BigNumber(0.1 * 1e8), wif: undefined, @@ -528,14 +542,20 @@ describe.each([ wrapper.vm.$v.form.asset.vat.$model = 'GB12345678' wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git' + let expectedAsset = { + name: 'business', + website: 'https://ark.io', + vat: 'GB12345678', + repository: 'https://github.com/arkecosystem/desktop-wallet.git' + } + + if (componentName === 'TransactionFormBusinessUpdate') { + expectedAsset = {} + } + expect(wrapper.vm.getTransactionData()).toEqual({ address: 'address-1', - asset: { - name: 'business', - website: 'https://ark.io', - vat: 'GB12345678', - repository: 'https://github.com/arkecosystem/desktop-wallet.git' - }, + asset: expectedAsset, passphrase: 'passphrase', secondPassphrase: 'second passphrase', fee: new BigNumber(0.1 * 1e8), diff --git a/src/renderer/components/Transaction/TransactionConfirm/TransactionConfirmBusiness/TransactionConfirmBusinessUpdate.vue b/src/renderer/components/Transaction/TransactionConfirm/TransactionConfirmBusiness/TransactionConfirmBusinessUpdate.vue index fc509792a7..7bd43dfdc5 100644 --- a/src/renderer/components/Transaction/TransactionConfirm/TransactionConfirmBusiness/TransactionConfirmBusinessUpdate.vue +++ b/src/renderer/components/Transaction/TransactionConfirm/TransactionConfirmBusiness/TransactionConfirmBusinessUpdate.vue @@ -17,6 +17,7 @@ @@ -24,6 +25,7 @@ diff --git a/src/renderer/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.vue b/src/renderer/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.vue index a4573449aa..f74d3da9aa 100644 --- a/src/renderer/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.vue +++ b/src/renderer/components/Transaction/TransactionForm/TransactionFormBridgechain/mixin.vue @@ -266,7 +266,10 @@ export default { }, hasSameAssetRepository () { - return this.form.asset.bridgechainAssetRepository === this.bridgechain.bridgechainAssetRepository + return ( + this.form.asset.bridgechainAssetRepository === this.bridgechain.bridgechainAssetRepository || + (!this.form.asset.bridgechainAssetRepository && (this.bridgechain.bridgechainAssetRepository === undefined)) + ) }, hasSameSeedNodes () { @@ -343,7 +346,9 @@ export default { bridgechainAssetRepositoryError () { if (this.$v.form.asset.bridgechainAssetRepository.$dirty && this.$v.form.asset.bridgechainAssetRepository.$invalid) { - if (!this.$v.form.asset.bridgechainAssetRepository.url) { + if (!this.$v.form.asset.bridgechainAssetRepository.required) { + return this.$t('VALIDATION.REQUIRED', [this.$t('TRANSACTION.BRIDGECHAIN.BRIDGECHAIN_ASSET_REPOSITORY')]) + } else if (!this.$v.form.asset.bridgechainAssetRepository.url) { return this.$t('VALIDATION.INVALID_URL') } } @@ -576,6 +581,9 @@ export default { }, bridgechainAssetRepository: { + required (value) { + return (this.bridgechain && this.bridgechain.bridgechainAssetRepository) ? required(value) : true + }, url (value) { return url(value) } diff --git a/src/renderer/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.vue b/src/renderer/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.vue index 1f60ab69e4..11a9ea852f 100644 --- a/src/renderer/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.vue +++ b/src/renderer/components/Transaction/TransactionForm/TransactionFormBusiness/mixin.vue @@ -100,7 +100,7 @@ />