Skip to content

Commit

Permalink
update permission e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Sep 20, 2023
1 parent b443a6d commit 230201f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
14 changes: 11 additions & 3 deletions e2e/specs/stateful/profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ const profiles = [
{
type: 'manager',
value: 'wrapmebaby.eth',
address: '0xFc5958B4B6F9a06D21E06429c8833f865577acf0',
},
{
type: 'owner',
value: 'wrapmebaby.eth',
address: '0xFc5958B4B6F9a06D21E06429c8833f865577acf0',
},
],
expiry: 'May 30, 2037',
Expand Down Expand Up @@ -208,18 +210,24 @@ test.describe('Profile', () => {
}

// should show details in more tab
await page.getByTestId('more-tab').click()
await page.getByTestId('ownership-tab').click()
for (const owner of profile.owners) {
await expect(
page.getByTestId(`role-row-${owner.address}`).getByTestId(`role-tag-${owner.type}`),
).toBeVisible()
await expect(page.getByTestId(`role-row-${owner.address}`)).toContainText(owner.value)
}

// should have view link for registration transaction
await page.getByTestId('more-tab').click()
await page.getByTestId('ownership-tab').click()
await expect(page.getByTestId('etherscan-registration-link')).toHaveAttribute(
'href',
/https:\/\/goerli\.etherscan\.io\/tx\/0x[a-fA-F0-9]{64}/,
)

// should show the expiry of the name if available
if (profile.expiry) {
await expect(page.getByTestId('expiry-data')).toContainText(profile.expiry)
await expect(page.getByTestId('expiry-panel-expiry')).toContainText(profile.expiry)
}
})
}
Expand Down
20 changes: 15 additions & 5 deletions e2e/specs/stateless/permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ test.describe('Permissions', () => {
owner: 'user',
})

const ownershipPage = makePageObject('OwnershipPage')
const subnamesPage = makePageObject('SubnamesPage')
await subnamesPage.goto(name)

await login.connect()
await expect(subnamesPage.getAddSubnameButton).toBeVisible()

await ownershipPage.goto(name)
await expect(ownershipPage.sendNameButton).toBeVisible()

const morePage = makePageObject('MorePage')
await morePage.goto(name)
await expect(morePage.getSendNameButton).toBeVisible()
await expect(morePage.editResolverButton).toBeVisible()

const permissionsPage = makePageObject('PermissionsPage')
Expand Down Expand Up @@ -90,8 +93,10 @@ test.describe('Permissions', () => {
await subnamesPage.goto(name)
await expect(subnamesPage.getDisabledAddSubnameButton).toBeVisible()

await ownershipPage.goto(name)
await expect(ownershipPage.disabledSendNameButton).toBeVisible()

await morePage.goto(name)
await expect(morePage.getDisabledSendNameButton).toBeVisible()
await expect(morePage.disabledEditResolverButton).toBeVisible()
})

Expand All @@ -113,7 +118,7 @@ test.describe('Permissions', () => {
})

const subname = `test.${name}`

const ownershipPage = makePageObject('OwnershipPage')
const profilePage = makePageObject('ProfilePage')
await profilePage.goto(subname)

Expand All @@ -127,8 +132,10 @@ test.describe('Permissions', () => {

const morePage = makePageObject('MorePage')
await morePage.goto(subname)
await expect(morePage.getSendNameButton).toBeVisible()
await expect(morePage.editResolverButton).toHaveCount(0)

ownershipPage.goto(subname)
await expect(ownershipPage.sendNameButton).toBeVisible()
})

test('should show correct buttons for managing subname (Name owner settings)', async ({
Expand All @@ -150,6 +157,7 @@ test.describe('Permissions', () => {

const subname = `test.${name}`

const ownershipPage = makePageObject('OwnershipPage')
const profilePage = makePageObject('ProfilePage')
await profilePage.goto(subname)

Expand All @@ -163,8 +171,10 @@ test.describe('Permissions', () => {

const morePage = makePageObject('MorePage')
await morePage.goto(subname)
await expect(morePage.getSendNameButton).toBeVisible()
await expect(morePage.editResolverButton).toBeVisible()

await ownershipPage.goto(subname)
await expect(ownershipPage.sendNameButton).toBeVisible()
})

test('should allow parent owner to extend expiry', async ({
Expand Down
3 changes: 3 additions & 0 deletions playwright/pageObjects/ownershipPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class OwnershipPage {

readonly sendNameButton: Locator

readonly disabledSendNameButton: Locator

readonly sendDNSButton: Locator

readonly refreshDNSButton: Locator
Expand All @@ -22,6 +24,7 @@ export class OwnershipPage {
this.page = page
this.editRolesButton = this.page.getByTestId('role-action-edit-roles')
this.sendNameButton = this.page.getByTestId('role-action-send-name')
this.disabledSendNameButton = this.page.getByTestId('send-name-disabled-button')
this.sendDNSButton = this.page.getByTestId('role-action-send-dns')
this.syncManagerButton = this.page.getByTestId('role-action-sync-manager')
this.refreshDNSButton = this.page.getByTestId('role-action-refresh-dns')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'

import { Button, Card } from '@ensdomains/thorin'

import { cacheableComponentStyles } from '@app/components/@atoms/CacheableComponent'
import { PseudoActionButton } from '@app/components/@atoms/PseudoActionButton/PseudoActionButton'
import { DisabledButtonWithTooltip } from '@app/components/@molecules/DisabledButtonWithTooltip'
import type { GroupedRoleRecord } from '@app/hooks/ownership/useRoles/useRoles'
import type { useNameDetails } from '@app/hooks/useNameDetails'

Expand Down Expand Up @@ -31,6 +33,7 @@ type Props = {
}

export const RolesSection = ({ name, roles, details }: Props) => {
const { t } = useTranslation('profile')
const actions = useRoleActions({ name, details, roles })

const isCached = details.basicIsCachedData
Expand All @@ -48,7 +51,7 @@ export const RolesSection = ({ name, roles, details }: Props) => {
/>
))}
<Footer>
{actions.data?.map(({ label, type, primary, icon, disabled = false, onClick }) => {
{actions.data?.map(({ label, type, primary, icon, error, disabled = false, onClick }) => {
if (type === 'refresh-dns')
return (
<div key={type}>
Expand All @@ -63,6 +66,20 @@ export const RolesSection = ({ name, roles, details }: Props) => {
</PseudoActionButton>
</div>
)
if (error)
return (
<div>
<DisabledButtonWithTooltip
content={t(`errors.${error}`)}
buttonId="send-name-disabled-button"
buttonText={label}
mobileWidth={150}
mobileButtonWidth="initial"
prefix={icon}
size="medium"
/>
</div>
)
return (
<div key={type}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Action = Omit<DropdownItemObject, 'onClick' | 'icon'> & {
primary?: boolean
icon: ReactNodeNoStrings
type: string
error?: string
onClick?: () => void
}

Expand Down Expand Up @@ -52,8 +53,10 @@ export const useRoleActions = ({ name, roles, details }: Props) => {
const data = useMemo(() => {
if (isLoading) return undefined
const canSend = checkCanSend({ abilities: abilities.data, nameType: nameType.data })
const canSendDNS = canSend && name && !name.endsWith('.eth')
const canSendEth = canSend && name && name.endsWith('.eth')
const { canSendError } = abilities.data
const showSend = canSend || !!canSendError
const showSendDNS = showSend && name && !name.endsWith('.eth')
const showSendEth = showSend && name && name.endsWith('.eth')
const canRefreshDNS = !!account.address && name && !name.endsWith('.eth')
const showSyncManager = checkCanSyncManager({
address: account.address,
Expand All @@ -65,11 +68,12 @@ export const useRoleActions = ({ name, roles, details }: Props) => {
const availableRoles = getAvailableRoles({ roles, abilities: abilities.data })
const canEditRoles = availableRoles.length > 0
return [
canSendDNS
showSendDNS
? {
type: 'send-dns',
icon: <AeroplaneSVG />,
label: t('action.send'),
error: canSendError,
onClick: () => showSendNameInput(`send-name-${name}`, { name }),
}
: null,
Expand All @@ -93,11 +97,12 @@ export const useRoleActions = ({ name, roles, details }: Props) => {
}),
}
: null,
canSendEth
showSendEth
? {
type: 'send-name',
icon: <AeroplaneSVG />,
label: t('action.send'),
error: canSendError,
onClick: () => showSendNameInput(`send-name-${name}`, { name }),
}
: null,
Expand Down

0 comments on commit 230201f

Please sign in to comment.