Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 14 additions & 44 deletions __tests__/viewModelBuilders/activity-identity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { AggregatedDataset } from "../../app/apis/azul/anvil-cmg/common/aggregatedEntities";
import type { ActivityEntity } from "../../app/apis/azul/anvil-cmg/common/entities";
import type { ActivitiesResponse } from "../../app/apis/azul/anvil-cmg/common/responses";
import { buildActivityIdentity } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
import { getChipLabels } from "./utils/identityCell";
import {
buildActivityIdentity,
buildActivityType,
} from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";

const DATASET_TITLE = "Test Dataset Title";
const DOCUMENT_ID = "test-document-id";
Expand Down Expand Up @@ -33,50 +35,18 @@ const createMockActivitiesResponse = (
}) as ActivitiesResponse;

describe("buildActivityIdentity", () => {
it("renders the document ID as a plain text title", () => {
const { title } = buildActivityIdentity(createMockActivitiesResponse());
expect(title).toEqual({ label: DOCUMENT_ID, url: "" });
});

it("renders an activity type chip", () => {
expect(
getChipLabels(buildActivityIdentity(createMockActivitiesResponse()).chips)
).toEqual(["activity type Sequencing"]);
});

it("renders an activity type chip for the Unknown activity type", () => {
const response = createMockActivitiesResponse({ activity_type: "Unknown" });
expect(getChipLabels(buildActivityIdentity(response).chips)).toEqual([
"activity type Unknown",
]);
});

it.each([
["null", null as unknown as string],
["unspecified", "Unspecified"],
])("renders no chips when the activity type is %s", (_, value) => {
const response = createMockActivitiesResponse({ activity_type: value });
expect(buildActivityIdentity(response).chips).toEqual([]);
});

it("renders the dataset title as a plain text subtitle", () => {
const { subtitle } = buildActivityIdentity(createMockActivitiesResponse());
expect(subtitle).toEqual({ label: DATASET_TITLE, url: "" });
});

it("renders the dataset count as the subtitle when there is more than one dataset", () => {
const response = createMockActivitiesResponse({}, [
{ dataset_id: ["dataset-a"], title: ["Dataset A"] },
{ dataset_id: ["dataset-b"], title: ["Dataset B"] },
]);
expect(buildActivityIdentity(response).subtitle).toEqual({
label: "2 datasets",
url: "",
it("renders the document ID as a plain text title, clamped to two lines, with no chips or subtitle", () => {
expect(buildActivityIdentity(createMockActivitiesResponse())).toEqual({
maxLines: 2,
title: { label: DOCUMENT_ID, url: "" },
});
});
});

it("omits the subtitle when there are no datasets", () => {
const response = createMockActivitiesResponse({}, []);
expect(buildActivityIdentity(response).subtitle).toBeUndefined();
describe("buildActivityType", () => {
it("renders the activity type", () => {
expect(buildActivityType(createMockActivitiesResponse()).value).toBe(
"Sequencing"
);
});
});
115 changes: 21 additions & 94 deletions __tests__/viewModelBuilders/biosample-identity.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import type {
} from "../../app/apis/azul/anvil-cmg/common/aggregatedEntities";
import type { BioSampleEntity } from "../../app/apis/azul/anvil-cmg/common/entities";
import type { BioSamplesResponse } from "../../app/apis/azul/anvil-cmg/common/responses";
import { buildBioSampleIdentity } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
import { getChipLabels } from "./utils/identityCell";
import {
buildAnatomicalSite,
buildBioSampleIdentity,
buildBioSampleType,
} from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";

const BIOSAMPLE_ID = "test-biosample-id";
const DATASET_TITLE = "Test Dataset Title";
const UNSPECIFIED_CASES: [string, null | string][] = [
["null", null],
["unspecified", "Unspecified"],
];

/**
* Creates a mock BioSamplesResponse for testing.
Expand Down Expand Up @@ -43,98 +42,26 @@ const createMockBioSamplesResponse = (
}) as BioSamplesResponse;

describe("buildBioSampleIdentity", () => {
it("renders the biosample ID as a plain text title", () => {
const { title } = buildBioSampleIdentity(createMockBioSamplesResponse());
expect(title).toEqual({ label: BIOSAMPLE_ID, url: "" });
});

it("renders biosample type, anatomical site, then organism type chips", () => {
const response = createMockBioSamplesResponse({}, [
{ organism_type: ["Human"] },
{ organism_type: ["Mouse"] },
]);
expect(getChipLabels(buildBioSampleIdentity(response).chips)).toEqual([
"biosample type Tissue",
"anatomical site Blood",
"organism type Human",
"organism type Mouse",
]);
});

it.each(UNSPECIFIED_CASES)(
"omits the biosample type chip when the biosample type is %s",
(_, value) => {
const response = createMockBioSamplesResponse({ biosample_type: value });
expect(getChipLabels(buildBioSampleIdentity(response).chips)).toEqual([
"anatomical site Blood",
"organism type Human",
]);
}
);

it.each(UNSPECIFIED_CASES)(
"omits the anatomical site chip when the anatomical site is %s",
(_, value) => {
const response = createMockBioSamplesResponse({ anatomical_site: value });
expect(getChipLabels(buildBioSampleIdentity(response).chips)).toEqual([
"biosample type Tissue",
"organism type Human",
]);
}
);

it.each([
["empty", []],
["null", [null]],
["unspecified", ["Unspecified"]],
])("omits organism type chips when the organism type is %s", (_, value) => {
const response = createMockBioSamplesResponse({}, [
{ organism_type: value },
]);
expect(getChipLabels(buildBioSampleIdentity(response).chips)).toEqual([
"biosample type Tissue",
"anatomical site Blood",
]);
});

it("renders one organism type chip per unique organism type across donors", () => {
const response = createMockBioSamplesResponse({}, [
{ organism_type: ["Human"] },
{ organism_type: ["Human"] },
]);
expect(getChipLabels(buildBioSampleIdentity(response).chips)).toEqual([
"biosample type Tissue",
"anatomical site Blood",
"organism type Human",
]);
it("renders the biosample ID as a plain text title, clamped to two lines, with no chips or subtitle", () => {
expect(buildBioSampleIdentity(createMockBioSamplesResponse())).toEqual({
maxLines: 2,
title: { label: BIOSAMPLE_ID, url: "" },
});
});
});

it("renders no chips when every biosample field is unspecified", () => {
const response = createMockBioSamplesResponse(
{ anatomical_site: null, biosample_type: null },
[]
describe("buildAnatomicalSite", () => {
it("renders the anatomical site", () => {
expect(buildAnatomicalSite(createMockBioSamplesResponse()).value).toBe(
"Blood"
);
expect(buildBioSampleIdentity(response).chips).toEqual([]);
});

it("renders the dataset title as a plain text subtitle", () => {
const { subtitle } = buildBioSampleIdentity(createMockBioSamplesResponse());
expect(subtitle).toEqual({ label: DATASET_TITLE, url: "" });
});

it("renders the dataset count as the subtitle when there is more than one dataset", () => {
const response = createMockBioSamplesResponse({}, undefined, [
{ dataset_id: ["dataset-a"], title: ["Dataset A"] },
{ dataset_id: ["dataset-b"], title: ["Dataset B"] },
]);
expect(buildBioSampleIdentity(response).subtitle).toEqual({
label: "2 datasets",
url: "",
});
});
});

it("omits the subtitle when there are no datasets", () => {
const response = createMockBioSamplesResponse({}, undefined, []);
expect(buildBioSampleIdentity(response).subtitle).toBeUndefined();
describe("buildBioSampleType", () => {
it("renders the biosample type", () => {
expect(buildBioSampleType(createMockBioSamplesResponse()).value).toBe(
"Tissue"
);
});
});
93 changes: 27 additions & 66 deletions __tests__/viewModelBuilders/buildFileDownload.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { AzulFileDownloadProps } from "@databiosphere/findable-ui/lib/components/Index/components/AzulFileDownload/azulFileDownload";
import { ReactElement } from "react";
import { FilesResponse } from "../../app/apis/azul/anvil-cmg/common/responses";
import { buildFileDownloadWithTooltip } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
import { buildFileDownloadMenu } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";

/**
* Creates a mock FilesResponse with configurable file and dataset values.
Expand Down Expand Up @@ -52,6 +50,7 @@ const createMockFilesResponse = (
file_format: "bam",
file_id: "file-123",
file_name: "sample.bam",
file_path: "folder/sample.bam",
file_size: 1024,
file_type: "Analysis",
...overrides,
Expand All @@ -64,19 +63,17 @@ const createMockFilesResponse = (
],
});

describe("buildFileDownload", () => {
describe("buildFileDownloadMenu", () => {
describe("url prop based on azul_mirror_uri", () => {
it("returns undefined url when azul_mirror_uri is null", () => {
const response = createMockFilesResponse({
azul_mirror_uri: null,
azul_url: "https://service.azul.data/repository/files/file-123",
});

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props.url
).toBeUndefined();
expect(result.url).toBeUndefined();
});

it("returns undefined url when azul_mirror_uri is empty string", () => {
Expand All @@ -85,11 +82,9 @@ describe("buildFileDownload", () => {
azul_url: "https://service.azul.data/repository/files/file-123",
});

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props.url
).toBeUndefined();
expect(result.url).toBeUndefined();
});

it("returns azul_url when azul_mirror_uri has a value", () => {
Expand All @@ -99,11 +94,9 @@ describe("buildFileDownload", () => {
azul_url: azulUrl,
});

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props.url
).toBe(azulUrl);
expect(result.url).toBe(azulUrl);
});

it("returns azul_url value exactly as provided when mirror uri exists", () => {
Expand All @@ -114,11 +107,9 @@ describe("buildFileDownload", () => {
azul_url: azulUrl,
});

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props.url
).toBe(azulUrl);
expect(result.url).toBe(azulUrl);
});
});

Expand All @@ -128,12 +119,9 @@ describe("buildFileDownload", () => {
file_name: "my-sample-file.bam",
});

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props
.entityName
).toBe("my-sample-file.bam");
expect(result.entityName).toBe("my-sample-file.bam");
});

it("returns correct relatedEntityId from dataset_id", () => {
Expand All @@ -142,12 +130,9 @@ describe("buildFileDownload", () => {
{ dataset_id: ["my-dataset-id-123"] }
);

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props
.relatedEntityId
).toBe("my-dataset-id-123");
expect(result.relatedEntityId).toBe("my-dataset-id-123");
});

it("returns correct relatedEntityName from dataset title", () => {
Expand All @@ -156,39 +141,17 @@ describe("buildFileDownload", () => {
{ title: ["My Research Dataset"] }
);

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props
.relatedEntityName
).toBe("My Research Dataset");
expect(result.relatedEntityName).toBe("My Research Dataset");
});
});

describe("tooltip title", () => {
it("returns tooltip message when download is disabled", () => {
const response = createMockFilesResponse({
azul_mirror_uri: null,
});

const result = buildFileDownloadWithTooltip(response);

expect(result.title).toBe(
"Direct file downloads are currently only available for open-access files."
);
});
describe("drsUri", () => {
it("returns the file's DRS URI", () => {
const result = buildFileDownloadMenu(createMockFilesResponse());

it("returns enabled tooltip message when download is available", () => {
const response = createMockFilesResponse({
azul_mirror_uri: "s3://bucket/path/to/file.bam",
azul_url: "https://service.azul.data/repository/files/file-123",
});

const result = buildFileDownloadWithTooltip(response);

expect(result.title).toBe(
"This open-access file is freely downloadable from AWS Open Data, with no data transfer fees."
);
expect(result.drsUri).toBe("drs://data.azul/file-123");
});
});

Expand All @@ -206,11 +169,10 @@ describe("buildFileDownload", () => {
}
);

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props
).toEqual({
expect(result).toEqual({
drsUri: "drs://data.azul/file-123",
entityName: "research-data.bam",
relatedEntityId: "dataset-abc",
relatedEntityName: "Genomics Research Project",
Expand All @@ -231,11 +193,10 @@ describe("buildFileDownload", () => {
}
);

const result = buildFileDownloadWithTooltip(response);
const result = buildFileDownloadMenu(response);

expect(
(result.children as ReactElement<AzulFileDownloadProps>).props
).toEqual({
expect(result).toEqual({
drsUri: "drs://data.azul/file-123",
entityName: "research-data.bam",
relatedEntityId: "dataset-abc",
relatedEntityName: "Genomics Research Project",
Expand Down
Loading