@fgv/ts-web-extras 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/86c9c1ad46e237e0b957c2442bf0355cf39babba.tar.log +121 -0
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +40 -0
- package/.rush/temp/operation/build/all.log +40 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +40 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +624 -0
- package/config/api-extractor.json +343 -0
- package/config/jest.config.json +16 -0
- package/config/rig.json +16 -0
- package/dist/ts-web-extras.d.ts +574 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/docs/index.md +34 -0
- package/docs/ts-web-extras.browserhashprovider.hashparts.md +88 -0
- package/docs/ts-web-extras.browserhashprovider.hashstring.md +72 -0
- package/docs/ts-web-extras.browserhashprovider.md +66 -0
- package/docs/ts-web-extras.exportasjson.md +70 -0
- package/docs/ts-web-extras.exportusingfilesystemapi.md +104 -0
- package/docs/ts-web-extras.extractdirectorypath.md +52 -0
- package/docs/ts-web-extras.fileapitreeaccessors.create.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +54 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.md +114 -0
- package/docs/ts-web-extras.filepickeraccepttype.accept.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.description.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.md +75 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +11 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +146 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +50 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +52 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.md +92 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +50 -0
- package/docs/ts-web-extras.filesystemhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.md +119 -0
- package/docs/ts-web-extras.filesystemhandle_2.name.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +58 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +11 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +11 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.md +57 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +50 -0
- package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +13 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.filetreehelpers.md +102 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +100 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.md +79 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.md +58 -0
- package/docs/ts-web-extras.ifilemetadata.lastmodified.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.md +124 -0
- package/docs/ts-web-extras.ifilemetadata.name.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.path.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.size.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.type.md +11 -0
- package/docs/ts-web-extras.ifsaccessapis.md +56 -0
- package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +52 -0
- package/docs/ts-web-extras.isdirectoryhandle.md +56 -0
- package/docs/ts-web-extras.isfilehandle.md +56 -0
- package/docs/ts-web-extras.isfilepath.md +52 -0
- package/docs/ts-web-extras.iurlconfigoptions.config.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.input.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.interactive.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.md +286 -0
- package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zippath.md +13 -0
- package/docs/ts-web-extras.md +512 -0
- package/docs/ts-web-extras.parsecontextfilter.md +52 -0
- package/docs/ts-web-extras.parsequalifierdefaults.md +52 -0
- package/docs/ts-web-extras.parseresourcetypes.md +52 -0
- package/docs/ts-web-extras.parseurlparameters.md +17 -0
- package/docs/ts-web-extras.safeshowdirectorypicker.md +72 -0
- package/docs/ts-web-extras.safeshowopenfilepicker.md +72 -0
- package/docs/ts-web-extras.safeshowsavefilepicker.md +72 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.md +96 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.supportsfilesystemaccess.md +56 -0
- package/docs/ts-web-extras.treeinitializer.md +15 -0
- package/docs/ts-web-extras.wellknowndirectory.md +13 -0
- package/docs/ts-web-extras.windowwithfsaccess.md +15 -0
- package/etc/ts-web-extras.api.md +310 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts +24 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.js +70 -0
- package/lib/packlets/crypto/browserHashProvider.js.map +1 -0
- package/lib/packlets/crypto/index.d.ts +6 -0
- package/lib/packlets/crypto/index.d.ts.map +1 -0
- package/lib/packlets/crypto/index.js +43 -0
- package/lib/packlets/crypto/index.js.map +1 -0
- package/lib/packlets/file-api-types/index.d.ts +205 -0
- package/lib/packlets/file-api-types/index.d.ts.map +1 -0
- package/lib/packlets/file-api-types/index.js +166 -0
- package/lib/packlets/file-api-types/index.js.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +129 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +334 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +6 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js +43 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts +60 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.js +102 -0
- package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/helpers/index.d.ts +6 -0
- package/lib/packlets/helpers/index.d.ts.map +1 -0
- package/lib/packlets/helpers/index.js +63 -0
- package/lib/packlets/helpers/index.js.map +1 -0
- package/lib/packlets/url-utils/index.d.ts +6 -0
- package/lib/packlets/url-utils/index.d.ts.map +1 -0
- package/lib/packlets/url-utils/index.js +43 -0
- package/lib/packlets/url-utils/index.js.map +1 -0
- package/lib/packlets/url-utils/urlParams.d.ts +94 -0
- package/lib/packlets/url-utils/urlParams.d.ts.map +1 -0
- package/lib/packlets/url-utils/urlParams.js +165 -0
- package/lib/packlets/url-utils/urlParams.js.map +1 -0
- package/lib/test/setupTests.d.ts +2 -0
- package/lib/test/setupTests.d.ts.map +1 -0
- package/lib/test/setupTests.js +76 -0
- package/lib/test/setupTests.js.map +1 -0
- package/lib/test/unit/browserHashProvider.test.d.ts +2 -0
- package/lib/test/unit/browserHashProvider.test.d.ts.map +1 -0
- package/lib/test/unit/browserHashProvider.test.js +142 -0
- package/lib/test/unit/browserHashProvider.test.js.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js +1139 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/fileApiTypes.test.d.ts +2 -0
- package/lib/test/unit/fileApiTypes.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTypes.test.js +444 -0
- package/lib/test/unit/fileApiTypes.test.js.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts +2 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.js +592 -0
- package/lib/test/unit/fileTreeHelpers.test.js.map +1 -0
- package/lib/test/unit/urlParams.test.d.ts +2 -0
- package/lib/test/unit/urlParams.test.d.ts.map +1 -0
- package/lib/test/unit/urlParams.test.js +395 -0
- package/lib/test/unit/urlParams.test.js.map +1 -0
- package/lib/test/utils/testHelpers.d.ts +51 -0
- package/lib/test/utils/testHelpers.d.ts.map +1 -0
- package/lib/test/utils/testHelpers.js +133 -0
- package/lib/test/utils/testHelpers.js.map +1 -0
- package/package.json +68 -0
- package/rush-logs/ts-web-extras.build.cache.log +3 -0
- package/rush-logs/ts-web-extras.build.log +40 -0
- package/src/index.ts +47 -0
- package/src/packlets/crypto/browserHashProvider.ts +73 -0
- package/src/packlets/crypto/index.ts +28 -0
- package/src/packlets/file-api-types/index.ts +345 -0
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +420 -0
- package/src/packlets/file-tree/index.ts +28 -0
- package/src/packlets/helpers/fileTreeHelpers.ts +107 -0
- package/src/packlets/helpers/index.ts +28 -0
- package/src/packlets/url-utils/index.ts +28 -0
- package/src/packlets/url-utils/urlParams.ts +245 -0
- package/src/test/setupTests.ts +87 -0
- package/src/test/unit/browserHashProvider.test.ts +155 -0
- package/src/test/unit/browserHashProvider.test.ts.bak +376 -0
- package/src/test/unit/fileApiTreeAccessors.test.ts +1318 -0
- package/src/test/unit/fileApiTypes.test.ts +551 -0
- package/src/test/unit/fileTreeHelpers.test.ts +694 -0
- package/src/test/unit/urlParams.test.ts +464 -0
- package/src/test/utils/testHelpers.ts +155 -0
- package/temp/build/typescript/ts_l9Fw4VUO.json +1 -0
- package/temp/coverage/base.css +224 -0
- package/temp/coverage/block-navigation.js +87 -0
- package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/crypto/index.html +116 -0
- package/temp/coverage/favicon.png +0 -0
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/file-tree/index.html +116 -0
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/helpers/index.html +116 -0
- package/temp/coverage/index.html +161 -0
- package/temp/coverage/lcov-report/base.css +224 -0
- package/temp/coverage/lcov-report/block-navigation.js +87 -0
- package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/lcov-report/crypto/index.html +116 -0
- package/temp/coverage/lcov-report/favicon.png +0 -0
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/lcov-report/file-tree/index.html +116 -0
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/lcov-report/helpers/index.html +116 -0
- package/temp/coverage/lcov-report/index.html +161 -0
- package/temp/coverage/lcov-report/prettify.css +1 -0
- package/temp/coverage/lcov-report/prettify.js +2 -0
- package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/temp/coverage/lcov-report/sorter.js +210 -0
- package/temp/coverage/lcov-report/url-utils/index.html +116 -0
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +820 -0
- package/temp/coverage/lcov.info +1096 -0
- package/temp/coverage/prettify.css +1 -0
- package/temp/coverage/prettify.js +2 -0
- package/temp/coverage/sort-arrow-sprite.png +0 -0
- package/temp/coverage/sorter.js +210 -0
- package/temp/coverage/url-utils/index.html +116 -0
- package/temp/coverage/url-utils/urlParams.ts.html +820 -0
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/63/package_63a8257b0e4d0e7ff33f927d75f27a75 +53 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
- package/temp/ts-web-extras.api.json +5040 -0
- package/temp/ts-web-extras.api.md +310 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import '@fgv/ts-utils-jest';
|
|
24
|
+
import {
|
|
25
|
+
parseUrlParameters,
|
|
26
|
+
parseContextFilter,
|
|
27
|
+
parseQualifierDefaults,
|
|
28
|
+
parseResourceTypes,
|
|
29
|
+
extractDirectoryPath,
|
|
30
|
+
isFilePath,
|
|
31
|
+
type IUrlConfigOptions
|
|
32
|
+
} from '../../packlets/url-utils';
|
|
33
|
+
|
|
34
|
+
// Mock window.location.search for testing
|
|
35
|
+
const mockLocation = {
|
|
36
|
+
search: ''
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Object.defineProperty(window, 'location', {
|
|
40
|
+
value: mockLocation,
|
|
41
|
+
writable: true
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('URL Parameters', () => {
|
|
45
|
+
describe('parseUrlParameters', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
mockLocation.search = '';
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('returns empty object for empty URL parameters', () => {
|
|
51
|
+
mockLocation.search = '';
|
|
52
|
+
const result = parseUrlParameters();
|
|
53
|
+
expect(result).toEqual({});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('parses basic string parameters', () => {
|
|
57
|
+
mockLocation.search = '?input=test.json&config=config.json';
|
|
58
|
+
const result = parseUrlParameters();
|
|
59
|
+
expect(result).toEqual({
|
|
60
|
+
input: 'test.json',
|
|
61
|
+
config: 'config.json',
|
|
62
|
+
inputStartDir: '/',
|
|
63
|
+
configStartDir: '/'
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('parses file paths and sets start directories', () => {
|
|
68
|
+
mockLocation.search = '?input=/path/to/file.json&config=/config/settings.json';
|
|
69
|
+
const result = parseUrlParameters();
|
|
70
|
+
expect(result).toEqual({
|
|
71
|
+
input: '/path/to/file.json',
|
|
72
|
+
config: '/config/settings.json',
|
|
73
|
+
inputStartDir: '/path/to',
|
|
74
|
+
configStartDir: '/config'
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('handles directory paths without setting start directories', () => {
|
|
79
|
+
mockLocation.search = '?input=/path/to/directory&config=/config/folder';
|
|
80
|
+
const result = parseUrlParameters();
|
|
81
|
+
expect(result).toEqual({
|
|
82
|
+
input: '/path/to/directory',
|
|
83
|
+
config: '/config/folder'
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('parses numeric parameters', () => {
|
|
88
|
+
mockLocation.search = '?maxDistance=5';
|
|
89
|
+
const result = parseUrlParameters();
|
|
90
|
+
expect(result).toEqual({
|
|
91
|
+
maxDistance: 5
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('ignores invalid numeric parameters', () => {
|
|
96
|
+
mockLocation.search = '?maxDistance=invalid';
|
|
97
|
+
const result = parseUrlParameters();
|
|
98
|
+
expect(result).toEqual({});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('parses boolean parameters (true)', () => {
|
|
102
|
+
mockLocation.search = '?reduceQualifiers=true&interactive=true&loadZip=true';
|
|
103
|
+
const result = parseUrlParameters();
|
|
104
|
+
expect(result).toEqual({
|
|
105
|
+
reduceQualifiers: true,
|
|
106
|
+
interactive: true,
|
|
107
|
+
loadZip: true
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('ignores boolean parameters that are not "true"', () => {
|
|
112
|
+
mockLocation.search = '?reduceQualifiers=false&interactive=1&loadZip=yes';
|
|
113
|
+
const result = parseUrlParameters();
|
|
114
|
+
expect(result).toEqual({});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('parses complex filter parameters', () => {
|
|
118
|
+
mockLocation.search =
|
|
119
|
+
'?contextFilter=lang%3Den%7Cregion%3DUS&qualifierDefaults=lang%3Den,fr%7Cregion%3DUS&resourceTypes=json,string';
|
|
120
|
+
const result = parseUrlParameters();
|
|
121
|
+
expect(result).toEqual({
|
|
122
|
+
contextFilter: 'lang=en|region=US',
|
|
123
|
+
qualifierDefaults: 'lang=en,fr|region=US',
|
|
124
|
+
resourceTypes: 'json,string'
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('parses ZIP loading parameters', () => {
|
|
129
|
+
mockLocation.search = '?loadZip=true&zipPath=/path/to/archive.zip&zipFile=download.zip';
|
|
130
|
+
const result = parseUrlParameters();
|
|
131
|
+
expect(result).toEqual({
|
|
132
|
+
loadZip: true,
|
|
133
|
+
zipPath: '/path/to/archive.zip',
|
|
134
|
+
zipFile: 'download.zip'
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('parses all parameters together', () => {
|
|
139
|
+
mockLocation.search =
|
|
140
|
+
'?input=data.json&config=settings.json&contextFilter=lang%3Den&qualifierDefaults=lang%3Den,fr&resourceTypes=json&maxDistance=3&reduceQualifiers=true&interactive=true&loadZip=true&zipPath=archive.zip&zipFile=download.zip';
|
|
141
|
+
const result = parseUrlParameters();
|
|
142
|
+
expect(result).toEqual({
|
|
143
|
+
input: 'data.json',
|
|
144
|
+
config: 'settings.json',
|
|
145
|
+
contextFilter: 'lang=en',
|
|
146
|
+
qualifierDefaults: 'lang=en,fr',
|
|
147
|
+
resourceTypes: 'json',
|
|
148
|
+
maxDistance: 3,
|
|
149
|
+
reduceQualifiers: true,
|
|
150
|
+
interactive: true,
|
|
151
|
+
loadZip: true,
|
|
152
|
+
zipPath: 'archive.zip',
|
|
153
|
+
zipFile: 'download.zip',
|
|
154
|
+
inputStartDir: '/',
|
|
155
|
+
configStartDir: '/'
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('handles URL encoded parameters', () => {
|
|
160
|
+
mockLocation.search = '?input=test%20file.json&config=config%2Bsettings.json';
|
|
161
|
+
const result = parseUrlParameters();
|
|
162
|
+
expect(result).toEqual({
|
|
163
|
+
input: 'test file.json',
|
|
164
|
+
config: 'config+settings.json',
|
|
165
|
+
inputStartDir: '/',
|
|
166
|
+
configStartDir: '/'
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('handles empty parameter values', () => {
|
|
171
|
+
mockLocation.search = '?input=&config=&maxDistance=';
|
|
172
|
+
const result = parseUrlParameters();
|
|
173
|
+
expect(result).toEqual({});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('parseContextFilter', () => {
|
|
178
|
+
test('parses simple key-value pairs', () => {
|
|
179
|
+
const result = parseContextFilter('language=en-US|territory=US');
|
|
180
|
+
expect(result).toEqual({
|
|
181
|
+
language: 'en-US',
|
|
182
|
+
territory: 'US'
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('handles single key-value pair', () => {
|
|
187
|
+
const result = parseContextFilter('language=en-US');
|
|
188
|
+
expect(result).toEqual({
|
|
189
|
+
language: 'en-US'
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('trims whitespace from keys and values', () => {
|
|
194
|
+
const result = parseContextFilter(' language = en-US | territory = US ');
|
|
195
|
+
expect(result).toEqual({
|
|
196
|
+
language: 'en-US',
|
|
197
|
+
territory: 'US'
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('handles empty string', () => {
|
|
202
|
+
const result = parseContextFilter('');
|
|
203
|
+
expect(result).toEqual({});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('ignores tokens without equals sign', () => {
|
|
207
|
+
const result = parseContextFilter('language=en-US|invalidtoken|territory=US');
|
|
208
|
+
expect(result).toEqual({
|
|
209
|
+
language: 'en-US',
|
|
210
|
+
territory: 'US'
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('ignores tokens with missing key', () => {
|
|
215
|
+
const result = parseContextFilter('=en-US|territory=US');
|
|
216
|
+
expect(result).toEqual({
|
|
217
|
+
territory: 'US'
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('ignores tokens with missing value', () => {
|
|
222
|
+
const result = parseContextFilter('language=|territory=US');
|
|
223
|
+
expect(result).toEqual({
|
|
224
|
+
territory: 'US'
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('handles special characters in values', () => {
|
|
229
|
+
const result = parseContextFilter('language=en-US|path=/some/path.json');
|
|
230
|
+
expect(result).toEqual({
|
|
231
|
+
language: 'en-US',
|
|
232
|
+
path: '/some/path.json'
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('handles complex nested values', () => {
|
|
237
|
+
const result = parseContextFilter('filter=a=b,c=d|type=complex');
|
|
238
|
+
expect(result).toEqual({
|
|
239
|
+
filter: 'a',
|
|
240
|
+
type: 'complex'
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('parseQualifierDefaults', () => {
|
|
246
|
+
test('parses simple qualifier defaults', () => {
|
|
247
|
+
const result = parseQualifierDefaults('language=en-US,en-CA|territory=US');
|
|
248
|
+
expect(result).toEqual({
|
|
249
|
+
language: ['en-US', 'en-CA'],
|
|
250
|
+
territory: ['US']
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('handles single qualifier with single value', () => {
|
|
255
|
+
const result = parseQualifierDefaults('language=en-US');
|
|
256
|
+
expect(result).toEqual({
|
|
257
|
+
language: ['en-US']
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('handles single qualifier with multiple values', () => {
|
|
262
|
+
const result = parseQualifierDefaults('language=en-US,en-CA,fr-CA');
|
|
263
|
+
expect(result).toEqual({
|
|
264
|
+
language: ['en-US', 'en-CA', 'fr-CA']
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('trims whitespace from keys and values', () => {
|
|
269
|
+
const result = parseQualifierDefaults(' language = en-US , en-CA | territory = US ');
|
|
270
|
+
expect(result).toEqual({
|
|
271
|
+
language: ['en-US', 'en-CA'],
|
|
272
|
+
territory: ['US']
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('handles empty string', () => {
|
|
277
|
+
const result = parseQualifierDefaults('');
|
|
278
|
+
expect(result).toEqual({});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('ignores tokens without equals sign', () => {
|
|
282
|
+
const result = parseQualifierDefaults('language=en-US|invalidtoken|territory=US');
|
|
283
|
+
expect(result).toEqual({
|
|
284
|
+
language: ['en-US'],
|
|
285
|
+
territory: ['US']
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('ignores tokens with missing key', () => {
|
|
290
|
+
const result = parseQualifierDefaults('=en-US,en-CA|territory=US');
|
|
291
|
+
expect(result).toEqual({
|
|
292
|
+
territory: ['US']
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('ignores tokens with missing value', () => {
|
|
297
|
+
const result = parseQualifierDefaults('language=|territory=US');
|
|
298
|
+
expect(result).toEqual({
|
|
299
|
+
territory: ['US']
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('handles complex qualifier combinations', () => {
|
|
304
|
+
const result = parseQualifierDefaults('language=en-US,en-CA,fr-CA|territory=US,CA|currency=USD,CAD');
|
|
305
|
+
expect(result).toEqual({
|
|
306
|
+
language: ['en-US', 'en-CA', 'fr-CA'],
|
|
307
|
+
territory: ['US', 'CA'],
|
|
308
|
+
currency: ['USD', 'CAD']
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('handles empty values in comma-separated lists', () => {
|
|
313
|
+
const result = parseQualifierDefaults('language=en-US,,en-CA|territory=,US,');
|
|
314
|
+
expect(result).toEqual({
|
|
315
|
+
language: ['en-US', '', 'en-CA'],
|
|
316
|
+
territory: ['', 'US', '']
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('parseResourceTypes', () => {
|
|
322
|
+
test('parses comma-separated resource types', () => {
|
|
323
|
+
const result = parseResourceTypes('json,string');
|
|
324
|
+
expect(result).toEqual(['json', 'string']);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('handles single resource type', () => {
|
|
328
|
+
const result = parseResourceTypes('json');
|
|
329
|
+
expect(result).toEqual(['json']);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('trims whitespace from types', () => {
|
|
333
|
+
const result = parseResourceTypes(' json , string , object ');
|
|
334
|
+
expect(result).toEqual(['json', 'string', 'object']);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('filters out empty types', () => {
|
|
338
|
+
const result = parseResourceTypes('json,,string,');
|
|
339
|
+
expect(result).toEqual(['json', 'string']);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('handles empty string', () => {
|
|
343
|
+
const result = parseResourceTypes('');
|
|
344
|
+
expect(result).toEqual([]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('handles only commas and whitespace', () => {
|
|
348
|
+
const result = parseResourceTypes(' , , ');
|
|
349
|
+
expect(result).toEqual([]);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('handles multiple resource types with various spacing', () => {
|
|
353
|
+
const result = parseResourceTypes('json, string,object , array, number');
|
|
354
|
+
expect(result).toEqual(['json', 'string', 'object', 'array', 'number']);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe('extractDirectoryPath', () => {
|
|
359
|
+
test('extracts directory from file path', () => {
|
|
360
|
+
expect(extractDirectoryPath('/path/to/file.json')).toBe('/path/to');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('returns directory path as-is', () => {
|
|
364
|
+
expect(extractDirectoryPath('/path/to/directory')).toBe('/path/to/directory');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test('handles root file path', () => {
|
|
368
|
+
expect(extractDirectoryPath('/file.json')).toBe('/');
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('handles root directory', () => {
|
|
372
|
+
expect(extractDirectoryPath('/')).toBe('/');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test('handles empty path', () => {
|
|
376
|
+
expect(extractDirectoryPath('')).toBe('');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test('handles relative file paths', () => {
|
|
380
|
+
expect(extractDirectoryPath('file.json')).toBe('/');
|
|
381
|
+
expect(extractDirectoryPath('dir/file.json')).toBe('dir');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('handles relative directory paths', () => {
|
|
385
|
+
expect(extractDirectoryPath('directory')).toBe('directory');
|
|
386
|
+
expect(extractDirectoryPath('path/to/directory')).toBe('path/to/directory');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('normalizes backslashes to forward slashes', () => {
|
|
390
|
+
expect(extractDirectoryPath('C:\\path\\to\\file.json')).toBe('C:/path/to');
|
|
391
|
+
expect(extractDirectoryPath('path\\file.json')).toBe('path');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test('handles mixed separators', () => {
|
|
395
|
+
expect(extractDirectoryPath('C:\\path/to\\file.json')).toBe('C:/path/to');
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('handles hidden files (starting with dot)', () => {
|
|
399
|
+
expect(extractDirectoryPath('/path/to/.hidden')).toBe('/path/to/.hidden');
|
|
400
|
+
expect(extractDirectoryPath('.hidden')).toBe('.hidden');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test('handles files with multiple dots', () => {
|
|
404
|
+
expect(extractDirectoryPath('/path/to/file.min.js')).toBe('/path/to');
|
|
405
|
+
expect(extractDirectoryPath('file.backup.json')).toBe('/');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('handles directories with dots in name', () => {
|
|
409
|
+
expect(extractDirectoryPath('/path/to/version.1.0')).toBe('/path/to');
|
|
410
|
+
expect(extractDirectoryPath('node_modules')).toBe('node_modules');
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe('isFilePath', () => {
|
|
415
|
+
test('identifies file paths with extensions', () => {
|
|
416
|
+
expect(isFilePath('file.json')).toBe(true);
|
|
417
|
+
expect(isFilePath('/path/to/file.json')).toBe(true);
|
|
418
|
+
expect(isFilePath('C:\\path\\file.txt')).toBe(true);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('identifies directory paths without extensions', () => {
|
|
422
|
+
expect(isFilePath('directory')).toBe(false);
|
|
423
|
+
expect(isFilePath('/path/to/directory')).toBe(false);
|
|
424
|
+
expect(isFilePath('C:\\path\\to\\directory')).toBe(false);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('handles empty path', () => {
|
|
428
|
+
expect(isFilePath('')).toBe(false);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test('handles root path', () => {
|
|
432
|
+
expect(isFilePath('/')).toBe(false);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('handles hidden files and directories', () => {
|
|
436
|
+
expect(isFilePath('.hidden')).toBe(false);
|
|
437
|
+
expect(isFilePath('.hiddendir')).toBe(false);
|
|
438
|
+
expect(isFilePath('/path/.hidden')).toBe(false);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test('handles files with multiple extensions', () => {
|
|
442
|
+
expect(isFilePath('file.min.js')).toBe(true);
|
|
443
|
+
expect(isFilePath('archive.tar.gz')).toBe(true);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
test('handles special file names', () => {
|
|
447
|
+
expect(isFilePath('Makefile')).toBe(false);
|
|
448
|
+
expect(isFilePath('README')).toBe(false);
|
|
449
|
+
expect(isFilePath('package.json')).toBe(true);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test('handles paths with mixed separators', () => {
|
|
453
|
+
expect(isFilePath('C:\\path/file.json')).toBe(true);
|
|
454
|
+
expect(isFilePath('path\\to/directory')).toBe(false);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test('handles edge cases with dots', () => {
|
|
458
|
+
expect(isFilePath('.')).toBe(false);
|
|
459
|
+
expect(isFilePath('..')).toBe(false);
|
|
460
|
+
expect(isFilePath('/path/.')).toBe(false);
|
|
461
|
+
expect(isFilePath('/path/..')).toBe(false);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Test utilities for mocking browser APIs
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Mock file data structure
|
|
29
|
+
*/
|
|
30
|
+
export interface MockFileData {
|
|
31
|
+
name: string;
|
|
32
|
+
content: string;
|
|
33
|
+
type?: string;
|
|
34
|
+
lastModified?: number;
|
|
35
|
+
webkitRelativePath?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a mock File object with all necessary properties and methods
|
|
40
|
+
*/
|
|
41
|
+
export function createMockFile(data: MockFileData): File {
|
|
42
|
+
const blob = new Blob([data.content], { type: data.type || 'text/plain' });
|
|
43
|
+
const file = new File([blob], data.name, {
|
|
44
|
+
type: data.type || 'text/plain',
|
|
45
|
+
lastModified: data.lastModified || Date.now()
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Add webkitRelativePath if provided (for directory uploads)
|
|
49
|
+
if (data.webkitRelativePath) {
|
|
50
|
+
Object.defineProperty(file, 'webkitRelativePath', {
|
|
51
|
+
value: data.webkitRelativePath,
|
|
52
|
+
writable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Ensure text() method works properly
|
|
58
|
+
if (!file.text || typeof file.text !== 'function') {
|
|
59
|
+
Object.defineProperty(file, 'text', {
|
|
60
|
+
value: () => Promise.resolve(data.content),
|
|
61
|
+
writable: false,
|
|
62
|
+
configurable: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return file;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create a mock FileList using DataTransfer API
|
|
71
|
+
* This is the most reliable method for creating FileList objects in tests
|
|
72
|
+
*/
|
|
73
|
+
export function createMockFileList(files: MockFileData[]): FileList {
|
|
74
|
+
// Use DataTransfer to create a proper FileList
|
|
75
|
+
const dt = new DataTransfer();
|
|
76
|
+
|
|
77
|
+
files.forEach((fileData) => {
|
|
78
|
+
const file = createMockFile(fileData);
|
|
79
|
+
dt.items.add(file);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return dt.files;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create a mock FileList for directory upload simulation
|
|
87
|
+
* Includes webkitRelativePath for each file
|
|
88
|
+
*/
|
|
89
|
+
export function createMockDirectoryFileList(
|
|
90
|
+
directoryStructure: Array<{ path: string; content: string; type?: string }>
|
|
91
|
+
): FileList {
|
|
92
|
+
const files = directoryStructure.map((item) => ({
|
|
93
|
+
name: item.path.split('/').pop() || '',
|
|
94
|
+
content: item.content,
|
|
95
|
+
type: item.type,
|
|
96
|
+
webkitRelativePath: item.path
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
return createMockFileList(files);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Helper to create a promise that resolves after a delay
|
|
104
|
+
* Useful for testing async operations
|
|
105
|
+
*/
|
|
106
|
+
export function delay(ms: number): Promise<void> {
|
|
107
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Helper to verify File API text() method works correctly
|
|
112
|
+
* Since we're using Blob/File polyfills, this ensures they have the right methods
|
|
113
|
+
*/
|
|
114
|
+
export async function verifyFileAPI(file: File): Promise<boolean> {
|
|
115
|
+
try {
|
|
116
|
+
// Check if text() method exists and works
|
|
117
|
+
if (typeof file.text !== 'function') {
|
|
118
|
+
throw new Error('File.text() method not available');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const text = await file.text();
|
|
122
|
+
return typeof text === 'string';
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Mock Web Crypto digest result for testing
|
|
130
|
+
* Creates a deterministic hash-like ArrayBuffer
|
|
131
|
+
*/
|
|
132
|
+
export function createMockDigest(input: string, algorithm: string = 'SHA-256'): ArrayBuffer {
|
|
133
|
+
// Create a deterministic "hash" based on input for testing
|
|
134
|
+
// This is not a real hash but good enough for testing
|
|
135
|
+
const hashLength = algorithm.includes('256') ? 32 : algorithm.includes('512') ? 64 : 20;
|
|
136
|
+
const buffer = new ArrayBuffer(hashLength);
|
|
137
|
+
const view = new Uint8Array(buffer);
|
|
138
|
+
|
|
139
|
+
// Fill with deterministic values based on input
|
|
140
|
+
for (let i = 0; i < hashLength; i++) {
|
|
141
|
+
view[i] = (input.charCodeAt(i % input.length) + i) % 256;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return buffer;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Convert ArrayBuffer to hex string for comparison in tests
|
|
149
|
+
*/
|
|
150
|
+
export function arrayBufferToHex(buffer: ArrayBuffer): string {
|
|
151
|
+
const view = new Uint8Array(buffer);
|
|
152
|
+
return Array.from(view)
|
|
153
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
154
|
+
.join('');
|
|
155
|
+
}
|