Skip to content

Commit

Permalink
feat!: made tracking parameters to azulFileDownload required (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Nov 13, 2024
1 parent 5be2c8e commit d102cc5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/components/Export/common/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EVENT_NAME, EVENT_PARAM } from "../../../common/analytics/entities";
* @param entity_name - Entity (tab) name.
* @param toolName - Tool name.
*/
export function bulkDownloadTracking(
export function trackBulkDownloadRequested(
entity_name: string,
toolName: string
): void {
Expand All @@ -21,7 +21,7 @@ export function bulkDownloadTracking(
* Executes event tracking for the file manifest export.
* @param entity_name - Entity (tab) name.
*/
export function fileManifestTracking(entity_name: string): void {
export function trackFileManifestRequested(entity_name: string): void {
// Track the file manifest requested event.
track(EVENT_NAME.INDEX_FILE_MANIFEST_REQUESTED, {
[EVENT_PARAM.ENTITY_NAME]: entity_name,
Expand All @@ -32,7 +32,7 @@ export function fileManifestTracking(entity_name: string): void {
* Executes event tracking for the Terra export.
* @param entity_name - Entity (tab) name.
*/
export function exportToTerraTracking(entity_name: string): void {
export function trackExportToTerraRequested(entity_name: string): void {
// Track the export to terra event.
track(EVENT_NAME.INDEX_ANALYZE_IN_TERRA_REQUESTED, {
[EVENT_PARAM.ENTITY_NAME]: entity_name,
Expand All @@ -45,7 +45,7 @@ export function exportToTerraTracking(entity_name: string): void {
* @param related_entity_id - The ID of the file's dataset / project
* @param related_entity_name -The name of the file's dataset / project
*/
export function trackFileDownload(
export function trackFileDownloaded(
entity_name: string,
related_entity_id: string,
related_entity_name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ExecutionEnvironment,
FormFacet,
} from "../../common/entities";
import { bulkDownloadTracking } from "../../common/tracking";
import { trackBulkDownloadRequested } from "../../common/tracking";
import { DownloadCurlCommandNotStarted } from "./components/DownloadCurlCommandNotStarted/downloadCurlCommandNotStarted";
import { DownloadCurlCommandReady } from "./components/DownloadCurlCommandReady/downloadCurlCommandReady";

Expand Down Expand Up @@ -63,7 +63,7 @@ export const DownloadCurlCommand = ({
isLoading={isLoading}
onRequestManifest={(): void => {
// Execute GTM tracking.
bulkDownloadTracking(entityList, executionEnvironment);
trackBulkDownloadRequested(entityList, executionEnvironment);
// Request manifest.
run();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useFileManifest } from "../../../../hooks/useFileManifest/useFileManife
import { useRequestFileManifest } from "../../../../hooks/useFileManifest/useRequestFileManifest";
import { FileManifestState } from "../../../../providers/fileManifestState";
import { FormFacet, ManifestDownloadFormat } from "../../common/entities";
import { exportToTerraTracking } from "../../common/tracking";
import { trackExportToTerraRequested } from "../../common/tracking";
import { ExportToTerraNotStarted } from "./components/ExportToTerraNotStarted/exportToTerraNotStarted";
import { ExportToTerraReady } from "./components/ExportToTerraReady/exportToTerraReady";

Expand Down Expand Up @@ -57,7 +57,7 @@ export const ExportToTerra = ({
manifestDownloadFormats={manifestDownloadFormats}
onRequestManifest={(): void => {
// Execute GA tracking
exportToTerraTracking(entityList);
trackExportToTerraRequested(entityList);
// Request manifest
run();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useRequestFileManifest } from "../../../../hooks/useFileManifest/useReq
import { FileLocation } from "../../../../hooks/useRequestFileLocation";
import { FileManifestState } from "../../../../providers/fileManifestState";
import { FormFacet } from "../../common/entities";
import { fileManifestTracking } from "../../common/tracking";
import { trackFileManifestRequested } from "../../common/tracking";
import { ManifestDownloadNotStarted } from "./components/ManifestDownloadNotStarted/manifestDownloadNotStarted";
import { ManifestDownloadReady } from "./components/ManifestDownloadReady/manifestDownloadReady";

Expand Down Expand Up @@ -55,7 +55,7 @@ export const ManifestDownload = ({
formFacet={formFacet}
isLoading={isLoading}
onRequestManifest={(): void => {
fileManifestTracking(entityList);
trackFileManifestRequested(entityList);
run();
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Box } from "@mui/material";
import React, { Fragment, useEffect, useRef, useState } from "react";
import { stringifyValues } from "../../../../common/utils";
import { useFileLocation } from "../../../../hooks/useFileLocation";
import { DownloadIcon } from "../../../common/CustomIcon/components/DownloadIcon/downloadIcon";
import { LoadingIcon } from "../../../common/CustomIcon/components/LoadingIcon/loadingIcon";
import { IconButton } from "../../../common/IconButton/iconButton";
import { trackFileDownload } from "../../../Export/common/tracking";
import { trackFileDownloaded } from "../../../Export/common/tracking";
import { StyledIconButton } from "./azulFileDownload.styles";
import {
AZUL_FILE_DOWNLOAD_TEST_ID,
Expand All @@ -14,9 +13,9 @@ import {
} from "./common/constants";

export interface AzulFileDownloadProps {
entityName?: string; // The name of the file downloaded.
relatedEntityId?: string[]; // An array of IDs of the file's datasets / projects
relatedEntityName?: string[]; // An array of names of the file's datasets / projects
entityName: string; // The name of the file downloaded.
relatedEntityId: string; // An array of IDs of the file's datasets / projects
relatedEntityName: string; // An array of names of the file's datasets / projects
url?: string; // Original "file fetch URL" as returned from Azul endpoint.
}

Expand Down Expand Up @@ -57,11 +56,7 @@ export const AzulFileDownload = ({
Icon={isLoading ? LoadingIcon : DownloadIcon}
onClick={(): void => {
setIsRequestPending(true);
trackFileDownload(
entityName ?? "",
stringifyValues(relatedEntityId ?? [""]),
stringifyValues(relatedEntityName ?? [""])
);
trackFileDownloaded(entityName, relatedEntityId, relatedEntityName);
run();
}}
size="medium"
Expand Down
17 changes: 11 additions & 6 deletions tests/azulFileDownload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe("AzulFileDownload", () => {
const FILE_URL = "https://example.com/storage/file";
const MOCK_RUN = jest.fn();
const URL = "https://example.com/repository/file";
const TRACKING_PARAMETERS = {
entityName: "filename.extension",
relatedEntityId: "id",
relatedEntityName: "name",
};
beforeEach(() => {
(useFileLocation as jest.Mock).mockReturnValue({
fileUrl: undefined,
Expand All @@ -33,24 +38,24 @@ describe("AzulFileDownload", () => {
});
describe("download button", () => {
test("should render the download button", () => {
render(<AzulFileDownload url={URL} />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} url={URL} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
expect(buttonEl).not.toBeNull();
});
test("should disable the download button if URL is undefined", () => {
render(<AzulFileDownload />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
expect(buttonEl.disabled).toBe(true);
});
test("should enable the download button if a URL is provided", () => {
render(<AzulFileDownload url={URL} />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} url={URL} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
expect(buttonEl.disabled).toBe(false);
});
});
describe("download functionality", () => {
test("should call the run function when the button is clicked", () => {
render(<AzulFileDownload url={URL} />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} url={URL} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
fireEvent.click(buttonEl);
expect(MOCK_RUN).toHaveBeenCalled();
Expand All @@ -61,7 +66,7 @@ describe("AzulFileDownload", () => {
isLoading: false,
run: MOCK_RUN,
});
render(<AzulFileDownload url={URL} />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} url={URL} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
fireEvent.click(buttonEl);
await waitFor(() => {
Expand All @@ -80,7 +85,7 @@ describe("AzulFileDownload", () => {
isLoading: false,
run: MOCK_RUN,
});
render(<AzulFileDownload url={URL} />);
render(<AzulFileDownload {...TRACKING_PARAMETERS} url={URL} />);
const buttonEl = getButtonById(AZUL_FILE_REQUEST_DOWNLOAD_TEST_ID);
const anchorEl = getAnchorEl(AZUL_FILE_DOWNLOAD_TEST_ID);
fireEvent.click(buttonEl);
Expand Down

0 comments on commit d102cc5

Please sign in to comment.