From 4fe785fa282c5d8a3f040eb419ad7649ad25505c Mon Sep 17 00:00:00 2001 From: storywithoutend Date: Thu, 9 Nov 2023 14:56:14 +0800 Subject: [PATCH 1/5] advanced editor fix: abi, rebuilding state, delete addresses --- e2e/specs/stateless/advancedEditor.spec.ts | 79 +++++++++++++++++++ playwright/pageObjects/advancedEditorModal.ts | 37 +++++++++ playwright/pageObjects/index.ts | 4 + playwright/pageObjects/recordsPage.ts | 26 ++++++ playwright/pageObjects/transactionModal.ts | 7 ++ .../AdvancedEditorTabContent.tsx | 1 + src/components/RecordItem.tsx | 2 +- .../pages/profile/[name]/tabs/RecordsTab.tsx | 2 +- src/hooks/useAdvancedEditor.test.ts | 54 +++++++++++++ src/hooks/useAdvancedEditor.ts | 66 +++++++++++----- src/utils/records.ts | 18 +++++ 11 files changed, 276 insertions(+), 20 deletions(-) create mode 100644 e2e/specs/stateless/advancedEditor.spec.ts create mode 100644 playwright/pageObjects/advancedEditorModal.ts create mode 100644 playwright/pageObjects/recordsPage.ts create mode 100644 src/hooks/useAdvancedEditor.test.ts diff --git a/e2e/specs/stateless/advancedEditor.spec.ts b/e2e/specs/stateless/advancedEditor.spec.ts new file mode 100644 index 000000000..1f41c780c --- /dev/null +++ b/e2e/specs/stateless/advancedEditor.spec.ts @@ -0,0 +1,79 @@ +import { expect } from '@playwright/test' +import { test } from '@root/playwright' + +test('should be able to maintain state when returning from transaction modal to advanced editor', async ({ + login, + makeName, + makePageObject, +}) => { + const name = await makeName({ + label: 'profile', + type: 'legacy', + records: { + texts: [{ key: 'text', value: 'text' }], + coinTypes: [{ key: 'SOL', value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH' }], + contentHash: 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', + abi: { + contentType: 1, + data: '{"test":"test"}', + }, + }, + }) + + const recordsPage = makePageObject('RecordsPage') + const advancedEditor = makePageObject('AdvancedEditorModal') + const transactionModal = makePageObject('TransactionModal') + + await recordsPage.goto(name) + await login.connect() + + // Validate records + await expect(recordsPage.getRecordValue('text', 'text')).toHaveText('text') + await expect(recordsPage.getRecordValue('address', 'sol')).toHaveText( + 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', + ) + await expect(recordsPage.getRecordValue('contentHash')).toHaveText( + 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', + ) + await expect(recordsPage.getRecordValue('abi')).toHaveText('"{\\"test\\":\\"test\\"}"') + + await recordsPage.editRecordsButton.click() + + // Validate advanced editor + await expect(await advancedEditor.recordInput('text', 'text')).toHaveValue('text') + await expect(await advancedEditor.recordInput('address', 'SOL')).toHaveValue( + 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', + ) + await expect(await advancedEditor.recordInput('contentHash')).toHaveValue( + 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', + ) + await expect(await advancedEditor.recordInput('abi')).toHaveValue('"{\\"test\\":\\"test\\"}"') + + await advancedEditor.recordClearButton('text', 'text').then((button) => button.click()) + await advancedEditor.recordClearButton('address', 'SOL').then((button) => button.click()) + await advancedEditor.recordInput('contentHash').then((input) => input.fill('')) + await advancedEditor.recordInput('abi').then((input) => input.fill('')) + + await advancedEditor.saveButton.click() + + // Validate transaction display item + await expect(transactionModal.displayItem('update')).toHaveText('4 records') + + await transactionModal.backButton.click() + + // Validate inputs have been rebuilt correctly + await expect(await advancedEditor.recordComponent('text', 'text')).toHaveCount(0) + await expect(await advancedEditor.recordComponent('address', 'SOL')).toHaveCount(0) + await expect(await advancedEditor.recordInput('contentHash')).toHaveValue('') + await expect(await advancedEditor.recordInput('abi')).toHaveValue('') + + await advancedEditor.saveButton.click() + + await transactionModal.autoComplete() + + // Validate change in records + await expect(recordsPage.getRecordButton('text', 'text')).toHaveCount(0) + await expect(recordsPage.getRecordButton('address', 'sol')).toHaveCount(0) + await expect(recordsPage.getRecordButton('contentHash')).toHaveCount(0) + await expect(recordsPage.getRecordButton('abi')).toHaveCount(0) +}) diff --git a/playwright/pageObjects/advancedEditorModal.ts b/playwright/pageObjects/advancedEditorModal.ts new file mode 100644 index 000000000..6e150163d --- /dev/null +++ b/playwright/pageObjects/advancedEditorModal.ts @@ -0,0 +1,37 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { Locator, Page } from '@playwright/test' + +export class AdvancedEditorModal { + readonly page: Page + + readonly saveButton: Locator + + constructor(page: Page) { + this.page = page + this.saveButton = this.page.getByTestId('advanced-editor').getByRole('button', { name: 'Save' }) + } + + tab(tab: 'text' | 'address' | 'other') { + return this.page.getByTestId(`${tab}-tab`) + } + + async recordComponent(type: 'text' | 'address' | 'contentHash' | 'abi', key?: string) { + if (['text', 'address'].includes(type)) { + await this.tab(type as 'text' | 'other').click() + return this.page.getByTestId(`record-input-${key}`) + } + await this.tab('other').click() + const _key = type === 'contentHash' ? 'Content Hash' : 'ABI' + return this.page.getByTestId(`record-input-${_key}`) + } + + async recordInput(type: 'text' | 'address' | 'contentHash' | 'abi', key?: string) { + const component = await this.recordComponent(type, key) + return component.locator('input') + } + + async recordClearButton(type: 'text' | 'address', key: string) { + const component = await this.recordComponent(type, key) + return component.locator('button') + } +} diff --git a/playwright/pageObjects/index.ts b/playwright/pageObjects/index.ts index f163b8895..8692e8f23 100644 --- a/playwright/pageObjects/index.ts +++ b/playwright/pageObjects/index.ts @@ -3,6 +3,7 @@ import { Page } from '@playwright/test' import { Web3ProviderBackend } from 'headless-web3-provider' import { AddressPage } from './addressPage' +import { AdvancedEditorModal } from './advancedEditorModal' import { EditRolesModal } from './editRolesModal' import { ExtendNamesModal } from './extendNamesModal' import { HomePage } from './homePage' @@ -10,6 +11,7 @@ import { MorePage } from './morePage' import { OwnershipPage } from './ownershipPage' import { PermissionsPage } from './permissionsPage' import { ProfilePage } from './profilePage' +import { RecordsPage } from './recordsPage' import { RegistrationPage } from './registrationPage' import { SendNameModal } from './sendNameModal' import { SubnamesPage } from './subnamePage' @@ -30,6 +32,8 @@ const pageObjects = { SendNameModal, SubnamesPage, TransactionModal, + RecordsPage, + AdvancedEditorModal, } type PageObjects = typeof pageObjects diff --git a/playwright/pageObjects/recordsPage.ts b/playwright/pageObjects/recordsPage.ts new file mode 100644 index 000000000..513f7e2de --- /dev/null +++ b/playwright/pageObjects/recordsPage.ts @@ -0,0 +1,26 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { Locator, Page } from '@playwright/test' + +export class RecordsPage { + readonly page: Page + + readonly editRecordsButton: Locator + + constructor(page: Page) { + this.page = page + this.editRecordsButton = this.page.getByRole('button', { name: 'Edit records' }) + } + + async goto(name: string) { + await this.page.goto(`/${name}?tab=records`) + } + + getRecordButton(type: 'text' | 'address' | 'contentHash' | 'abi', key?: string) { + const testId = key ? `name-details-${type}-${key.toLowerCase()}` : `name-details-${type}` + return this.page.getByTestId(testId) + } + + getRecordValue(type: 'text' | 'address' | 'contentHash' | 'abi', key?: string) { + return this.getRecordButton(type, key).locator('> div').last() + } +} diff --git a/playwright/pageObjects/transactionModal.ts b/playwright/pageObjects/transactionModal.ts index b3bda4e31..862a3289b 100644 --- a/playwright/pageObjects/transactionModal.ts +++ b/playwright/pageObjects/transactionModal.ts @@ -17,6 +17,8 @@ export class TransactionModal { readonly transactionModal: Locator + readonly backButton: Locator + constructor(page: Page, wallet: Web3ProviderBackend) { this.page = page this.wallet = wallet @@ -25,6 +27,7 @@ export class TransactionModal { this.completeButton = this.page.getByTestId('transaction-modal-complete-button') this.closeButton = this.page.getByTestId('close-icon') this.transactionModal = this.page.getByTestId('transaction-modal-inner') + this.backButton = this.page.locator('body .modal').getByRole('button', { name: 'Back' }) } async authorize() { @@ -53,4 +56,8 @@ export class TransactionModal { } while (isModalVisible) /* eslint-enable no-await-in-loop */ } + + displayItem(key: string, option = 'normal') { + return this.page.getByTestId(`display-item-${key}-${option}`).locator('> div').last() + } } diff --git a/src/components/@molecules/AdvancedEditor/AdvancedEditorTabContent.tsx b/src/components/@molecules/AdvancedEditor/AdvancedEditorTabContent.tsx index 940e1c2d9..290d8db3c 100644 --- a/src/components/@molecules/AdvancedEditor/AdvancedEditorTabContent.tsx +++ b/src/components/@molecules/AdvancedEditor/AdvancedEditorTabContent.tsx @@ -25,6 +25,7 @@ const TabContentContainer = styled.div( display: flex; flex-direction: column; gap: ${theme.space['3']}; + padding-right: ${theme.space['1']}; overflow: hidden; flex: 1; `, diff --git a/src/components/RecordItem.tsx b/src/components/RecordItem.tsx index 880ef89fb..e0dd5d851 100644 --- a/src/components/RecordItem.tsx +++ b/src/components/RecordItem.tsx @@ -11,7 +11,7 @@ const RecordItem = ({ itemKey?: string value: string showLegacy?: boolean - type: 'text' | 'address' | 'contentHash' + type: 'text' | 'address' | 'contentHash' | 'abi' }) => { const breakpoint = useBreakpoint() const keyLabel = showLegacy && itemKey ? itemKey?.replace('_LEGACY', '') : itemKey diff --git a/src/components/pages/profile/[name]/tabs/RecordsTab.tsx b/src/components/pages/profile/[name]/tabs/RecordsTab.tsx index 2256c7031..b266009f3 100644 --- a/src/components/pages/profile/[name]/tabs/RecordsTab.tsx +++ b/src/components/pages/profile/[name]/tabs/RecordsTab.tsx @@ -261,7 +261,7 @@ export const RecordsTab = ({ )} - {abi && } + {abi && } {canEdit && resolverAddress !== emptyAddress && ( diff --git a/src/hooks/useAdvancedEditor.test.ts b/src/hooks/useAdvancedEditor.test.ts new file mode 100644 index 000000000..87b402b2d --- /dev/null +++ b/src/hooks/useAdvancedEditor.test.ts @@ -0,0 +1,54 @@ +import { normalizeAbi } from './useAdvancedEditor' + +describe('normalizeAbi', () => { + it('should normalize abi that is a string', () => { + expect(normalizeAbi("test")).toEqual({ contentType: 1, data: 'test' }) + }) + + it('should normalize abi that is an empty string', () => { + expect(normalizeAbi("")).toEqual({ contentType: 1, data: '' }) + }) + + it('should normalize abi with a string for data', () => { + expect(normalizeAbi({ data: 'test' })).toEqual({ contentType: 1, data: 'test' }) + }) + + it('should normalize abi with an empty string for data', () => { + expect(normalizeAbi({ data: '' })).toEqual({ contentType: 1, data: '' }) + }) + + it('should normalize abi with an object for data', () => { + expect(normalizeAbi({ data: {test: 'test'} })).toEqual({ contentType: 1, data: '{"test":"test"}' }) + }) + it('should normalize abi with an array for data', () => { + expect(normalizeAbi({ data: ['test'] })).toEqual({ contentType: 1, data: '["test"]' }) + }) + + it('should normalize abi with an object for data', () => { + expect(normalizeAbi({ data: {test: 'test'} })).toEqual({ contentType: 1, data: '{"test":"test"}' }) + }) + + it('should NOT normalize abi that is a number', () => { + expect(normalizeAbi(5 as any)).toBeUndefined() + }) + + it('should NOT normalize abi that is null', () => { + expect(normalizeAbi(null as any)).toBeUndefined() + }) + + it('should NOT normalize abi that is undefined', () => { + expect(normalizeAbi(undefined as any)).toBeUndefined() + }) + + it('should NOT normalize abi with null for data', () => { + expect(normalizeAbi({ data: null as any})).toBeUndefined() + }) + + it('should NOT normalize abi with undefined for data', () => { + expect(normalizeAbi({ data: undefined as any})).toBeUndefined() + }) + + it('should NOT normalize abi with a number for data', () => { + expect(normalizeAbi({ data: 5 as any})).toBeUndefined() + }) +}) \ No newline at end of file diff --git a/src/hooks/useAdvancedEditor.ts b/src/hooks/useAdvancedEditor.ts index 69cc06f15..1771fc2b9 100644 --- a/src/hooks/useAdvancedEditor.ts +++ b/src/hooks/useAdvancedEditor.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { useTranslation } from 'react-i18next' -import { Pattern, match } from 'ts-pattern' +import { P, Pattern, match } from 'ts-pattern' import { RecordOptions } from '@ensdomains/ensjs/utils/recordHelpers' @@ -11,7 +11,6 @@ import useExpandableRecordsGroup from '@app/hooks/useExpandableRecordsGroup' import { DetailedProfile } from '@app/hooks/useNameDetails' import { useProfile } from '@app/hooks/useProfile' import { useResolverHasInterfaces } from '@app/hooks/useResolverHasInterfaces' -import { emptyAddress } from '@app/utils/constants' import { convertFormSafeKey, convertProfileToProfileFormObject, @@ -35,6 +34,15 @@ const getFieldsByType = (type: 'text' | 'addr' | 'contentHash', data: AdvancedEd return Object.fromEntries(entries) } +type NormalizedAbi = { contentType: number | undefined; data: string } +export const normalizeAbi = (abi: RecordOptions['abi'] | string): NormalizedAbi | undefined => { + return match(abi) + .with(P.string, (data) => ({ contentType: 1, data })) + .with({ data: P.string }, ({ data }) => ({ contentType: 1, data })) + .with({ data: {} }, ({ data }) => ({ contentType: 1, data: JSON.stringify(data) })) + .otherwise(() => undefined) +} + export type AdvancedEditorType = { text: { [key: string]: string @@ -166,6 +174,7 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) => } })() + const [shouldRunOverwritesScript, setShouldRunOverwritesScript] = useState(false) useEffect(() => { if (profile) { const formObject = convertProfileToProfileFormObject(profile) @@ -189,33 +198,60 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) => address: Object.keys(newDefaultValues.address) || [], text: Object.keys(newDefaultValues.text) || [], } + setExistingRecords(newExistingRecords) + setShouldRunOverwritesScript(true) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [profile]) + useEffect(() => { + if (shouldRunOverwritesScript) { overwrites?.texts?.forEach((text) => { const { key, value } = text const formKey = formSafeKey(key) - setValue(`text.${formKey}`, value, { shouldDirty: true }) - if (!newExistingRecords.text.includes(formKey)) { - newExistingRecords.text.push(formKey) + const isExisting = existingRecords.text.includes(formKey) + if (value && isExisting) { + setValue(`text.${formKey}`, value, { shouldDirty: true }) + } else if (value && !isExisting) { + addTextKey(formKey) + setValue(`text.${formKey}`, value, { shouldDirty: true }) + } else if (!value && isExisting) { + removeTextKey(formKey, false) + } else if (!value && !isExisting) { + removeTextKey(formKey, true) } }) overwrites?.coinTypes?.forEach((coinType) => { const { key, value } = coinType const formKey = formSafeKey(key) - setValue(`address.${formKey}`, value, { shouldDirty: true }) - if (!newExistingRecords.address.includes(formKey)) { - newExistingRecords.address.push(formKey) + const isExisting = existingRecords.address.includes(formKey) + if (value && isExisting) { + setValue(`address.${formKey}`, value, { shouldDirty: true }) + } else if (value && !isExisting) { + addAddressKey(formKey) + setValue(`address.${formKey}`, value, { shouldDirty: true }) + } else if (!value && isExisting) { + removeAddressKey(formKey, false) + } else if (!value && !isExisting) { + removeAddressKey(formKey, true) } }) - if (overwrites?.contentHash) { + if (typeof overwrites?.contentHash === 'string') { setValue('other.contentHash', overwrites.contentHash, { shouldDirty: true }) } - setExistingRecords(newExistingRecords) + const abi = normalizeAbi(overwrites?.abi) + if (abi) { + setValue('other.abi', abi, { shouldDirty: true }) + } + + setShouldRunOverwritesScript(false) } + // eslint-disable-next-line react-hooks/exhaustive-deps - }, [profile]) + }, [existingRecords, shouldRunOverwritesScript]) const { hasInterface: hasABIInterface, isLoading: isLoadingABIInterface } = useResolverHasInterfaces(['IABIResolver'], profile?.resolverAddress, loading) @@ -236,11 +272,6 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) => value, })) as { key: string; value: string }[] - const coinTypesWithZeroAddressses = coinTypes.map((coinType) => { - if (coinType.value) return coinType - return { key: coinType.key, value: emptyAddress } - }) - const contentHash = dirtyFields.other?.contentHash const abi = match(dirtyFields.other?.abi?.data) @@ -250,7 +281,7 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) => const records = { texts, - coinTypes: coinTypesWithZeroAddressses, + coinTypes, contentHash, abi, } @@ -276,7 +307,6 @@ const useAdvancedEditor = ({ profile, loading, overwrites, callback }: Props) => handleTabClick, hasErrors, existingRecords, - setExistingRecords, existingTextKeys, newTextKeys, addTextKey, diff --git a/src/utils/records.ts b/src/utils/records.ts index 214c13def..9e1e944b8 100644 --- a/src/utils/records.ts +++ b/src/utils/records.ts @@ -1,3 +1,6 @@ +import { BigNumberish } from '@ethersproject/bignumber' +import { P, match as _match } from 'ts-pattern' + import { RecordOptions } from '@ensdomains/ensjs/utils/recordHelpers' import { ContentHash, Profile, RecordItem } from '@app/types' @@ -11,12 +14,27 @@ const contentHashTouple = (contentHash?: string, deleteLabel = 'delete'): [strin return [['contenthash', contentHash]] } +const abiTouple = ( + abi?: { contentType?: BigNumberish; data: string | object } | string, + deleteLabel = 'delete', +): [string, string][] => { + const abiStr = _match(abi) + .with(P.string, (_abi) => _abi) + .with({ data: P.string }, ({ data }) => data) + .with({ data: {} }, ({ data }) => JSON.stringify(data)) + .otherwise(() => undefined) + if (abiStr === '') return [[deleteLabel, 'abi']] + if (!abiStr) return [] + return [['abi', abiStr]] +} + export const recordOptionsToToupleList = ( records?: RecordOptions, deleteLabel = 'delete', ): [string, string][] => { return [ ...contentHashTouple(records?.contentHash, deleteLabel), + ...abiTouple(records?.abi, deleteLabel), ...(records?.texts?.map(({ key, value }) => [key, value]) || []), ...(records?.coinTypes?.map(({ key, value }) => [key, shortenAddress(value)]) || []), ].map(([key, value]) => (value ? [key, value] : [deleteLabel, key])) From be7d79776172d1da8eb392f6556804c423c38f90 Mon Sep 17 00:00:00 2001 From: storywithoutend Date: Thu, 9 Nov 2023 15:42:35 +0800 Subject: [PATCH 2/5] update unit test --- .../input/AdvancedEditor/AdvancedEditor.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction-flow/input/AdvancedEditor/AdvancedEditor.test.tsx b/src/transaction-flow/input/AdvancedEditor/AdvancedEditor.test.tsx index ebbf8df1c..54b782989 100644 --- a/src/transaction-flow/input/AdvancedEditor/AdvancedEditor.test.tsx +++ b/src/transaction-flow/input/AdvancedEditor/AdvancedEditor.test.tsx @@ -278,7 +278,7 @@ describe('AdvancedEditor', () => { }) expect(mockDispatch.mock.calls[0][0].payload[0].data.records.coinTypes[0]).toEqual({ key: 'ETH', - value: '0x0000000000000000000000000000000000000000', + value: '', }) expect(mockDispatch.mock.calls[0][0].payload[0].data.records.coinTypes.length).toBe(1) }) From 3d64f1a182f77d72f98455ddfa60c446c55335db Mon Sep 17 00:00:00 2001 From: storywithoutend Date: Thu, 9 Nov 2023 16:29:16 +0800 Subject: [PATCH 3/5] update profile editor spec for abi record item --- e2e/specs/stateless/profileEditor.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/specs/stateless/profileEditor.spec.ts b/e2e/specs/stateless/profileEditor.spec.ts index 9e4a8b136..0dd18977a 100644 --- a/e2e/specs/stateless/profileEditor.spec.ts +++ b/e2e/specs/stateless/profileEditor.spec.ts @@ -318,7 +318,7 @@ test.describe('wrapped', () => { await expect(profilePage.record('text', 'nickname')).toHaveText('Test Name') await page.getByTestId('records-tab').click() - await expect(page.getByTestId('name-details-text')).toHaveText('[{"test":"test"}]') + await expect(page.getByTestId('name-details-abi')).toHaveText('[{"test":"test"}]') }) }) }) From 9d17fd06b55c347a71f7068dc7c87cc2b5c5f863 Mon Sep 17 00:00:00 2001 From: sugh01 <19183308+sugh01@users.noreply.github.com> Date: Fri, 10 Nov 2023 06:59:32 +0100 Subject: [PATCH 4/5] (test) Add few more records to test --- e2e/specs/stateless/advancedEditor.spec.ts | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/e2e/specs/stateless/advancedEditor.spec.ts b/e2e/specs/stateless/advancedEditor.spec.ts index 1f41c780c..77b600687 100644 --- a/e2e/specs/stateless/advancedEditor.spec.ts +++ b/e2e/specs/stateless/advancedEditor.spec.ts @@ -10,8 +10,16 @@ test('should be able to maintain state when returning from transaction modal to label: 'profile', type: 'legacy', records: { - texts: [{ key: 'text', value: 'text' }], - coinTypes: [{ key: 'SOL', value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH' }], + texts: [ + { key: 'name', value: 'Bob' }, + { key: 'text', value: 'text' }, + { key: 'com.twitter', value: '@test' }, + ], + coinTypes: [ + { key: 'SOL', value: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH' }, + { key: 'ETH', value: '0xbec1C7C11F2Fa9AB24b9E49122D26e721766DAF6' }, + { key: 'BTC', value: '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE' }, + ], contentHash: 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', abi: { contentType: 1, @@ -28,10 +36,18 @@ test('should be able to maintain state when returning from transaction modal to await login.connect() // Validate records + await expect(recordsPage.getRecordValue('text', 'name')).toHaveText('Bob') await expect(recordsPage.getRecordValue('text', 'text')).toHaveText('text') + await expect(recordsPage.getRecordValue('text', 'com.twitter')).toHaveText('@test') await expect(recordsPage.getRecordValue('address', 'sol')).toHaveText( 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', ) + await expect(recordsPage.getRecordValue('address', 'eth')).toHaveText( + '0xbec1C7C11F2Fa9AB24b9E49122D26e721766DAF6', + ) + await expect(recordsPage.getRecordValue('address', 'btc')).toHaveText( + '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE', + ) await expect(recordsPage.getRecordValue('contentHash')).toHaveText( 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', ) @@ -41,9 +57,17 @@ test('should be able to maintain state when returning from transaction modal to // Validate advanced editor await expect(await advancedEditor.recordInput('text', 'text')).toHaveValue('text') + await expect(await advancedEditor.recordInput('text', 'name')).toHaveValue('Bob') + await expect(await advancedEditor.recordInput('text', 'com.twitter')).toHaveValue('@test') await expect(await advancedEditor.recordInput('address', 'SOL')).toHaveValue( 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH', ) + await expect(await advancedEditor.recordInput('address', 'ETH')).toHaveValue( + '0xbec1C7C11F2Fa9AB24b9E49122D26e721766DAF6', + ) + await expect(await advancedEditor.recordInput('address', 'BTC')).toHaveValue( + '1PzAJcFtEiXo9UGtRU6iqXQKj8NXtcC7DE', + ) await expect(await advancedEditor.recordInput('contentHash')).toHaveValue( 'ipfs://bafybeico3uuyj3vphxpvbowchdwjlrlrh62awxscrnii7w7flu5z6fk77y', ) @@ -51,29 +75,35 @@ test('should be able to maintain state when returning from transaction modal to await advancedEditor.recordClearButton('text', 'text').then((button) => button.click()) await advancedEditor.recordClearButton('address', 'SOL').then((button) => button.click()) + await advancedEditor.recordClearButton('address', 'ETH').then((button) => button.click()) await advancedEditor.recordInput('contentHash').then((input) => input.fill('')) await advancedEditor.recordInput('abi').then((input) => input.fill('')) await advancedEditor.saveButton.click() // Validate transaction display item - await expect(transactionModal.displayItem('update')).toHaveText('4 records') + await expect(transactionModal.displayItem('update')).toHaveText('5 records') await transactionModal.backButton.click() // Validate inputs have been rebuilt correctly await expect(await advancedEditor.recordComponent('text', 'text')).toHaveCount(0) await expect(await advancedEditor.recordComponent('address', 'SOL')).toHaveCount(0) + await expect(await advancedEditor.recordComponent('address', 'ETH')).toHaveCount(0) await expect(await advancedEditor.recordInput('contentHash')).toHaveValue('') await expect(await advancedEditor.recordInput('abi')).toHaveValue('') await advancedEditor.saveButton.click() + // Validate transaction display item + await expect(transactionModal.displayItem('update')).toHaveText('5 records') + await transactionModal.autoComplete() // Validate change in records await expect(recordsPage.getRecordButton('text', 'text')).toHaveCount(0) await expect(recordsPage.getRecordButton('address', 'sol')).toHaveCount(0) + await expect(recordsPage.getRecordButton('address', 'eth')).toHaveCount(0) await expect(recordsPage.getRecordButton('contentHash')).toHaveCount(0) await expect(recordsPage.getRecordButton('abi')).toHaveCount(0) }) From c336a7519f95b05d6b88617fed5e0401858fb254 Mon Sep 17 00:00:00 2001 From: storywithoutend Date: Mon, 13 Nov 2023 09:48:06 +0800 Subject: [PATCH 5/5] fix bug in useExpandableRecordsGroup --- src/hooks/useExpandableRecordsGroup.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hooks/useExpandableRecordsGroup.ts b/src/hooks/useExpandableRecordsGroup.ts index 368395ecc..6176b10fe 100644 --- a/src/hooks/useExpandableRecordsGroup.ts +++ b/src/hooks/useExpandableRecordsGroup.ts @@ -53,8 +53,7 @@ const useExpandableRecordsGroup = ({ shouldDirty: returnAllFields ? Object.keys(otherValues).length > 0 : true, }) } else { - const newValues = { ...otherValues, [key]: '' } - setValue(group, newValues as PathValue>, { shouldDirty: true }) + setValue(`${group}.${key}` as Path, '' as PathValue>, { shouldDirty: true }) } }