Skip to content

Commit 18b9b0d

Browse files
ChayanDasslidel
andauthored
fix(files): not found page (#2455)
* fix the file not found page * fix the header for file not found Signed-off-by: Chayan Das <01chayandas@gmail.com> * test(e2e): add test for file-not-found error page verify that browsing to a non-existing path shows the "Unable to load this path" error page with a working "Go to Files" button also fix flakiness by waiting for buttons to be enabled before clicking, and fix selector in invalid IPNS test --------- Signed-off-by: Chayan Das <01chayandas@gmail.com> Co-authored-by: Marcin Rataj <lidel@lidel.org>
1 parent 74a44d8 commit 18b9b0d

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

src/files/FilesPage.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ const FilesPage = ({
197197
, [files?.content, files?.pins, selected])
198198

199199
if (!files || files.type === 'file') return null
200-
200+
// if file not found
201+
if (files.type === 'not-found') {
202+
return <FileNotFound path={files.path} error={files.error} />
203+
}
201204
// Don't render stale content during navigation
202205
if (files.path && filesPathInfo.path && files.path !== filesPathInfo.path) {
203206
return null
204207
}
205-
206208
if (files.type === 'unknown') {
207209
// Show error page if there's an error, otherwise show inspect suggestion
208210
if (files.error) {
@@ -217,9 +219,6 @@ const FilesPage = ({
217219
</div>
218220
)
219221
}
220-
if (files.type === 'not-found') {
221-
return <FileNotFound path={files.path} error={files.error} />
222-
}
223222

224223
const commonProps = {
225224
updateSorting: doFilesUpdateSorting,

src/files/header/Header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class Header extends React.Component {
5757
} = this.props
5858

5959
const pinsInQueue = pendingPins.length + failedPins.length + completedPins.length
60-
60+
const filefound = files && files.type !== 'not-found'
6161
return (
6262
<div className='db flex-l justify-between items-center mb3'>
6363
<div className='flex items-center w-100 justify-between mr3'>
6464
<div className='breadheader overflow-hidden mr1'>
65-
<Breadcrumbs className="joyride-files-breadcrumbs" path={files ? files.path : '/404'}
65+
<Breadcrumbs className="joyride-files-breadcrumbs" path={filefound ? files.path : '/404'}
6666
onClick={onNavigate} onContextMenuHandle={(...args) => this.handleBreadCrumbsContextMenu(...args)}
6767
onAddFiles={this.props.onAddFiles} onMove={this.props.onMove}/>
6868
</div>

test/e2e/explore.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const createCID = async (value, codec, hasher, version = 1) => {
4444
async function testExploredCid ({ cid, type, humanReadableCID, page, fillOutForm = true }) {
4545
if (fillOutForm) {
4646
await explore.cidInput(page).fill(cid)
47+
await expect(explore.inspectButton(page)).toBeEnabled()
4748
await explore.inspectButton(page).press('Enter')
4849
}
4950

@@ -96,6 +97,7 @@ test.describe('Explore screen', () => {
9697
test('Inspect button opens DAG Explorer and shows Raw Block', async ({ page }) => {
9798
// enter the inlined "hello world" CID in the explore form
9899
await explore.cidInput(page).fill(INLINED_HELLO_WORLD_CID)
100+
await expect(explore.inspectButton(page)).toBeEnabled()
99101
await explore.inspectButton(page).click()
100102

101103
// should navigate to Explore screen with the CID

test/e2e/files.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect } from './setup/coverage.js'
22
import { fixtureData } from './fixtures/index.js'
3-
import { files } from './setup/locators.js'
3+
import { files, explore } from './setup/locators.js'
44
import all from 'it-all'
55
import filesize from 'filesize'
66
import * as kuboRpcModule from 'kubo-rpc-client'
@@ -112,4 +112,28 @@ test.describe('Files screen', () => {
112112
await page.waitForURL(`/#/explore/${testCid}`)
113113
await expect(page.getByText('CID info')).toBeVisible()
114114
})
115+
116+
test('should show error page when navigating to non-existing path', async ({ page }) => {
117+
// bafyaabakaieac is CIDv1 of an empty directory, so /404 inside it does not exist
118+
const nonExistingPath = '/ipfs/bafyaabakaieac/404'
119+
120+
// enter the path in the explore form input and click Browse
121+
await explore.cidInput(page).fill(nonExistingPath)
122+
await expect(explore.browseButton(page)).toBeEnabled()
123+
await explore.browseButton(page).click()
124+
125+
// expect error page to be displayed with the correct title
126+
await expect(page.getByRole('heading', { name: 'Unable to load this path' })).toBeVisible()
127+
128+
// expect the path to be displayed in the error message area (below the heading)
129+
await expect(page.locator('p.truncate').filter({ hasText: 'bafyaabakaieac/404' })).toBeVisible()
130+
131+
// expect the "Go to Files" button to be present and working
132+
const goToFilesButton = page.getByRole('link', { name: 'Go to Files' })
133+
await expect(goToFilesButton).toBeVisible()
134+
await goToFilesButton.click()
135+
136+
// confirm navigation back to files root
137+
await page.waitForURL('/#/files')
138+
})
115139
})

test/e2e/status.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ test.describe('Status page', () => {
4141

4242
// enter the inlined "hello world" CID
4343
await explore.cidInput(page).fill(INLINED_HELLO_WORLD_CID)
44+
await expect(explore.browseButton(page)).toBeEnabled()
4445
await explore.browseButton(page).click()
4546

4647
// should display the file content "hello world"
@@ -56,6 +57,7 @@ test.describe('Status page', () => {
5657

5758
// enter the inlined "hello world" CID
5859
await explore.cidInput(page).fill(INLINED_HELLO_WORLD_CID)
60+
await expect(explore.inspectButton(page)).toBeEnabled()
5961
await explore.inspectButton(page).click()
6062

6163
// should display "Raw Block" in DAG Explorer
@@ -88,16 +90,14 @@ test.describe('Status page', () => {
8890

8991
// enter an IPNS path that will fail DNSLink resolution
9092
await explore.cidInput(page).fill('/ipns/invalid-dnslink.example.com')
93+
await expect(explore.browseButton(page)).toBeEnabled()
9194
await explore.browseButton(page).click()
9295

9396
// wait for navigation to the IPNS path
9497
await expect(page).toHaveURL(/invalid-dnslink/, { timeout: 10000 })
9598

96-
// should show error state - either 404 badge or error page
97-
// (depends on how quickly the DNS lookup fails)
98-
const error404 = page.getByText('404')
99-
const errorPage = page.locator('h1.red')
100-
await expect(error404.or(errorPage)).toBeVisible({ timeout: 30000 })
99+
// should show error page with "Unable to load this path" heading
100+
await expect(page.getByRole('heading', { name: 'Unable to load this path' })).toBeVisible({ timeout: 30000 })
101101
})
102102

103103
test('ipfs:// protocol URL is accepted and normalized', async ({ page }) => {

0 commit comments

Comments
 (0)