Skip to content

Commit f8e5b59

Browse files
committed
Updates
1 parent 346cb9b commit f8e5b59

File tree

5 files changed

+92
-94
lines changed

5 files changed

+92
-94
lines changed

packages/core/src/ui/FileSelector/FileSelector.test.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/core/src/ui/FileSelector/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/core/src/ui/FileSelector/util.test.ts

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
MAX_LABEL_LENGTH,
3+
addAccountToLocation,
34
getAccountLabel,
5+
getInitialSourceType,
46
shorten,
5-
} from './SourceTypeSelector.tsx'
7+
} from './util.ts'
68

79
import type { BaseInternetAccountModel } from '../../pluggableElementTypes/index.ts'
810

@@ -69,3 +71,90 @@ describe('getAccountLabel', () => {
6971
expect(getAccountLabel(account)).toBe('Box')
7072
})
7173
})
74+
75+
describe('getInitialSourceType', () => {
76+
test('returns internetAccountId when location has one', () => {
77+
const location = {
78+
locationType: 'UriLocation' as const,
79+
uri: 'https://example.com/file.bam',
80+
internetAccountId: 'google-drive-account',
81+
}
82+
expect(getInitialSourceType(location)).toBe('google-drive-account')
83+
})
84+
85+
test('returns "url" for UriLocation without internetAccountId', () => {
86+
const location = {
87+
locationType: 'UriLocation' as const,
88+
uri: 'https://example.com/file.bam',
89+
}
90+
expect(getInitialSourceType(location)).toBe('url')
91+
})
92+
93+
test('returns "url" for undefined location', () => {
94+
expect(getInitialSourceType(undefined)).toBe('url')
95+
})
96+
97+
test('returns "file" for BlobLocation', () => {
98+
const location = {
99+
locationType: 'BlobLocation' as const,
100+
blobId: 'b123',
101+
name: 'test.bam',
102+
}
103+
expect(getInitialSourceType(location)).toBe('file')
104+
})
105+
106+
test('returns "file" for FileHandleLocation', () => {
107+
const location = {
108+
locationType: 'FileHandleLocation' as const,
109+
handleId: 'fh123',
110+
name: 'test.bam',
111+
}
112+
expect(getInitialSourceType(location)).toBe('file')
113+
})
114+
115+
test('returns "file" for LocalPathLocation', () => {
116+
const location = {
117+
locationType: 'LocalPathLocation' as const,
118+
localPath: '/path/to/file.bam',
119+
}
120+
expect(getInitialSourceType(location)).toBe('file')
121+
})
122+
})
123+
124+
describe('addAccountToLocation', () => {
125+
const mockAccount = {
126+
internetAccountId: 'test-account-id',
127+
} as BaseInternetAccountModel
128+
129+
test('adds internetAccountId to UriLocation', () => {
130+
const location = {
131+
locationType: 'UriLocation' as const,
132+
uri: 'https://example.com/file.bam',
133+
}
134+
const result = addAccountToLocation(location, mockAccount)
135+
expect(result).toEqual({
136+
locationType: 'UriLocation',
137+
uri: 'https://example.com/file.bam',
138+
internetAccountId: 'test-account-id',
139+
})
140+
})
141+
142+
test('returns location unchanged when no account provided', () => {
143+
const location = {
144+
locationType: 'UriLocation' as const,
145+
uri: 'https://example.com/file.bam',
146+
}
147+
const result = addAccountToLocation(location, undefined)
148+
expect(result).toEqual(location)
149+
})
150+
151+
test('returns non-UriLocation unchanged even with account', () => {
152+
const location = {
153+
locationType: 'BlobLocation' as const,
154+
blobId: 'b123',
155+
name: 'test.bam',
156+
}
157+
const result = addAccountToLocation(location, mockAccount)
158+
expect(result).toEqual(location)
159+
})
160+
})

packages/core/src/ui/FileSelector/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isUriLocation } from '@jbrowse/core/util/index'
22

33
import type { BaseInternetAccountModel } from '../../pluggableElementTypes/index.ts'
4-
import type { FileLocation } from '@jbrowse/core/util/index'
4+
import type { FileLocation } from '../../util/index.ts'
55

66
export const MAX_LABEL_LENGTH = 5
77

packages/core/src/ui/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export { default as Dialog } from './Dialog.tsx'
77
export { default as EditableTypography } from './EditableTypography.tsx'
88
export { default as ErrorMessage } from './ErrorMessage.tsx'
99
export { default as FatalErrorDialog } from './FatalErrorDialog.tsx'
10-
export { default as FileSelector } from './FileSelector/index.ts'
10+
export { default as FileSelector } from './FileSelector/FileSelector.tsx'
1111
export { default as LoadingEllipses } from './LoadingEllipses.tsx'
1212
export { default as Menu } from './Menu.tsx'
1313
export { default as PrerenderedCanvas } from './PrerenderedCanvas.tsx'

0 commit comments

Comments
 (0)