Skip to content

Commit

Permalink
add test with modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Jan 30, 2025
1 parent a4341d2 commit 3451eb6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const hiddenAccountInfoModal = {
body: () => cy.get('[data-cy=modal-hidden-account-info]'),
gotItButton: () => cy.get('[data-cy=button-hidden-account-info-gotit]'),
checkBoxMessage: () => cy.get('[data-cy=checkbox-dont-show-again]')
}
1 change: 1 addition & 0 deletions packages/ui/cypress/support/page-objects/multisigPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const multisigPage = {
subscanMenuOption: () => cy.get('[data-cy=menu-option-subscan]'),
reviewButton: () => cy.get('[data-cy=button-review-tx]'),
setIdentityMenuOption: () => cy.get('[data-cy=menu-option-set-identity]'),
hideAccountMenuOption: () => cy.get('[data-cy=menu-option-hide-this-account]'),
assetHubBalance: (id: string) => cy.get(`[data-cy=asset-balance-${id}]`),
nativeBalance: () => cy.get('[data-cy=asset-balance-native]'),

Expand Down
94 changes: 94 additions & 0 deletions packages/ui/cypress/tests/hidden-accounts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import { westendMemberAccount } from '../fixtures/westendAccounts'
import { topMenuItems } from '../support/page-objects/topMenuItems'
import { multisigPage } from '../support/page-objects/multisigPage'
import { landingPage } from '../support/page-objects/landingPage'
import { hiddenAccountInfoModal } from '../support/page-objects/modals/hiddenAccountInfoModal'

const randomAddress = 'HeVswqunza8rP2hEWDCThfiB5v2Jxng91yX2oGAZnCKtsgS'
const westendWatchedAccount = {
pubKey: '0xc94fccf2736cad38e169025ed308fdb6ae09185350b05e6193d0f5343ce7362f',
address: '5GcfBqhnXDMsUwHaebV9zHew1A6aVHbt4tH2XtdKi7mM48hC'
}

const addHiddenAccount = (address: string) => {
settingsPage.hiddenAccountsInputsWrapper().within(() => {
Expand Down Expand Up @@ -165,4 +170,93 @@ describe('Hidden Accounts', () => {
settingsPage.hiddenAccountsContainer().should('have.length', 0)
settingsPage.addButton().should('be.disabled')
})

it('can hide an account from the 3 dots menu', () => {
cy.setupAndVisit({
url: landingPageNetworkAddress({
network: 'westend',
address: westendMemberAccount.hidden.expectedPure.address
}),
extensionConnectionAllowed: true,
injectExtensionWithAccounts: [westendMemberAccount.hidden.account]
})

multisigPage.optionsMenuButton().click()
multisigPage.hideAccountMenuOption().should('exist').click()
hiddenAccountInfoModal.body().should('be.visible')
hiddenAccountInfoModal.checkBoxMessage().should('not.be.checked')
hiddenAccountInfoModal.gotItButton().should('be.visible').click()
cy.url().should('include', westendMemberAccount.hidden.expectedSingleMultisig.westEndAddress)
topMenuItems.multiproxySelectorDesktop().should('be.visible').click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 1)
goToHiddenAccountSettings()
settingsPage
.hiddenAccountsContainer()
.should('have.length', 1)
.within(() => {
accountDisplay
.addressLabel()
.should('contain.text', westendMemberAccount.hidden.expectedPure.address.slice(0, 6))
})

// remove the hidden account
settingsPage.hiddenAccountDeleteButton().should('be.visible').click()
settingsPage.hiddenAccountsContainer().should('not.exist')
topMenuItems.multiproxySelectorDesktop().should('be.visible').click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 2)
topMenuItems.homeButton().click()

// hide it again but say to not view the message again
multisigPage.optionsMenuButton().click()
multisigPage.hideAccountMenuOption().should('exist').click()
hiddenAccountInfoModal.body().should('be.visible')
hiddenAccountInfoModal.checkBoxMessage().should('not.be.checked').click()
hiddenAccountInfoModal.gotItButton().should('be.visible').click()

topMenuItems.multiproxySelectorDesktop().should('be.visible').click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 1)
goToHiddenAccountSettings()
settingsPage.hiddenAccountsContainer().should('have.length', 1)

// remove the hidden account
settingsPage.hiddenAccountDeleteButton().should('be.visible').click()

topMenuItems.homeButton().click()
topMenuItems.multiproxySelectorDesktop().should('be.visible').click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 2)

multisigPage.optionsMenuButton().click()
multisigPage.hideAccountMenuOption().should('exist').click()
hiddenAccountInfoModal.body().should('not.exist')
topMenuItems.multiproxySelectorDesktop().should('be.visible').click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 1)
})

it.only('removes a watched account if hidding a watched account', () => {
cy.setupAndVisit({
url: landingPageNetworkAddress({
network: 'westend',
address: westendWatchedAccount.address
}),
extensionConnectionAllowed: true,
injectExtensionWithAccounts: [westendMemberAccount.hidden.account],
watchedAccounts: [westendWatchedAccount.pubKey]
})

topMenuItems.multiproxySelectorDesktop().click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 3)

// hide the watched account
multisigPage.optionsMenuButton().click()
multisigPage.hideAccountMenuOption().should('exist').click()
hiddenAccountInfoModal.body().should('be.visible')
hiddenAccountInfoModal.gotItButton().click()

topMenuItems.multiproxySelectorDesktop().click()
topMenuItems.multiproxySelectorOptionDesktop().should('have.length', 2)
goToHiddenAccountSettings()
settingsPage.hiddenAccountsContainer().should('not.exist')
settingsPage.watchedAccountsAccordion().click()
settingsPage.watchedAccountsContainer().should('not.exist')
})
})
3 changes: 2 additions & 1 deletion packages/ui/src/components/modals/HiddenAccountInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ const HiddenAccountInfo = ({ onClose, className }: Props) => {
setDontShow(!dontShow)
}}
// @ts-expect-error
inputProps={{ 'data-cy': 'checkbox-message' }}
inputProps={{ 'data-cy': 'checkbox-dont-show-again' }}
/>
}
/>
<Button
data-cy="button-hidden-account-info-gotit"
className="closeButton"
variant="primary"
onClick={onClick}
Expand Down
27 changes: 15 additions & 12 deletions packages/ui/src/hooks/useGetIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ export const useGetIdentity = () => {
}
).then((val) => {
const id: IdentityInfo = { judgements: [], sub }
val?.[0].judgements.forEach(([, judgement]) => {
id.judgements.push(judgement.type)
})
Object.entries(val?.[0]?.info || {}).forEach(([key, value]) => {
if ((value as IdentityData)?.type !== 'None') {
// console.log('key', JSONprint(key));
// console.log('value', JSONprint(value));
const text = (value as IdentityData)?.value as FixedSizeBinary<2> | undefined
if (text) {
id[key] = text.asText()

if (val?.[0]) {
val?.[0].judgements.forEach(([, judgement]) => {
id.judgements.push(judgement.type)
})
Object.entries(val?.[0]?.info || {}).forEach(([key, value]) => {
if ((value as IdentityData)?.type !== 'None') {
// console.log('key', JSONprint(key));
// console.log('value', JSONprint(value));
const text = (value as IdentityData)?.value as FixedSizeBinary<2> | undefined
if (text) {
id[key] = text.asText()
}
}
}
})
})
}

return id
})
Expand Down

0 comments on commit 3451eb6

Please sign in to comment.