Skip to content

Commit c1c73e5

Browse files
committed
fix lint and test
1 parent 7c48ba7 commit c1c73e5

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/components/File/File.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ describe('File Component', () => {
4444
const source = getHttpSource(url)
4545
assert(source?.kind === 'file')
4646

47-
const { getByText } = await act(() => render(<File source={source} />))
47+
const { getAllByRole } = await act(() => render(
48+
<ConfigProvider value={config}>
49+
<File source={source} />
50+
</ConfigProvider>
51+
))
4852

49-
expect(getByText(url)).toBeDefined()
53+
const links = getAllByRole('link')
54+
expect(links[0]?.getAttribute('href')).toBe('/')
55+
expect(links[1]?.getAttribute('href')).toBe('/files?key=https://example.com/')
56+
expect(links[2]?.getAttribute('href')).toBe('/files?key=https://example.com/test.txt')
5057
})
5158

5259
it('renders correct breadcrumbs for nested folders', async () => {

src/lib/sources/httpSource.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DirSource, FileMetadata, FileSource, SourcePart } from './types.js'
22
import { getFileName } from './utils.js'
33

4-
function s3listv2(bucket: string, prefix: string) {
4+
function s3list(bucket: string, prefix: string) {
55
const url = `https://${bucket}.s3.amazonaws.com/?list-type=2&prefix=${prefix}&delimiter=/`
66
return fetch(url)
77
.then(res => {
@@ -58,7 +58,6 @@ function getSourceParts(sourceId: string): SourcePart[] {
5858
? [`${protocol}://${rest.split('/', 1)[0]}`, ...rest.split('/').slice(1)]
5959
: sourceId.split('/')
6060
const sourceParts = [
61-
//{ 'text': '/', 'sourceId': '' },
6261
...parts.map((part, depth) => {
6362
const slashSuffix = depth === parts.length - 1 ? '' : '/'
6463
return {
@@ -94,13 +93,17 @@ export function getHttpSource(sourceId: string, options?: {requestInit?: Request
9493
sourceId,
9594
sourceParts,
9695
prefix,
97-
listFiles: () => s3listv2(bucket, prefix).then(items =>
96+
listFiles: () => s3list(bucket, prefix).then(items =>
9897
items
9998
.filter(item => item.key !== undefined)
10099
.map(item => {
101-
const isDirectory = item.key!.endsWith('/')
100+
if (!item.key) {
101+
throw new Error('Key is undefined')
102+
}
103+
const isDirectory = item.key.endsWith('/')
102104
const itemSourceId = `https://${bucket}.s3.amazonaws.com/${item.key}`
103-
let name = item.key!.split('/').pop() || item.key
105+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
106+
let name = item.key.split('/').pop() || item.key
104107
if (name && isDirectory) {
105108
name = name.replace(prefix, '')
106109
}

0 commit comments

Comments
 (0)