@scality/data-browser-library 1.0.0-preview.11

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.
Files changed (256) hide show
  1. package/dist/components/Editor.d.ts +12 -0
  2. package/dist/components/Editor.js +28 -0
  3. package/dist/components/__tests__/BucketCreate.test.d.ts +1 -0
  4. package/dist/components/__tests__/BucketCreate.test.js +408 -0
  5. package/dist/components/__tests__/BucketLifecycleFormPage.test.d.ts +1 -0
  6. package/dist/components/__tests__/BucketLifecycleFormPage.test.js +618 -0
  7. package/dist/components/__tests__/BucketLifecycleList.test.d.ts +1 -0
  8. package/dist/components/__tests__/BucketLifecycleList.test.js +325 -0
  9. package/dist/components/__tests__/BucketList.test.d.ts +1 -0
  10. package/dist/components/__tests__/BucketList.test.js +415 -0
  11. package/dist/components/__tests__/BucketNotificationCreatePage.test.d.ts +1 -0
  12. package/dist/components/__tests__/BucketNotificationCreatePage.test.js +316 -0
  13. package/dist/components/__tests__/BucketOverview.test.d.ts +1 -0
  14. package/dist/components/__tests__/BucketOverview.test.js +769 -0
  15. package/dist/components/__tests__/BucketPolicyPage.test.d.ts +1 -0
  16. package/dist/components/__tests__/BucketPolicyPage.test.js +268 -0
  17. package/dist/components/__tests__/BucketReplicationFormPage.test.d.ts +1 -0
  18. package/dist/components/__tests__/BucketReplicationFormPage.test.js +1757 -0
  19. package/dist/components/__tests__/BucketReplicationList.test.d.ts +1 -0
  20. package/dist/components/__tests__/BucketReplicationList.test.js +344 -0
  21. package/dist/components/__tests__/CreateFolderButton.test.d.ts +1 -0
  22. package/dist/components/__tests__/CreateFolderButton.test.js +147 -0
  23. package/dist/components/__tests__/DeleteBucketButton.test.d.ts +1 -0
  24. package/dist/components/__tests__/DeleteBucketButton.test.js +272 -0
  25. package/dist/components/__tests__/DeleteBucketConfigRuleButton.test.d.ts +1 -0
  26. package/dist/components/__tests__/DeleteBucketConfigRuleButton.test.js +196 -0
  27. package/dist/components/__tests__/DeleteObjectButton.test.d.ts +1 -0
  28. package/dist/components/__tests__/DeleteObjectButton.test.js +302 -0
  29. package/dist/components/__tests__/EmptyBucketButton.test.d.ts +1 -0
  30. package/dist/components/__tests__/EmptyBucketButton.test.js +302 -0
  31. package/dist/components/__tests__/MetadataSearch.test.d.ts +1 -0
  32. package/dist/components/__tests__/MetadataSearch.test.js +201 -0
  33. package/dist/components/__tests__/ObjectList.test.d.ts +1 -0
  34. package/dist/components/__tests__/ObjectList.test.js +283 -0
  35. package/dist/components/__tests__/UploadButton.test.d.ts +1 -0
  36. package/dist/components/__tests__/UploadButton.test.js +144 -0
  37. package/dist/components/buckets/BucketCreate.d.ts +49 -0
  38. package/dist/components/buckets/BucketCreate.js +237 -0
  39. package/dist/components/buckets/BucketDetails.d.ts +1 -0
  40. package/dist/components/buckets/BucketDetails.js +106 -0
  41. package/dist/components/buckets/BucketLifecycleFormPage.d.ts +15 -0
  42. package/dist/components/buckets/BucketLifecycleFormPage.js +1085 -0
  43. package/dist/components/buckets/BucketLifecycleList.d.ts +10 -0
  44. package/dist/components/buckets/BucketLifecycleList.js +270 -0
  45. package/dist/components/buckets/BucketList.d.ts +15 -0
  46. package/dist/components/buckets/BucketList.js +146 -0
  47. package/dist/components/buckets/BucketLocation.d.ts +3 -0
  48. package/dist/components/buckets/BucketLocation.js +16 -0
  49. package/dist/components/buckets/BucketOverview.d.ts +88 -0
  50. package/dist/components/buckets/BucketOverview.js +291 -0
  51. package/dist/components/buckets/BucketPage.d.ts +2 -0
  52. package/dist/components/buckets/BucketPage.js +47 -0
  53. package/dist/components/buckets/BucketPolicyButton.d.ts +7 -0
  54. package/dist/components/buckets/BucketPolicyButton.js +18 -0
  55. package/dist/components/buckets/BucketPolicyPage.d.ts +1 -0
  56. package/dist/components/buckets/BucketPolicyPage.js +236 -0
  57. package/dist/components/buckets/BucketReplicationFormPage.d.ts +1 -0
  58. package/dist/components/buckets/BucketReplicationFormPage.js +834 -0
  59. package/dist/components/buckets/BucketReplicationList.d.ts +11 -0
  60. package/dist/components/buckets/BucketReplicationList.js +189 -0
  61. package/dist/components/buckets/BucketVersioning.d.ts +4 -0
  62. package/dist/components/buckets/BucketVersioning.js +73 -0
  63. package/dist/components/buckets/DeleteBucketButton.d.ts +8 -0
  64. package/dist/components/buckets/DeleteBucketButton.js +78 -0
  65. package/dist/components/buckets/DeleteBucketConfigRuleButton.d.ts +18 -0
  66. package/dist/components/buckets/DeleteBucketConfigRuleButton.js +53 -0
  67. package/dist/components/buckets/EmptyBucketButton.d.ts +5 -0
  68. package/dist/components/buckets/EmptyBucketButton.js +232 -0
  69. package/dist/components/buckets/EmptyBucketSummary.d.ts +9 -0
  70. package/dist/components/buckets/EmptyBucketSummary.js +60 -0
  71. package/dist/components/buckets/EmptyBucketSummaryList.d.ts +13 -0
  72. package/dist/components/buckets/EmptyBucketSummaryList.js +140 -0
  73. package/dist/components/buckets/__tests__/BucketVersioning.test.d.ts +1 -0
  74. package/dist/components/buckets/__tests__/BucketVersioning.test.js +163 -0
  75. package/dist/components/buckets/notifications/BucketNotificationCreatePage.d.ts +1 -0
  76. package/dist/components/buckets/notifications/BucketNotificationCreatePage.js +234 -0
  77. package/dist/components/buckets/notifications/EventsSection.d.ts +1 -0
  78. package/dist/components/buckets/notifications/EventsSection.js +123 -0
  79. package/dist/components/buckets/notifications/events.d.ts +12 -0
  80. package/dist/components/buckets/notifications/events.js +27 -0
  81. package/dist/components/index.d.ts +21 -0
  82. package/dist/components/index.js +22 -0
  83. package/dist/components/layouts/ArrowNavigation.d.ts +4 -0
  84. package/dist/components/layouts/ArrowNavigation.js +16 -0
  85. package/dist/components/layouts/BrowserPageLayout.d.ts +12 -0
  86. package/dist/components/layouts/BrowserPageLayout.js +51 -0
  87. package/dist/components/objects/CreateFolderButton.d.ts +29 -0
  88. package/dist/components/objects/CreateFolderButton.js +118 -0
  89. package/dist/components/objects/DeleteObjectButton.d.ts +8 -0
  90. package/dist/components/objects/DeleteObjectButton.js +191 -0
  91. package/dist/components/objects/ObjectDetails/ObjectMetadata.d.ts +2 -0
  92. package/dist/components/objects/ObjectDetails/ObjectMetadata.js +356 -0
  93. package/dist/components/objects/ObjectDetails/ObjectSummary.d.ts +3 -0
  94. package/dist/components/objects/ObjectDetails/ObjectSummary.js +241 -0
  95. package/dist/components/objects/ObjectDetails/ObjectTags.d.ts +3 -0
  96. package/dist/components/objects/ObjectDetails/ObjectTags.js +272 -0
  97. package/dist/components/objects/ObjectDetails/index.d.ts +9 -0
  98. package/dist/components/objects/ObjectDetails/index.js +75 -0
  99. package/dist/components/objects/ObjectList.d.ts +40 -0
  100. package/dist/components/objects/ObjectList.js +453 -0
  101. package/dist/components/objects/ObjectLock/EditRetentionButton.d.ts +4 -0
  102. package/dist/components/objects/ObjectLock/EditRetentionButton.js +32 -0
  103. package/dist/components/objects/ObjectLock/ObjectLockRetentionSettings.d.ts +3 -0
  104. package/dist/components/objects/ObjectLock/ObjectLockRetentionSettings.js +211 -0
  105. package/dist/components/objects/ObjectLock/ObjectLockSettings.d.ts +9 -0
  106. package/dist/components/objects/ObjectLock/ObjectLockSettings.js +158 -0
  107. package/dist/components/objects/ObjectLock/ObjectLockSettingsUtils.d.ts +8 -0
  108. package/dist/components/objects/ObjectLock/ObjectLockSettingsUtils.js +39 -0
  109. package/dist/components/objects/ObjectLock/__tests__/EditRetentionButton.test.d.ts +1 -0
  110. package/dist/components/objects/ObjectLock/__tests__/EditRetentionButton.test.js +204 -0
  111. package/dist/components/objects/ObjectLock/__tests__/ObjectLockSettings.test.d.ts +1 -0
  112. package/dist/components/objects/ObjectLock/__tests__/ObjectLockSettings.test.js +374 -0
  113. package/dist/components/objects/ObjectPage.d.ts +1 -0
  114. package/dist/components/objects/ObjectPage.js +45 -0
  115. package/dist/components/objects/UploadButton.d.ts +34 -0
  116. package/dist/components/objects/UploadButton.js +229 -0
  117. package/dist/components/providers/DataBrowserProvider.d.ts +20 -0
  118. package/dist/components/providers/DataBrowserProvider.js +42 -0
  119. package/dist/components/search/MetadataSearch.d.ts +5 -0
  120. package/dist/components/search/MetadataSearch.js +162 -0
  121. package/dist/components/search/SearchHints.d.ts +8 -0
  122. package/dist/components/search/SearchHints.js +21 -0
  123. package/dist/components/ui/ArrayFieldActions.d.ts +36 -0
  124. package/dist/components/ui/ArrayFieldActions.js +43 -0
  125. package/dist/components/ui/ConfirmDeleteRuleModal.d.ts +16 -0
  126. package/dist/components/ui/ConfirmDeleteRuleModal.js +43 -0
  127. package/dist/components/ui/DeleteObjectModalContent.d.ts +5 -0
  128. package/dist/components/ui/DeleteObjectModalContent.js +71 -0
  129. package/dist/components/ui/FilterFormSection.d.ts +44 -0
  130. package/dist/components/ui/FilterFormSection.js +159 -0
  131. package/dist/components/ui/Search.elements.d.ts +17 -0
  132. package/dist/components/ui/Search.elements.js +59 -0
  133. package/dist/components/ui/Table.elements.d.ts +36 -0
  134. package/dist/components/ui/Table.elements.js +87 -0
  135. package/dist/config/factory.d.ts +63 -0
  136. package/dist/config/factory.js +74 -0
  137. package/dist/config/types.d.ts +46 -0
  138. package/dist/config/types.js +0 -0
  139. package/dist/hooks/__tests__/useISVBucketDetection.test.d.ts +1 -0
  140. package/dist/hooks/__tests__/useISVBucketDetection.test.js +188 -0
  141. package/dist/hooks/__tests__/useIsBucketEmpty.test.d.ts +1 -0
  142. package/dist/hooks/__tests__/useIsBucketEmpty.test.js +122 -0
  143. package/dist/hooks/bucketConfiguration.d.ts +168 -0
  144. package/dist/hooks/bucketConfiguration.js +67 -0
  145. package/dist/hooks/bucketOperations.d.ts +36 -0
  146. package/dist/hooks/bucketOperations.js +12 -0
  147. package/dist/hooks/factories/__tests__/useCreateS3FunctionMutationHook.test.d.ts +1 -0
  148. package/dist/hooks/factories/__tests__/useCreateS3FunctionMutationHook.test.js +276 -0
  149. package/dist/hooks/factories/__tests__/useCreateS3InfiniteQueryHook.test.d.ts +1 -0
  150. package/dist/hooks/factories/__tests__/useCreateS3InfiniteQueryHook.test.js +259 -0
  151. package/dist/hooks/factories/__tests__/useCreateS3LoginHook.test.d.ts +1 -0
  152. package/dist/hooks/factories/__tests__/useCreateS3LoginHook.test.js +166 -0
  153. package/dist/hooks/factories/__tests__/useCreateS3MutationHook.test.d.ts +1 -0
  154. package/dist/hooks/factories/__tests__/useCreateS3MutationHook.test.js +200 -0
  155. package/dist/hooks/factories/__tests__/useCreateS3QueryHook.test.d.ts +1 -0
  156. package/dist/hooks/factories/__tests__/useCreateS3QueryHook.test.js +179 -0
  157. package/dist/hooks/factories/index.d.ts +18 -0
  158. package/dist/hooks/factories/index.js +5 -0
  159. package/dist/hooks/factories/useCreateS3InfiniteQueryHook.d.ts +13 -0
  160. package/dist/hooks/factories/useCreateS3InfiniteQueryHook.js +76 -0
  161. package/dist/hooks/factories/useCreateS3LoginHook.d.ts +8 -0
  162. package/dist/hooks/factories/useCreateS3LoginHook.js +22 -0
  163. package/dist/hooks/factories/useCreateS3MutationHook.d.ts +5 -0
  164. package/dist/hooks/factories/useCreateS3MutationHook.js +50 -0
  165. package/dist/hooks/factories/useCreateS3QueryHook.d.ts +3 -0
  166. package/dist/hooks/factories/useCreateS3QueryHook.js +51 -0
  167. package/dist/hooks/index.d.ts +13 -0
  168. package/dist/hooks/index.js +13 -0
  169. package/dist/hooks/loginOperations.d.ts +21 -0
  170. package/dist/hooks/loginOperations.js +9 -0
  171. package/dist/hooks/objectOperations.d.ts +190 -0
  172. package/dist/hooks/objectOperations.js +67 -0
  173. package/dist/hooks/presignedOperations.d.ts +73 -0
  174. package/dist/hooks/presignedOperations.js +72 -0
  175. package/dist/hooks/useBatchObjectLegalHold.d.ts +11 -0
  176. package/dist/hooks/useBatchObjectLegalHold.js +45 -0
  177. package/dist/hooks/useDeleteBucketConfigRule.d.ts +26 -0
  178. package/dist/hooks/useDeleteBucketConfigRule.js +46 -0
  179. package/dist/hooks/useEmptyBucket.d.ts +27 -0
  180. package/dist/hooks/useEmptyBucket.js +116 -0
  181. package/dist/hooks/useISVBucketDetection.d.ts +15 -0
  182. package/dist/hooks/useISVBucketDetection.js +27 -0
  183. package/dist/hooks/useIsBucketEmpty.d.ts +7 -0
  184. package/dist/hooks/useIsBucketEmpty.js +36 -0
  185. package/dist/hooks/useLoginMutation.d.ts +21 -0
  186. package/dist/hooks/useLoginMutation.js +9 -0
  187. package/dist/hooks/useS3Client.d.ts +1 -0
  188. package/dist/hooks/useS3Client.js +13 -0
  189. package/dist/hooks/useTableRowSelection.d.ts +9 -0
  190. package/dist/hooks/useTableRowSelection.js +45 -0
  191. package/dist/index.d.ts +6 -0
  192. package/dist/index.js +6 -0
  193. package/dist/schemas/bucketPolicySchema.json +321 -0
  194. package/dist/test/msw/handlers/deleteBucket.d.ts +1 -0
  195. package/dist/test/msw/handlers/deleteBucket.js +14 -0
  196. package/dist/test/msw/handlers/getBucketAcl.d.ts +1 -0
  197. package/dist/test/msw/handlers/getBucketAcl.js +96 -0
  198. package/dist/test/msw/handlers/getBucketLocation.d.ts +1 -0
  199. package/dist/test/msw/handlers/getBucketLocation.js +23 -0
  200. package/dist/test/msw/handlers/getBucketPolicy.d.ts +11 -0
  201. package/dist/test/msw/handlers/getBucketPolicy.js +72 -0
  202. package/dist/test/msw/handlers/headObject.d.ts +1 -0
  203. package/dist/test/msw/handlers/headObject.js +17 -0
  204. package/dist/test/msw/handlers/listBuckets.d.ts +1 -0
  205. package/dist/test/msw/handlers/listBuckets.js +24 -0
  206. package/dist/test/msw/handlers/listObjectVersions.d.ts +1 -0
  207. package/dist/test/msw/handlers/listObjectVersions.js +83 -0
  208. package/dist/test/msw/handlers/listObjects.d.ts +1 -0
  209. package/dist/test/msw/handlers/listObjects.js +66 -0
  210. package/dist/test/msw/handlers/objectLegalHold.d.ts +1 -0
  211. package/dist/test/msw/handlers/objectLegalHold.js +24 -0
  212. package/dist/test/msw/handlers/objectRetention.d.ts +1 -0
  213. package/dist/test/msw/handlers/objectRetention.js +27 -0
  214. package/dist/test/msw/handlers/putBucketAcl.d.ts +1 -0
  215. package/dist/test/msw/handlers/putBucketAcl.js +18 -0
  216. package/dist/test/msw/handlers/putObject.d.ts +1 -0
  217. package/dist/test/msw/handlers/putObject.js +16 -0
  218. package/dist/test/msw/handlers.d.ts +4 -0
  219. package/dist/test/msw/handlers.js +109 -0
  220. package/dist/test/msw/index.d.ts +2 -0
  221. package/dist/test/msw/index.js +3 -0
  222. package/dist/test/msw/server.d.ts +4 -0
  223. package/dist/test/msw/server.js +20 -0
  224. package/dist/test/msw/utils.d.ts +2 -0
  225. package/dist/test/msw/utils.js +13 -0
  226. package/dist/test/setup.d.ts +1 -0
  227. package/dist/test/setup.js +90 -0
  228. package/dist/test/testUtils.d.ts +181 -0
  229. package/dist/test/testUtils.js +310 -0
  230. package/dist/test/utils/errorHandling.test.d.ts +1 -0
  231. package/dist/test/utils/errorHandling.test.js +423 -0
  232. package/dist/types/index.d.ts +51 -0
  233. package/dist/types/index.js +0 -0
  234. package/dist/utils/constants.d.ts +12 -0
  235. package/dist/utils/constants.js +9 -0
  236. package/dist/utils/deletion/index.d.ts +2 -0
  237. package/dist/utils/deletion/index.js +2 -0
  238. package/dist/utils/deletion/messages.d.ts +5 -0
  239. package/dist/utils/deletion/messages.js +29 -0
  240. package/dist/utils/deletion/types.d.ts +11 -0
  241. package/dist/utils/deletion/types.js +0 -0
  242. package/dist/utils/errorHandling.d.ts +63 -0
  243. package/dist/utils/errorHandling.js +84 -0
  244. package/dist/utils/hooks.d.ts +2 -0
  245. package/dist/utils/hooks.js +26 -0
  246. package/dist/utils/index.d.ts +4 -0
  247. package/dist/utils/index.js +4 -0
  248. package/dist/utils/proxyMiddleware.d.ts +18 -0
  249. package/dist/utils/proxyMiddleware.js +56 -0
  250. package/dist/utils/s3Client.d.ts +5 -0
  251. package/dist/utils/s3Client.js +36 -0
  252. package/dist/utils/s3RuleUtils.d.ts +53 -0
  253. package/dist/utils/s3RuleUtils.js +101 -0
  254. package/dist/utils/useFeatures.d.ts +1 -0
  255. package/dist/utils/useFeatures.js +7 -0
  256. package/package.json +84 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @fileoverview Test utilities for data-browser-library
3
+ *
4
+ * This file provides common utilities for testing:
5
+ * - Test configuration and credentials
6
+ * - Mock setup utilities (S3, DOM, etc.)
7
+ * - React Testing Library wrappers
8
+ * - React Query wrappers
9
+ * - Global configuration utilities
10
+ * - Factory pattern validation utilities
11
+ * - Form testing helpers
12
+ */
13
+ import React from "react";
14
+ import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
15
+ import { UseQueryResult } from "@tanstack/react-query";
16
+ import { S3BrowserConfig, S3Credentials } from "../types";
17
+ import type { S3Configuration, DevelopmentConfiguration } from "../config/types";
18
+ /**
19
+ * Default S3 configuration for tests
20
+ */
21
+ export declare const testConfig: S3BrowserConfig;
22
+ /**
23
+ * Default S3 credentials for tests
24
+ */
25
+ export declare const testCredentials: S3Credentials;
26
+ /**
27
+ * Mock S3 client for tests
28
+ */
29
+ export declare const mockS3Client: {
30
+ send: jest.Mock<any, any, any>;
31
+ };
32
+ export declare const MockedS3Client: jest.MockedClass<typeof S3Client>;
33
+ export declare const MockedPutObjectCommand: jest.MockedClass<typeof PutObjectCommand>;
34
+ /**
35
+ * Sets up S3 mocks for testing
36
+ */
37
+ export declare const setupS3Mocks: () => void;
38
+ /**
39
+ * Common mock setup that should be run before each test
40
+ */
41
+ export declare const setupCommonMocks: () => void;
42
+ /**
43
+ * Mocks DOM measurements APIs for virtualization and layout testing
44
+ * AutoSizer uses offsetWidth and offsetHeight which Jest/JSDom doesn't support
45
+ * @param width - The mock width in pixels
46
+ * @param height - The mock height in pixels
47
+ */
48
+ export declare function mockOffsetSize(width: number, height: number): void;
49
+ /**
50
+ * Creates a simple QueryClient wrapper for tests that don't need DataBrowser context
51
+ */
52
+ export declare const createQueryWrapper: () => ({ children }: {
53
+ children: React.ReactNode;
54
+ }) => import("react/jsx-runtime").JSX.Element;
55
+ /**
56
+ * Creates a test wrapper with DataBrowser context and QueryClient
57
+ */
58
+ export declare const createTestWrapper: (config?: S3BrowserConfig, credentials?: S3Credentials) => ({ children }: {
59
+ children: React.ReactNode;
60
+ }) => import("react/jsx-runtime").JSX.Element;
61
+ /**
62
+ * Renders a hook with the standard test wrapper
63
+ */
64
+ export declare const renderHookWithWrapper: <TProps, TResult>(hook: (props: TProps) => TResult, options?: {
65
+ initialProps?: TProps;
66
+ config?: S3BrowserConfig;
67
+ credentials?: S3Credentials;
68
+ }) => import("@testing-library/react").RenderHookResult<TResult, TProps>;
69
+ /**
70
+ * Creates a test File object
71
+ */
72
+ export declare const createTestFile: (name: string, content: string, type?: string) => File;
73
+ type GlobalConfigOverrides = {
74
+ s3?: Partial<S3Configuration>;
75
+ dev?: Partial<DevelopmentConfiguration>;
76
+ environment?: {
77
+ isDevelopment?: boolean;
78
+ isProduction?: boolean;
79
+ };
80
+ };
81
+ /**
82
+ * Override global configuration for testing specific scenarios
83
+ * Useful for testing different deployment environments or proxy configurations
84
+ */
85
+ export declare const overrideGlobalConfig: (overrides: GlobalConfigOverrides) => void;
86
+ /**
87
+ * Reset global configuration to test defaults
88
+ * Should be called in afterEach or afterAll to ensure test isolation
89
+ */
90
+ export declare const resetGlobalConfig: () => void;
91
+ /**
92
+ * Test helper for running tests with specific global configuration
93
+ */
94
+ export declare const withGlobalConfig: (overrides: GlobalConfigOverrides, testFn: () => void | Promise<void>) => () => Promise<void>;
95
+ /**
96
+ * Creates a factory test error
97
+ */
98
+ export declare const createFactoryTestError: (testContext: string, operationName: string, details?: string) => Error;
99
+ /**
100
+ * Validates that a hook follows the expected factory pattern
101
+ */
102
+ export declare const validateFactoryHook: (hook: any, operationName: string) => void;
103
+ /**
104
+ * Validates that a hook result has expected React Query properties
105
+ */
106
+ export declare const validateHookResult: (result: any, hookType: "query" | "mutation" | "infiniteQuery") => void;
107
+ /**
108
+ * Creates a mock UseMutationResult for testing React Query mutations
109
+ *
110
+ * This helper provides a complete mock object that matches the UseMutationResult type
111
+ * from @tanstack/react-query, eliminating the need for 'as any' type assertions.
112
+ *
113
+ * @param mutate - The mocked mutate function (usually jest.fn())
114
+ * @param overrides - Optional overrides for any properties (e.g., { isPending: true })
115
+ * @returns A complete UseMutationResult mock object
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const mockCreateBucket = jest.fn();
120
+ * const mockResult = createMockMutationResult(mockCreateBucket, { isPending: true });
121
+ * mockUseCreateBucket.mockReturnValue(mockResult);
122
+ * ```
123
+ */
124
+ export declare const createMockMutationResult: (mutate: jest.Mock, overrides?: {}) => {
125
+ mutate: jest.Mock<any, any, any>;
126
+ mutateAsync: jest.Mock<any, any, any>;
127
+ reset: jest.Mock<any, any, any>;
128
+ isPending: false;
129
+ isIdle: true;
130
+ isError: false;
131
+ isSuccess: false;
132
+ status: "idle";
133
+ data: undefined;
134
+ error: null;
135
+ variables: undefined;
136
+ context: undefined;
137
+ failureCount: number;
138
+ failureReason: null;
139
+ isPaused: false;
140
+ submittedAt: number;
141
+ };
142
+ /**
143
+ * Creates a mock UseQueryResult for testing React Query queries
144
+ *
145
+ * This helper provides a complete mock object that matches the UseQueryResult type
146
+ * from @tanstack/react-query, eliminating the need for 'as any' type assertions.
147
+ *
148
+ * @param overrides - Optional overrides for any properties (e.g., { isLoading: true, data: mockData })
149
+ * @returns A complete UseQueryResult mock object
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * const mockQueryResult = createMockQueryResult({ isLoading: true });
154
+ * mockUseGetBucketPolicy.mockReturnValue(mockQueryResult);
155
+ * ```
156
+ */
157
+ export declare const createMockQueryResult: <T, E = Error>(overrides?: Partial<UseQueryResult<T, E>>) => UseQueryResult<T, E>;
158
+ /**
159
+ * Finds a Toggle input element by its label text
160
+ * Traverses the DOM to locate the associated checkbox input
161
+ * @param labelText - The text content of the label
162
+ * @returns The toggle input element or null if not found
163
+ */
164
+ export declare const findToggleByLabel: (labelText: string) => HTMLInputElement | null;
165
+ /**
166
+ * Waits for a submit button to be enabled and clicks it
167
+ * @param buttonName - The type of button to click ("create" or "save")
168
+ */
169
+ export declare const submitForm: (buttonName?: "create" | "save") => Promise<void>;
170
+ /**
171
+ * Sets up a mock mutation to simulate successful form submission
172
+ * @param mockMutate - The jest mock function for the mutation
173
+ */
174
+ export declare const mockSuccessSubmit: (mockMutate: jest.Mock) => void;
175
+ /**
176
+ * Sets up a mock mutation to simulate failed form submission
177
+ * @param mockMutate - The jest mock function for the mutation
178
+ * @param errorMessage - The error message to return (default: "Network Error")
179
+ */
180
+ export declare const mockErrorSubmit: (mockMutate: jest.Mock, errorMessage?: string) => void;
181
+ export { setupMswServer, overrideHandlers } from "./msw";
@@ -0,0 +1,310 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
4
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
+ import { fireEvent, renderHook, screen, waitFor } from "@testing-library/react";
6
+ import { coreUIAvailableThemes } from "@scality/core-ui/dist/style/theme";
7
+ import { CoreUiThemeProvider } from "@scality/core-ui/dist/next";
8
+ import { ToastProvider } from "@scality/core-ui";
9
+ import { DataBrowserProvider } from "../components/providers/DataBrowserProvider.js";
10
+ import { overrideHandlers, setupMswServer } from "./msw/index.js";
11
+ var __webpack_require__ = {};
12
+ (()=>{
13
+ __webpack_require__.g = (()=>{
14
+ if ('object' == typeof globalThis) return globalThis;
15
+ try {
16
+ return this || new Function('return this')();
17
+ } catch (e) {
18
+ if ('object' == typeof window) return window;
19
+ }
20
+ })();
21
+ })();
22
+ const testConfig = {
23
+ endpoint: "https://s3.amazonaws.com",
24
+ region: "us-east-1",
25
+ forcePathStyle: true
26
+ };
27
+ const testCredentials = {
28
+ accessKeyId: "test-access-key",
29
+ secretAccessKey: "test-secret-key",
30
+ sessionToken: "test-session-token"
31
+ };
32
+ const mockS3Client = {
33
+ send: jest.fn()
34
+ };
35
+ const MockedS3Client = S3Client;
36
+ const MockedPutObjectCommand = PutObjectCommand;
37
+ const setupS3Mocks = ()=>{
38
+ jest.clearAllMocks();
39
+ MockedS3Client.mockImplementation(()=>mockS3Client);
40
+ MockedPutObjectCommand.mockImplementation((input)=>({
41
+ input,
42
+ resolveMiddleware: jest.fn()
43
+ }));
44
+ };
45
+ const setupCommonMocks = ()=>{
46
+ setupS3Mocks();
47
+ };
48
+ function mockOffsetSize(width, height) {
49
+ __webpack_require__.g.ResizeObserver = jest.fn().mockImplementation(()=>({
50
+ observe: jest.fn(),
51
+ unobserve: jest.fn(),
52
+ disconnect: jest.fn()
53
+ }));
54
+ Element.prototype.getBoundingClientRect = jest.fn(()=>({
55
+ width: width || 800,
56
+ height: height || 600,
57
+ top: 0,
58
+ left: 0,
59
+ bottom: height || 600,
60
+ right: width || 800,
61
+ x: 0,
62
+ y: 0,
63
+ toJSON: jest.fn()
64
+ }));
65
+ Object.defineProperties(window.HTMLElement.prototype, {
66
+ offsetHeight: {
67
+ get: ()=>height || 600,
68
+ configurable: true
69
+ },
70
+ offsetWidth: {
71
+ get: ()=>width || 800,
72
+ configurable: true
73
+ },
74
+ scrollHeight: {
75
+ get: ()=>height || 600,
76
+ configurable: true
77
+ },
78
+ scrollWidth: {
79
+ get: ()=>width || 800,
80
+ configurable: true
81
+ }
82
+ });
83
+ const mockComputedStyle = {
84
+ fontSize: "14px",
85
+ paddingLeft: "0px",
86
+ paddingRight: "0px",
87
+ paddingTop: "0px",
88
+ paddingBottom: "0px",
89
+ getPropertyValue: jest.fn((prop)=>{
90
+ const styles = {
91
+ "font-size": "14px",
92
+ "padding-left": "0px",
93
+ "padding-right": "0px",
94
+ "padding-top": "0px",
95
+ "padding-bottom": "0px"
96
+ };
97
+ return styles[prop] || "";
98
+ })
99
+ };
100
+ jest.spyOn(window, "getComputedStyle").mockImplementation(()=>mockComputedStyle);
101
+ }
102
+ const createQueryWrapper = ()=>{
103
+ const queryClient = new QueryClient({
104
+ defaultOptions: {
105
+ queries: {
106
+ retry: false
107
+ },
108
+ mutations: {
109
+ retry: false
110
+ }
111
+ }
112
+ });
113
+ const theme = coreUIAvailableThemes.darkRebrand;
114
+ return ({ children })=>/*#__PURE__*/ jsx(QueryClientProvider, {
115
+ client: queryClient,
116
+ children: /*#__PURE__*/ jsx(CoreUiThemeProvider, {
117
+ theme: theme,
118
+ children: children
119
+ })
120
+ });
121
+ };
122
+ const createTestWrapper = (config = testConfig, credentials = testCredentials)=>{
123
+ const queryClient = new QueryClient({
124
+ defaultOptions: {
125
+ queries: {
126
+ retry: false
127
+ },
128
+ mutations: {
129
+ retry: false
130
+ }
131
+ }
132
+ });
133
+ const getConfig = ()=>({
134
+ ...config,
135
+ credentials
136
+ });
137
+ const theme = coreUIAvailableThemes.darkRebrand;
138
+ return ({ children })=>/*#__PURE__*/ jsx(DataBrowserProvider, {
139
+ queryClient: queryClient,
140
+ getS3Config: getConfig,
141
+ theme: theme,
142
+ enableDevtools: false,
143
+ children: /*#__PURE__*/ jsx(CoreUiThemeProvider, {
144
+ theme: theme,
145
+ children: /*#__PURE__*/ jsx(ToastProvider, {
146
+ children: children
147
+ })
148
+ })
149
+ });
150
+ };
151
+ const renderHookWithWrapper = (hook, options)=>{
152
+ const { config, credentials, ...renderOptions } = options || {};
153
+ return renderHook(hook, {
154
+ wrapper: createTestWrapper(config, credentials),
155
+ ...renderOptions
156
+ });
157
+ };
158
+ const createTestFile = (name, content, type = "text/plain")=>new File([
159
+ content
160
+ ], name, {
161
+ type
162
+ });
163
+ const overrideGlobalConfig = (overrides)=>{
164
+ const currentS3 = globalThis.__S3_CONFIG__;
165
+ const currentDev = globalThis.__DEV_CONFIG__;
166
+ if (overrides.s3) globalThis.__S3_CONFIG__ = {
167
+ ...currentS3,
168
+ ...overrides.s3
169
+ };
170
+ if (overrides.dev) globalThis.__DEV_CONFIG__ = {
171
+ ...currentDev,
172
+ ...overrides.dev
173
+ };
174
+ if (overrides.environment) {
175
+ if (void 0 !== overrides.environment.isDevelopment) globalThis.__IS_DEVELOPMENT__ = overrides.environment.isDevelopment;
176
+ if (void 0 !== overrides.environment.isProduction) globalThis.__IS_PRODUCTION__ = overrides.environment.isProduction;
177
+ }
178
+ };
179
+ const resetGlobalConfig = ()=>{
180
+ globalThis.__S3_CONFIG__ = {
181
+ endpoint: "http://localhost:8000",
182
+ region: "us-east-1",
183
+ realHost: "s3.amazonaws.com",
184
+ forcePathStyle: true
185
+ };
186
+ globalThis.__DEV_CONFIG__ = {
187
+ useProxy: false,
188
+ proxyEndpoint: "http://localhost:3000/api/s3",
189
+ proxyBasePath: "/api/s3",
190
+ proxyHost: "localhost",
191
+ proxyPort: 3000
192
+ };
193
+ globalThis.__IS_DEVELOPMENT__ = true;
194
+ globalThis.__IS_PRODUCTION__ = false;
195
+ };
196
+ const withGlobalConfig = (overrides, testFn)=>async ()=>{
197
+ overrideGlobalConfig(overrides);
198
+ try {
199
+ await testFn();
200
+ } finally{
201
+ resetGlobalConfig();
202
+ }
203
+ };
204
+ const createFactoryTestError = (testContext, operationName, details)=>new Error(`Factory Test Failure [${testContext}]: ${operationName} - ${details || "Unknown error"}. Check factory implementation and hook usage patterns.`);
205
+ const validateFactoryHook = (hook, operationName)=>{
206
+ if ("function" != typeof hook) throw createFactoryTestError("Factory Validation", operationName, "hook should be a function - check if useCreate*Hook factory is properly returning a hook function");
207
+ };
208
+ const validateHookResult = (result, hookType)=>{
209
+ const commonProps = [
210
+ "isError",
211
+ "isSuccess",
212
+ "data",
213
+ "error"
214
+ ];
215
+ const queryProps = [
216
+ "isLoading"
217
+ ];
218
+ const mutationProps = [
219
+ "mutate",
220
+ "mutateAsync",
221
+ "isPending"
222
+ ];
223
+ const infiniteProps = [
224
+ "hasNextPage",
225
+ "fetchNextPage",
226
+ "isFetchingNextPage"
227
+ ];
228
+ const expectedProps = [
229
+ ...commonProps,
230
+ ..."query" === hookType ? queryProps : [],
231
+ ..."mutation" === hookType ? mutationProps : [],
232
+ ..."infiniteQuery" === hookType ? infiniteProps : []
233
+ ];
234
+ for (const prop of expectedProps)if (!(prop in result)) throw createFactoryTestError("Hook Validation", hookType, `Missing property '${prop}' - check if factory is returning proper React Query hook result`);
235
+ };
236
+ const createMockMutationResult = (mutate, overrides = {})=>({
237
+ mutate,
238
+ mutateAsync: jest.fn(),
239
+ reset: jest.fn(),
240
+ isPending: false,
241
+ isIdle: true,
242
+ isError: false,
243
+ isSuccess: false,
244
+ status: "idle",
245
+ data: void 0,
246
+ error: null,
247
+ variables: void 0,
248
+ context: void 0,
249
+ failureCount: 0,
250
+ failureReason: null,
251
+ isPaused: false,
252
+ submittedAt: 0,
253
+ ...overrides
254
+ });
255
+ const createMockQueryResult = (overrides = {})=>({
256
+ data: void 0,
257
+ error: null,
258
+ isError: false,
259
+ isLoading: false,
260
+ isLoadingError: false,
261
+ isRefetchError: false,
262
+ isSuccess: false,
263
+ status: "pending",
264
+ dataUpdatedAt: 0,
265
+ errorUpdatedAt: 0,
266
+ failureCount: 0,
267
+ failureReason: null,
268
+ errorUpdateCount: 0,
269
+ isFetched: false,
270
+ isFetchedAfterMount: false,
271
+ isFetching: false,
272
+ isInitialLoading: false,
273
+ isPaused: false,
274
+ isPlaceholderData: false,
275
+ isPending: false,
276
+ isRefetching: false,
277
+ isStale: false,
278
+ refetch: jest.fn(),
279
+ ...overrides
280
+ });
281
+ const findToggleByLabel = (labelText)=>{
282
+ const label = screen.getByText(labelText);
283
+ let current = label.parentElement;
284
+ while(current && !current.querySelector('input[type="checkbox"]'))current = current.parentElement;
285
+ return current?.querySelector('input[type="checkbox"]');
286
+ };
287
+ const submitForm = async (buttonName = "create")=>{
288
+ await waitFor(()=>{
289
+ const button = screen.getByRole("button", {
290
+ name: "create" === buttonName ? /create/i : /save/i
291
+ });
292
+ expect(button).toBeEnabled();
293
+ });
294
+ const button = screen.getByRole("button", {
295
+ name: "create" === buttonName ? /create/i : /save/i
296
+ });
297
+ fireEvent.click(button);
298
+ };
299
+ const mockSuccessSubmit = (mockMutate)=>{
300
+ mockMutate.mockImplementation((_, options)=>{
301
+ options?.onSuccess?.();
302
+ });
303
+ };
304
+ const mockErrorSubmit = (mockMutate, errorMessage = "Network Error")=>{
305
+ const error = new Error(errorMessage);
306
+ mockMutate.mockImplementation((_, options)=>{
307
+ options?.onError?.(error);
308
+ });
309
+ };
310
+ export { MockedPutObjectCommand, MockedS3Client, createFactoryTestError, createMockMutationResult, createMockQueryResult, createQueryWrapper, createTestFile, createTestWrapper, findToggleByLabel, mockErrorSubmit, mockOffsetSize, mockS3Client, mockSuccessSubmit, overrideGlobalConfig, overrideHandlers, renderHookWithWrapper, resetGlobalConfig, setupCommonMocks, setupMswServer, setupS3Mocks, submitForm, testConfig, testCredentials, validateFactoryHook, validateHookResult, withGlobalConfig };
@@ -0,0 +1 @@
1
+ export {};