Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FET-1619 If tab specified in query string doesn't exist, app crashes. Should redirect to profile tab #835

Merged
merged 19 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
54 changes: 54 additions & 0 deletions e2e/specs/stateless/profileEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,60 @@ test.describe('profile', () => {
await expect(profilePage.record('text', 'email')).toHaveText('[email protected]')
await expect(profilePage.contentHash()).toContainText('ipfs://bafybeic...')
})

test('should redirect to profile tab if tab specified in query string does not exist', async ({
page,
login,
makeName,
makePageObject,
}) => {
const name = await makeName({
label: 'profile',
type: 'legacy',
records: await makeRecords(),
})

const profilePage = makePageObject('ProfilePage')

await profilePage.goto(name)
await login.connect()

const validTabs: Array<String> = [
'profile',
'records',
'ownership',
'subnames',
'permissions',
'more',
] as const

const generateRandomTab = () => {
const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
vuongnmdevblock marked this conversation as resolved.
Show resolved Hide resolved
const length = 10

let randomTab = ''

do {
randomTab = Array.from({ length }, () =>
characters.charAt(Math.floor(Math.random() * characters.length)),
).join('')
} while (validTabs.includes(randomTab))

return randomTab
}

await page.goto(`/${name}?tab=${generateRandomTab()}`)

await expect(page).toHaveURL(`/${name}`)

await page.pause()
await expect(profilePage.record('text', 'description')).toHaveText('Hello2')
await expect(profilePage.record('text', 'url')).toHaveText('twitter.com')
await expect(profilePage.record('address', 'btc')).toHaveText('bc1qj...pwa6n')
await expect(profilePage.record('address', 'etcLegacy')).toHaveText('etcLegacy0x3C4...293BC')
await expect(profilePage.record('text', 'email')).toHaveText('[email protected]')
await expect(profilePage.contentHash()).toContainText('ipfs://bafybeic...')
})
})

test.describe('migrations', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/components/pages/profile/[name]/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,16 @@ const ProfileContent = ({ isSelf, isLoading: parentIsLoading, name }: Props) =>
// profile.decryptedName fetches labels from NW/subgraph
// normalisedName fetches labels from localStorage
useEffect(() => {
if (!tab || !tabs.includes(tab)) {
router.replace(`/${normalisedName}`)
}
shouldRedirect(router, 'Profile.tsx', '/profile', {
vuongnmdevblock marked this conversation as resolved.
Show resolved Hide resolved
isSelf,
name,
decodedName: profile?.decodedName,
normalisedName,
})
}, [profile?.decodedName, normalisedName, name, isSelf, router])
}, [profile?.decodedName, normalisedName, name, isSelf, router, tab])

// useEffect(() => {
// if (shouldShowSuccessPage(transactions)) {
Expand Down Expand Up @@ -296,7 +299,7 @@ const ProfileContent = ({ isSelf, isLoading: parentIsLoading, name }: Props) =>
.with('more', () => (
<MoreTab name={normalisedName} nameDetails={nameDetails} abilities={abilities.data} />
))
.exhaustive(),
.otherwise(() => <ProfileTab name={normalisedName} nameDetails={nameDetails} />),
}}
vuongnmdevblock marked this conversation as resolved.
Show resolved Hide resolved
</Content>
</>
Expand Down
Loading