|
1 | 1 | import { |
2 | 2 | MAX_LABEL_LENGTH, |
| 3 | + addAccountToLocation, |
3 | 4 | getAccountLabel, |
| 5 | + getInitialSourceType, |
4 | 6 | shorten, |
5 | | -} from './SourceTypeSelector.tsx' |
| 7 | +} from './util.ts' |
6 | 8 |
|
7 | 9 | import type { BaseInternetAccountModel } from '../../pluggableElementTypes/index.ts' |
8 | 10 |
|
@@ -69,3 +71,90 @@ describe('getAccountLabel', () => { |
69 | 71 | expect(getAccountLabel(account)).toBe('Box') |
70 | 72 | }) |
71 | 73 | }) |
| 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 | +}) |
0 commit comments