@databiosphere/findable-ui 16.1.0 → 17.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.
Files changed (84) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/lib/components/Export/components/DownloadCurlCommand/downloadCurlCommand.d.ts +3 -2
  4. package/lib/components/Export/components/DownloadCurlCommand/downloadCurlCommand.js +6 -4
  5. package/lib/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.d.ts +3 -2
  6. package/lib/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.js +2 -12
  7. package/lib/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.d.ts +5 -2
  8. package/lib/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.js +2 -2
  9. package/lib/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.d.ts +3 -1
  10. package/lib/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.js +2 -2
  11. package/lib/components/Export/components/ExportToTerra/exportToTerra.d.ts +1 -1
  12. package/lib/components/Export/components/ExportToTerra/exportToTerra.js +9 -6
  13. package/lib/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.d.ts +3 -1
  14. package/lib/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.js +3 -4
  15. package/lib/components/Export/components/ManifestDownload/manifestDownload.d.ts +3 -2
  16. package/lib/components/Export/components/ManifestDownload/manifestDownload.js +6 -4
  17. package/lib/hooks/types.d.ts +4 -0
  18. package/lib/hooks/types.js +5 -0
  19. package/lib/hooks/useFileManifest/common/entities.d.ts +0 -5
  20. package/lib/hooks/useFileManifest/common/entities.js +0 -6
  21. package/lib/hooks/useFileManifest/useFileManifest.d.ts +8 -5
  22. package/lib/hooks/useFileManifest/useFileManifest.js +29 -8
  23. package/lib/hooks/useFileManifest/useFileManifestDownload.js +10 -9
  24. package/lib/hooks/useFileManifest/useFileManifestFormat.d.ts +12 -0
  25. package/lib/hooks/useFileManifest/useFileManifestFormat.js +10 -0
  26. package/lib/hooks/useRequestFileLocation.d.ts +1 -4
  27. package/lib/hooks/useRequestFileLocation.js +1 -5
  28. package/lib/hooks/useRequestManifest/constants.d.ts +2 -0
  29. package/lib/hooks/useRequestManifest/constants.js +4 -0
  30. package/lib/hooks/useRequestManifest/types.d.ts +6 -0
  31. package/lib/hooks/useRequestManifest/types.js +1 -0
  32. package/lib/hooks/useRequestManifest/useRequestManifest.d.ts +10 -0
  33. package/lib/hooks/useRequestManifest/useRequestManifest.js +30 -0
  34. package/lib/hooks/useRequestManifest/utils.d.ts +65 -0
  35. package/lib/hooks/useRequestManifest/utils.js +118 -0
  36. package/lib/mocks/useRequestFileManifest.mocks.d.ts +11 -0
  37. package/lib/mocks/useRequestFileManifest.mocks.js +100 -0
  38. package/lib/providers/fileManifestState/constants.d.ts +0 -2
  39. package/lib/providers/fileManifestState/constants.js +0 -11
  40. package/lib/providers/fileManifestState.d.ts +3 -25
  41. package/lib/providers/fileManifestState.js +3 -36
  42. package/lib/views/ExportView/exportView.js +2 -2
  43. package/package.json +1 -1
  44. package/src/components/Export/components/DownloadCurlCommand/downloadCurlCommand.tsx +17 -10
  45. package/src/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.tsx +7 -16
  46. package/src/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.tsx +8 -4
  47. package/src/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.tsx +4 -1
  48. package/src/components/Export/components/ExportToTerra/exportToTerra.tsx +13 -9
  49. package/src/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.tsx +4 -9
  50. package/src/components/Export/components/ManifestDownload/manifestDownload.tsx +17 -11
  51. package/src/hooks/types.ts +4 -0
  52. package/src/hooks/useFileManifest/common/entities.ts +0 -6
  53. package/src/hooks/useFileManifest/useFileManifest.ts +34 -13
  54. package/src/hooks/useFileManifest/useFileManifestDownload.ts +21 -16
  55. package/src/hooks/useFileManifest/useFileManifestFormat.ts +23 -0
  56. package/src/hooks/useRequestFileLocation.ts +1 -5
  57. package/src/hooks/useRequestManifest/constants.ts +6 -0
  58. package/src/hooks/useRequestManifest/types.ts +7 -0
  59. package/src/hooks/useRequestManifest/useRequestManifest.ts +49 -0
  60. package/src/hooks/useRequestManifest/utils.ts +153 -0
  61. package/src/mocks/useRequestFileManifest.mocks.ts +121 -0
  62. package/src/providers/fileManifestState/constants.ts +0 -15
  63. package/src/providers/fileManifestState.tsx +5 -77
  64. package/src/views/ExportView/exportView.tsx +2 -2
  65. package/tests/buildRequestFilters.test.ts +68 -0
  66. package/tests/buildRequestManifest.test.ts +103 -0
  67. package/tests/useRequestManifest.test.ts +193 -0
  68. package/lib/hooks/useFileManifest/common/buildFileManifestRequestURL.d.ts +0 -15
  69. package/lib/hooks/useFileManifest/common/buildFileManifestRequestURL.js +0 -28
  70. package/lib/hooks/useFileManifest/useFileManifestURL.d.ts +0 -5
  71. package/lib/hooks/useFileManifest/useFileManifestURL.js +0 -11
  72. package/lib/hooks/useFileManifest/useRequestFileManifest.d.ts +0 -11
  73. package/lib/hooks/useFileManifest/useRequestFileManifest.js +0 -40
  74. package/lib/providers/fileManifestState/actions.d.ts +0 -9
  75. package/lib/providers/fileManifestState/actions.js +0 -19
  76. package/lib/providers/fileManifestState/utils.d.ts +0 -34
  77. package/lib/providers/fileManifestState/utils.js +0 -80
  78. package/src/hooks/useFileManifest/common/buildFileManifestRequestURL.ts +0 -44
  79. package/src/hooks/useFileManifest/useFileManifestURL.ts +0 -12
  80. package/src/hooks/useFileManifest/useRequestFileManifest.ts +0 -51
  81. package/src/providers/fileManifestState/actions.ts +0 -34
  82. package/src/providers/fileManifestState/utils.ts +0 -108
  83. package/tests/fileManifestRequestFilters.test.ts +0 -160
  84. package/tests/updateFilesFacetsStatus.test.ts +0 -84
@@ -1,23 +1,10 @@
1
- import {
2
- FILE_MANIFEST_TYPE,
3
- FILES_FACETS_STATUS,
4
- } from "../../hooks/useFileManifest/common/entities";
5
1
  import { FileManifestState } from "../fileManifestState";
6
2
 
7
- export const ENTITIES_FILE_MANIFEST_TYPES: FILE_MANIFEST_TYPE[] = [
8
- FILE_MANIFEST_TYPE.BULK_DOWNLOAD,
9
- FILE_MANIFEST_TYPE.DOWNLOAD_MANIFEST,
10
- FILE_MANIFEST_TYPE.EXPORT_TO_TERRA,
11
- ];
12
-
13
3
  export const FILE_MANIFEST_STATE: FileManifestState = {
14
- fileManifestFormat: undefined,
15
- fileManifestType: undefined,
16
4
  fileSummary: undefined,
17
5
  fileSummaryFacetName: undefined,
18
6
  fileSummaryFilters: [],
19
7
  filesFacets: [],
20
- filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
21
8
  filters: [],
22
9
  isEnabled: false,
23
10
  isFacetsLoading: false,
@@ -25,7 +12,5 @@ export const FILE_MANIFEST_STATE: FileManifestState = {
25
12
  isFileSummaryLoading: false,
26
13
  isLoading: false,
27
14
  isSummaryLoading: false,
28
- requestParams: undefined,
29
- requestURL: undefined,
30
15
  summary: undefined,
31
16
  };
@@ -5,10 +5,7 @@ import React, {
5
5
  useEffect,
6
6
  useReducer,
7
7
  } from "react";
8
- import {
9
- AzulSummaryResponse,
10
- ManifestDownloadFormat,
11
- } from "../apis/azul/common/entities";
8
+ import { AzulSummaryResponse } from "../apis/azul/common/entities";
12
9
  import { getFilterParameterValue } from "../apis/azul/common/utils";
13
10
  import {
14
11
  CategoryKey,
@@ -18,27 +15,16 @@ import {
18
15
  } from "../common/entities";
19
16
  import { useCatalog } from "../hooks/useCatalog";
20
17
  import { buildNextFilterState } from "../hooks/useCategoryFilter";
21
- import { buildFileManifestRequestURL } from "../hooks/useFileManifest/common/buildFileManifestRequestURL";
22
- import {
23
- FileFacet,
24
- FileManifestType,
25
- FILES_FACETS_STATUS,
26
- } from "../hooks/useFileManifest/common/entities";
18
+ import { FileFacet } from "../hooks/useFileManifest/common/entities";
27
19
  import { useFetchFilesFacets } from "../hooks/useFileManifest/useFetchFilesFacets";
28
20
  import { useFetchSummary } from "../hooks/useFileManifest/useFetchSummary";
29
- import { useFileManifestURL } from "../hooks/useFileManifest/useFileManifestURL";
30
- import { updateFileManifestAction } from "./fileManifestState/actions";
31
21
  import { FILE_MANIFEST_STATE } from "./fileManifestState/constants";
32
- import { getRequestFilters } from "./fileManifestState/utils";
33
22
 
34
23
  /**
35
24
  * File manifest state.
36
25
  */
37
26
  export type FileManifestState = {
38
- fileManifestFormat?: ManifestDownloadFormat;
39
- fileManifestType?: FileManifestType;
40
27
  filesFacets: FileFacet[];
41
- filesFacetsStatus: FILES_FACETS_STATUS;
42
28
  fileSummary?: AzulSummaryResponse;
43
29
  fileSummaryFacetName?: string;
44
30
  fileSummaryFilters: Filters;
@@ -49,8 +35,6 @@ export type FileManifestState = {
49
35
  isFileSummaryLoading: boolean;
50
36
  isLoading: boolean;
51
37
  isSummaryLoading: boolean;
52
- requestParams?: URLSearchParams;
53
- requestURL?: string;
54
38
  summary?: AzulSummaryResponse;
55
39
  };
56
40
 
@@ -79,13 +63,9 @@ export function FileManifestStateProvider({
79
63
  // Determine catalog.
80
64
  const catalog = useCatalog() as string; // catalog should be defined.
81
65
 
82
- // Determine file manifest request data URL.
83
- const URL = useFileManifestURL();
84
-
85
66
  // File manifest state.
86
67
  const [fileManifestState, fileManifestDispatch] = useReducer(
87
- (s: FileManifestState, a: FileManifestAction) =>
88
- fileManifestReducer(s, a, { URL, catalog }),
68
+ (s: FileManifestState, a: FileManifestAction) => fileManifestReducer(s, a),
89
69
  FILE_MANIFEST_STATE
90
70
  );
91
71
 
@@ -154,7 +134,6 @@ export enum FileManifestActionKind {
154
134
  ClearFileManifest = "CLEAR_FILE_MANIFEST",
155
135
  FetchFileManifest = "FETCH_FILE_MANIFEST",
156
136
  UpdateFileManifest = "UPDATE_FILE_MANIFEST",
157
- UpdateFileManifestFormat = "UPDATE_FILE_MANIFEST_FORMAT",
158
137
  UpdateFilter = "UPDATE_FILTER",
159
138
  UpdateFiltersCategory = "UPDATE_FILTERS_CATEGORY",
160
139
  }
@@ -166,7 +145,6 @@ export type FileManifestAction =
166
145
  | ClearFileManifestAction
167
146
  | FetchFileManifestAction
168
147
  | UpdateFileManifestAction
169
- | UpdateFileManifestFormatAction
170
148
  | UpdateFilterAction
171
149
  | UpdateFiltersCategoryAction;
172
150
 
@@ -194,14 +172,6 @@ type UpdateFileManifestAction = {
194
172
  type: FileManifestActionKind.UpdateFileManifest;
195
173
  };
196
174
 
197
- /**
198
- * Update file manifest format action.
199
- */
200
- type UpdateFileManifestFormatAction = {
201
- payload: ManifestDownloadFormat | undefined;
202
- type: FileManifestActionKind.UpdateFileManifestFormat;
203
- };
204
-
205
175
  /**
206
176
  * Update filter action.
207
177
  */
@@ -222,8 +192,6 @@ type UpdateFiltersCategoryAction = {
222
192
  * Initialize file manifest payload.
223
193
  */
224
194
  type FetchFileManifestPayload = {
225
- fileManifestFormat?: ManifestDownloadFormat;
226
- fileManifestType?: FileManifestType;
227
195
  fileSummaryFacetName?: string;
228
196
  filters: Filters;
229
197
  };
@@ -251,38 +219,23 @@ export type UpdateFilterPayload = {
251
219
  selectedValue: CategoryValueKey;
252
220
  };
253
221
 
254
- /**
255
- * File manifest context.
256
- */
257
- export interface FileManifestContext {
258
- catalog: string;
259
- URL: string;
260
- }
261
-
262
222
  /**
263
223
  * File manifest reducer.
264
224
  * @param state - File manifest state.
265
225
  * @param action - File manifest action.
266
- * @param fileManifestContext - File manifest context.
267
226
  * @returns file manifest state.
268
227
  */
269
228
  function fileManifestReducer(
270
229
  state: FileManifestState,
271
- action: FileManifestAction,
272
- fileManifestContext: FileManifestContext
230
+ action: FileManifestAction
273
231
  ): FileManifestState {
274
232
  const { payload, type } = action;
275
- const { catalog, URL } = fileManifestContext;
276
233
  switch (type) {
277
234
  // Resets file manifest.
278
235
  case FileManifestActionKind.ClearFileManifest: {
279
236
  return {
280
237
  ...state,
281
- fileManifestFormat: undefined,
282
- filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
283
238
  isEnabled: false,
284
- requestParams: undefined,
285
- requestURL: undefined,
286
239
  };
287
240
  }
288
241
  // Fetches file manifest.
@@ -297,30 +250,11 @@ function fileManifestReducer(
297
250
  ...payload,
298
251
  fileSummaryFilters,
299
252
  isEnabled: true,
300
- requestParams: undefined,
301
- requestURL: undefined,
302
253
  };
303
254
  }
304
255
  // Updates file manifest.
305
256
  case FileManifestActionKind.UpdateFileManifest: {
306
- return updateFileManifestAction(state, payload, fileManifestContext);
307
- }
308
- // Updates file manifest format.
309
- case FileManifestActionKind.UpdateFileManifestFormat: {
310
- // Build request params and request URL.
311
- const { requestParams, requestURL } =
312
- buildFileManifestRequestURL(
313
- URL,
314
- getRequestFilters(state),
315
- catalog,
316
- payload
317
- ) || {};
318
- return {
319
- ...state,
320
- fileManifestFormat: payload,
321
- requestParams,
322
- requestURL,
323
- };
257
+ return { ...state, ...payload };
324
258
  }
325
259
  // Updates selected file manifest filters with given selected category value.
326
260
  case FileManifestActionKind.UpdateFilter: {
@@ -339,10 +273,7 @@ function fileManifestReducer(
339
273
  return {
340
274
  ...state,
341
275
  fileSummaryFilters,
342
- filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
343
276
  filters,
344
- requestParams: undefined,
345
- requestURL: undefined,
346
277
  };
347
278
  }
348
279
  // Updates selected file manifest filters by category.
@@ -361,10 +292,7 @@ function fileManifestReducer(
361
292
  return {
362
293
  ...state,
363
294
  fileSummaryFilters,
364
- filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
365
295
  filters,
366
- requestParams: undefined,
367
- requestURL: undefined,
368
296
  };
369
297
  }
370
298
  default:
@@ -4,7 +4,7 @@ import { ComponentCreator } from "../../components/ComponentCreator/ComponentCre
4
4
  import { BackPageView } from "../../components/Layout/components/BackPage/backPageView";
5
5
  import { useExploreState } from "../../hooks/useExploreState";
6
6
  import { useExportConfig } from "../../hooks/useExportConfig";
7
- import { useRequestFileManifest } from "../../hooks/useFileManifest/useRequestFileManifest";
7
+ import { useFileManifest } from "../../hooks/useFileManifest/useFileManifest";
8
8
  import { useUpdateURLSearchParams } from "../../hooks/useUpdateURLSearchParams";
9
9
 
10
10
  export type ExportViewProps = AzulEntityStaticResponse;
@@ -14,7 +14,7 @@ export const ExportView = (props: ExportViewProps): JSX.Element => {
14
14
  exploreState: { filterState },
15
15
  } = useExploreState();
16
16
  useUpdateURLSearchParams();
17
- useRequestFileManifest(undefined, undefined, filterState, undefined);
17
+ useFileManifest(filterState, undefined);
18
18
  const { tabs, top } = useExportConfig();
19
19
  const currentTab = tabs[0];
20
20
  const { mainColumn, sideColumn } = currentTab;
@@ -0,0 +1,68 @@
1
+ import { Filters } from "../src/common/entities";
2
+ import { buildRequestFilters } from "../src/hooks/useRequestManifest/utils";
3
+ import {
4
+ FILE_MANIFEST_STATE,
5
+ FILTERS,
6
+ FORM_FACET,
7
+ } from "../src/mocks/useRequestFileManifest.mocks";
8
+ import { FileManifestState } from "../src/providers/fileManifestState";
9
+
10
+ describe("buildRequestFilters", () => {
11
+ describe("should return filters from file manifest state", () => {
12
+ test("when form facet is not defined", () => {
13
+ const fileManifestState = getFileManifestState(FILTERS.FORM_INITIAL_SET);
14
+ const result = buildRequestFilters(fileManifestState, {});
15
+ expect(result).toEqual(fileManifestState.filters);
16
+ });
17
+
18
+ test("when form facet `fileSummaryFacet` and `speciesFacet` are not defined", () => {
19
+ const fileManifestState = getFileManifestState(FILTERS.FORM_INITIAL_SET);
20
+ const result = buildRequestFilters(
21
+ fileManifestState,
22
+ FORM_FACET.INITIAL_SET
23
+ );
24
+ expect(result).toEqual(fileManifestState.filters);
25
+ });
26
+
27
+ test("when at least one form facet has no terms selected", () => {
28
+ const fileManifestState = getFileManifestState(
29
+ FILTERS.FORM_INCOMPLETE_SET
30
+ );
31
+ const result = buildRequestFilters(
32
+ fileManifestState,
33
+ FORM_FACET.INCOMPLETE_SET
34
+ );
35
+ expect(result).toEqual(fileManifestState.filters);
36
+ });
37
+
38
+ test("when at least one form facet has an unselected term", () => {
39
+ const fileManifestState = getFileManifestState(FILTERS.FORM_SUBSET);
40
+ const result = buildRequestFilters(fileManifestState, FORM_FACET.SUBSET);
41
+ expect(result).toEqual(fileManifestState.filters);
42
+ });
43
+ });
44
+
45
+ describe("should return filters excluding form related filters", () => {
46
+ test("when all form facets have all their terms selected", () => {
47
+ const fileManifestState = getFileManifestState(FILTERS.FORM_COMPLETE_SET);
48
+ const result = buildRequestFilters(
49
+ fileManifestState,
50
+ FORM_FACET.COMPLETE_SET
51
+ );
52
+ expect(result).not.toEqual(fileManifestState.filters);
53
+ expect(result).toEqual(FILTERS.FORM_INITIAL_SET);
54
+ });
55
+ });
56
+ });
57
+
58
+ /**
59
+ * Returns a file manifest state with the given filters.
60
+ * @param filters - Selected filters.
61
+ * @returns file manifest state.
62
+ */
63
+ function getFileManifestState(filters: Filters): FileManifestState {
64
+ return {
65
+ ...FILE_MANIFEST_STATE,
66
+ filters,
67
+ };
68
+ }
@@ -0,0 +1,103 @@
1
+ import {
2
+ MANIFEST_DOWNLOAD_FORMAT,
3
+ ManifestDownloadFormat,
4
+ } from "../src/apis/azul/common/entities";
5
+ import { transformFilters } from "../src/apis/azul/common/filterTransformer";
6
+ import { Filters } from "../src/common/entities";
7
+ import { METHOD } from "../src/hooks/types";
8
+ import { buildRequestManifest } from "../src/hooks/useRequestManifest/utils";
9
+ import { FILTERS } from "../src/mocks/useRequestFileManifest.mocks";
10
+
11
+ const ENDPOINT_URL = "https://example.com/";
12
+ const CATALOG = "test-catalog";
13
+ const MANIFEST_FORMAT = MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB;
14
+
15
+ describe("buildRequestManifest", () => {
16
+ test("should return request method 'PUT'", () => {
17
+ const result = buildRequestManifest(
18
+ ENDPOINT_URL,
19
+ CATALOG,
20
+ FILTERS.FORM_SUBSET,
21
+ MANIFEST_FORMAT
22
+ );
23
+ expect(result.requestMethod).toEqual(METHOD.PUT);
24
+ });
25
+
26
+ test("should return defined request params and request url", () => {
27
+ const result = buildRequestManifest(
28
+ ENDPOINT_URL,
29
+ CATALOG,
30
+ FILTERS.FORM_SUBSET,
31
+ MANIFEST_FORMAT
32
+ );
33
+ expect(result.requestParams).toBeDefined();
34
+ expect(result.requestUrl).toBeDefined();
35
+ });
36
+
37
+ test("should return request params with entries 'catalog', 'filters' and 'format'", () => {
38
+ const result = buildRequestManifest(
39
+ ENDPOINT_URL,
40
+ CATALOG,
41
+ FILTERS.FORM_SUBSET,
42
+ MANIFEST_FORMAT
43
+ );
44
+ // Assert that the requestParams contains the required keys.
45
+ expect(result.requestParams?.has("catalog")).toBeTruthy();
46
+ expect(result.requestParams?.has("filters")).toBeTruthy();
47
+ expect(result.requestParams?.has("format")).toBeTruthy();
48
+ // // Assert the values of these keys.
49
+ expect(result.requestParams?.get("catalog")).toEqual(CATALOG);
50
+ expect(result.requestParams?.get("filters")).toEqual(
51
+ transformFilters(FILTERS.FORM_SUBSET)
52
+ );
53
+ expect(result.requestParams?.get("format")).toEqual(MANIFEST_FORMAT);
54
+ });
55
+
56
+ test("should return expected request URL", () => {
57
+ const result = buildRequestManifest(
58
+ ENDPOINT_URL,
59
+ CATALOG,
60
+ FILTERS.FORM_INITIAL_SET,
61
+ MANIFEST_FORMAT
62
+ );
63
+ const expectedParams = getExpectedParams(
64
+ CATALOG,
65
+ FILTERS.FORM_INITIAL_SET,
66
+ MANIFEST_FORMAT
67
+ );
68
+ const expectedUrl = getExpectedUrl(expectedParams);
69
+ expect(result.requestUrl).toEqual(expectedUrl);
70
+ });
71
+ });
72
+
73
+ /**
74
+ * Returns the expected URLSearchParams for the given parameters.
75
+ * @param catalog - Catalog.
76
+ * @param filters - Selected filters.
77
+ * @param manifestFormat - Manifest format.
78
+ * @returns URLSearchParams.
79
+ */
80
+ function getExpectedParams(
81
+ catalog: string,
82
+ filters: Filters,
83
+ manifestFormat: ManifestDownloadFormat
84
+ ): URLSearchParams {
85
+ return new URLSearchParams({
86
+ catalog,
87
+ filters: transformFilters(filters),
88
+ format: manifestFormat,
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Returns the expected URL for the given parameters.
94
+ * @param expectedParams - Expected URLSearchParams.
95
+ * @param endpointUrl - Data URL.
96
+ * @returns expected URL.
97
+ */
98
+ function getExpectedUrl(
99
+ expectedParams: URLSearchParams,
100
+ endpointUrl: string = ENDPOINT_URL
101
+ ): string {
102
+ return `${endpointUrl}fetch/manifest/files?${expectedParams.toString()}`;
103
+ }
@@ -0,0 +1,193 @@
1
+ import { jest } from "@jest/globals";
2
+ import { renderHook } from "@testing-library/react";
3
+ import { MANIFEST_DOWNLOAD_FORMAT } from "../src/apis/azul/common/entities";
4
+ import { FormFacet } from "../src/components/Export/common/entities";
5
+ import { METHOD } from "../src/hooks/types";
6
+ import {
7
+ CATALOG,
8
+ CONFIG,
9
+ FILE_MANIFEST_STATE,
10
+ FORM_FACET,
11
+ } from "../src/mocks/useRequestFileManifest.mocks";
12
+
13
+ jest.unstable_mockModule("../src/hooks/useConfig", () => ({
14
+ useConfig: jest.fn(),
15
+ }));
16
+
17
+ jest.unstable_mockModule("../src/hooks/useCatalog", () => ({
18
+ useCatalog: jest.fn(),
19
+ }));
20
+
21
+ jest.unstable_mockModule("../src/hooks/useFileManifestState", () => ({
22
+ useFileManifestState: jest.fn(),
23
+ }));
24
+
25
+ const { useConfig } = await import("../src/hooks/useConfig");
26
+ const { useCatalog } = await import("../src/hooks/useCatalog");
27
+ const { useFileManifestState } = await import(
28
+ "../src/hooks/useFileManifestState"
29
+ );
30
+ const { useRequestManifest } = await import(
31
+ "../src/hooks/useRequestManifest/useRequestManifest"
32
+ );
33
+
34
+ const MOCK_USE_CATALOG = useCatalog as jest.MockedFunction<typeof useCatalog>;
35
+ const MOCK_USE_CONFIG = useConfig as jest.MockedFunction<
36
+ () => Partial<ReturnType<typeof useConfig>>
37
+ >;
38
+ const MOCK_USE_FILE_MANIFEST_STATE =
39
+ useFileManifestState as jest.MockedFunction<
40
+ () => Partial<ReturnType<typeof useFileManifestState>>
41
+ >;
42
+
43
+ describe("useRequestManifest", () => {
44
+ beforeEach(() => {
45
+ MOCK_USE_CATALOG.mockReset();
46
+ MOCK_USE_CONFIG.mockReset();
47
+ MOCK_USE_FILE_MANIFEST_STATE.mockReset();
48
+ MOCK_USE_CATALOG.mockReturnValue(CATALOG);
49
+ MOCK_USE_CONFIG.mockReturnValue(CONFIG);
50
+ MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
51
+ fileManifestDispatch: jest.fn(),
52
+ fileManifestState: FILE_MANIFEST_STATE,
53
+ });
54
+ });
55
+
56
+ describe("useRequestManifest - always returns request method", () => {
57
+ test("requestMethod is always METHOD.PUT regardless of conditions", () => {
58
+ MOCK_USE_CATALOG.mockReturnValue(undefined);
59
+ const { result } = renderHook(() =>
60
+ useRequestManifest(undefined, FORM_FACET.INITIAL_SET)
61
+ );
62
+ expect(result.current.requestMethod).toEqual(METHOD.PUT);
63
+ expect(result.current.requestParams).toBeUndefined();
64
+ expect(result.current.requestUrl).toBeUndefined();
65
+ });
66
+ });
67
+
68
+ describe("useRequestManifest - returns undefined for params and URL when", () => {
69
+ test("catalog is not defined", () => {
70
+ MOCK_USE_CATALOG.mockReturnValue(undefined);
71
+ testRequestManifest({
72
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
73
+ });
74
+ });
75
+
76
+ describe("fileManifestFormat is not ready", () => {
77
+ test("when fileManifestFormat is not defined", () => {
78
+ testRequestManifest({
79
+ fileManifestFormat: undefined,
80
+ });
81
+ });
82
+
83
+ test("when fileManifestFormat is invalid", () => {
84
+ testRequestManifest({
85
+ fileManifestFormat: "INVALID_FORMAT" as MANIFEST_DOWNLOAD_FORMAT,
86
+ });
87
+ });
88
+ });
89
+
90
+ describe("fileManifestState is not ready", () => {
91
+ test("when fileManifestState is not enabled", () => {
92
+ MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
93
+ fileManifestDispatch: jest.fn(),
94
+ fileManifestState: { ...FILE_MANIFEST_STATE, isEnabled: false },
95
+ });
96
+ testRequestManifest({
97
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
98
+ });
99
+ });
100
+
101
+ test("when fileManifestState is loading", () => {
102
+ MOCK_USE_FILE_MANIFEST_STATE.mockReturnValue({
103
+ fileManifestDispatch: jest.fn(),
104
+ fileManifestState: { ...FILE_MANIFEST_STATE, isLoading: true },
105
+ });
106
+ testRequestManifest({
107
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
108
+ });
109
+ });
110
+ });
111
+
112
+ describe("form selection is not ready", () => {
113
+ test("when a form facet is undefined", () => {
114
+ testRequestManifest({
115
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
116
+ formFacet: {},
117
+ });
118
+ });
119
+
120
+ test("when a form facet `fileSummaryFacet` and `speciesFacet` are not defined", () => {
121
+ testRequestManifest({
122
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
123
+ formFacet: FORM_FACET.INITIAL_SET,
124
+ });
125
+ });
126
+
127
+ test("when a form facet is not selected", () => {
128
+ testRequestManifest({
129
+ fileManifestFormat: MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
130
+ formFacet: FORM_FACET.INCOMPLETE_SET,
131
+ });
132
+ });
133
+ });
134
+ });
135
+
136
+ describe("useRequestManifest - returns the request manifest object when all conditions are met", () => {
137
+ test("and at least one form facet has an unselected term", () => {
138
+ const { result } = renderHook(() =>
139
+ useRequestManifest(
140
+ MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
141
+ FORM_FACET.SUBSET
142
+ )
143
+ );
144
+ expect(result.current.requestMethod).toEqual(METHOD.PUT);
145
+ expect(result.current.requestParams).toBeDefined();
146
+ expect(result.current.requestUrl).toBeDefined();
147
+ });
148
+
149
+ test("and all form facets have all their terms selected", () => {
150
+ const { result } = renderHook(() =>
151
+ useRequestManifest(
152
+ MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB,
153
+ FORM_FACET.COMPLETE_SET
154
+ )
155
+ );
156
+ expect(result.current.requestMethod).toEqual(METHOD.PUT);
157
+ expect(result.current.requestParams).toBeDefined();
158
+ expect(result.current.requestUrl).toBeDefined();
159
+ });
160
+ });
161
+ });
162
+
163
+ /**
164
+ * Utility function to test the behavior of the `useRequestManifest` hook.
165
+ * This function renders the `useRequestManifest` hook with the provided arguments
166
+ * and asserts the expected values for `requestMethod`, `requestParams`, and `requestUrl`.
167
+ * @param testObject - Object containing the expected values for `requestMethod`, `requestParams`, and `requestUrl`.
168
+ * @param testObject.expectedMethod - The expected request method.
169
+ * @param testObject.expectedParams - The expected request parameters.
170
+ * @param testObject.expectedUrl - The expected request URL.
171
+ * @param testObject.fileManifestFormat - The file manifest format.
172
+ * @param testObject.formFacet - Form facet.
173
+ */
174
+ function testRequestManifest({
175
+ expectedParams = undefined,
176
+ expectedUrl = undefined,
177
+ expectedMethod = METHOD.PUT,
178
+ fileManifestFormat,
179
+ formFacet = FORM_FACET.COMPLETE_SET,
180
+ }: {
181
+ expectedMethod?: METHOD;
182
+ expectedParams?: URLSearchParams;
183
+ expectedUrl?: string;
184
+ fileManifestFormat?: MANIFEST_DOWNLOAD_FORMAT;
185
+ formFacet?: FormFacet;
186
+ }): void {
187
+ const { result } = renderHook(() =>
188
+ useRequestManifest(fileManifestFormat, formFacet)
189
+ );
190
+ expect(result.current.requestMethod).toEqual(expectedMethod);
191
+ expect(result.current.requestParams).toEqual(expectedParams);
192
+ expect(result.current.requestUrl).toEqual(expectedUrl);
193
+ }
@@ -1,15 +0,0 @@
1
- import { ManifestDownloadFormat } from "../../../apis/azul/common/entities";
2
- import { Filters } from "../../../common/entities";
3
- export interface FileManifestRequestURL {
4
- requestParams: URLSearchParams;
5
- requestURL: string;
6
- }
7
- /**
8
- * Build up file manifest request params and URL query string for the given search results, catalog and format.
9
- * @param url - Data URL.
10
- * @param filters - Selected filters.
11
- * @param catalog - Configured catalog.
12
- * @param manifestFormat - Manifest format.
13
- * @returns file manifest request params and URL query string.
14
- */
15
- export declare const buildFileManifestRequestURL: (url: string, filters: Filters | undefined, catalog: string, manifestFormat: ManifestDownloadFormat | undefined) => FileManifestRequestURL | undefined;
@@ -1,28 +0,0 @@
1
- import { AZUL_PARAM, } from "../../../apis/azul/common/entities";
2
- import { transformFilters } from "../../../apis/azul/common/filterTransformer";
3
- /**
4
- * Build up file manifest request params and URL query string for the given search results, catalog and format.
5
- * @param url - Data URL.
6
- * @param filters - Selected filters.
7
- * @param catalog - Configured catalog.
8
- * @param manifestFormat - Manifest format.
9
- * @returns file manifest request params and URL query string.
10
- */
11
- export const buildFileManifestRequestURL = (url, filters, catalog, manifestFormat) => {
12
- if (!manifestFormat)
13
- return;
14
- if (!filters)
15
- return;
16
- // Build request params.
17
- const requestParams = new URLSearchParams({
18
- [AZUL_PARAM.CATALOG]: catalog,
19
- [AZUL_PARAM.FILTERS]: transformFilters(filters),
20
- format: manifestFormat,
21
- });
22
- // Build file manifest URL
23
- const requestURL = `${url}fetch/manifest/files?${requestParams.toString()}`;
24
- return {
25
- requestParams,
26
- requestURL,
27
- };
28
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns data URL for the integrations end point.
3
- * @returns data URL for the integrations end point.
4
- */
5
- export declare const useFileManifestURL: () => string;
@@ -1,11 +0,0 @@
1
- import { useConfig } from "../useConfig";
2
- /**
3
- * Returns data URL for the integrations end point.
4
- * @returns data URL for the integrations end point.
5
- */
6
- export const useFileManifestURL = () => {
7
- const { config } = useConfig();
8
- const { dataSource } = config;
9
- const { url } = dataSource;
10
- return url;
11
- };
@@ -1,11 +0,0 @@
1
- import { ManifestDownloadFormat } from "../../apis/azul/common/entities";
2
- import { Filters } from "../../common/entities";
3
- import { FileManifestType } from "./common/entities";
4
- /**
5
- * Initializes and fetches file manifest comprising file facets and summary for the given file manifest format.
6
- * @param fileManifestType - File manifest type.
7
- * @param fileManifestFormat - File manifest format.
8
- * @param initialFilters - Filters to initialize file manifest request.
9
- * @param fileSummaryFacetName - File summary facet name.
10
- */
11
- export declare const useRequestFileManifest: (fileManifestType: FileManifestType | undefined, fileManifestFormat: ManifestDownloadFormat | undefined, initialFilters?: Filters | undefined, fileSummaryFacetName?: string) => void;