Skip to content

Commit

Permalink
Merge pull request #578 from CBIIT/CRDCDH-1674-update
Browse files Browse the repository at this point in the history
CRDCDH-1674 Fix Orphaned Files error being moved from submission to QC Results
  • Loading branch information
amattu2 authored Jan 3, 2025
2 parents d0c7583 + db0ccaa commit b2f17c2
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 102 deletions.
260 changes: 240 additions & 20 deletions src/components/Contexts/SubmissionContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { act, render, renderHook, waitFor } from "@testing-library/react";
import { MockedProvider, MockedResponse } from "@apollo/client/testing";
import { GraphQLError } from "graphql";
import { SubmissionCtxStatus, SubmissionProvider, useSubmissionContext } from "./SubmissionContext";
import { GET_SUBMISSION, GetSubmissionInput, GetSubmissionResp } from "../../graphql";
import {
GET_SUBMISSION,
GetSubmissionInput,
GetSubmissionResp,
SUBMISSION_QC_RESULTS,
SubmissionQCResultsResp,
} from "../../graphql";

const mockStartPolling = jest.fn();
const mockStopPolling = jest.fn();
Expand Down Expand Up @@ -100,7 +106,23 @@ describe("useSubmissionContext", () => {
},
];

expect(() => render(<TestParent mocks={mocks} _id="test-nominal-id" />)).not.toThrow();
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: null,
},
},
},
];

expect(() =>
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-nominal-id" />)
).not.toThrow();
});
});

Expand All @@ -119,8 +141,23 @@ describe("SubmissionProvider", () => {
error: new Error("Network error"),
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: null,
},
},
},
];

const { getByTestId } = render(<TestParent mocks={mocks} _id="test-network-error-id" />);
const { getByTestId } = render(
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-network-error-id" />
);

await waitFor(() => expect(getByTestId("ctx-status")).toHaveTextContent("ERROR"));
});
Expand All @@ -137,8 +174,23 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: null,
},
},
},
];

const { getByTestId } = render(<TestParent mocks={mocks} _id="test-graphql-error-id" />);
const { getByTestId } = render(
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-graphql-error-id" />
);

await waitFor(() => expect(getByTestId("ctx-status")).toHaveTextContent("ERROR"));
});
Expand All @@ -159,8 +211,23 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: null,
},
},
},
];

const { getByTestId } = render(<TestParent mocks={mocks} _id="test-null-id" />);
const { getByTestId } = render(
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-null-id" />
);

await waitFor(() => expect(getByTestId("ctx-status")).toHaveTextContent("ERROR"));
});
Expand Down Expand Up @@ -188,8 +255,26 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

const { getByTestId } = render(<TestParent mocks={mocks} _id="test-valid-id" />);
const { getByTestId } = render(
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-valid-id" />
);

await waitFor(() => expect(getByTestId("ctx-status")).toHaveTextContent("LOADED"));
});
Expand Down Expand Up @@ -223,10 +308,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-validating-id" />);
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-validating-id" />);

await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(1));
// Should poll getSubmission + submissionQCResults
await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(2));
expect(mockStopPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -259,10 +361,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-validating-id" />);
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-validating-id" />);

await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(1));
// Should stop polling getSubmission + submissionQCResults
await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(2));
expect(mockStartPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -295,10 +414,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-uploading-id" />);
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-uploading-id" />);

await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(1));
// Should poll getSubmission + submissionQCResults
await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(2));
expect(mockStopPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -331,10 +467,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-uploading-id" />);
// Should stop polling getSubmission + submissionQCResults
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-uploading-id" />);

await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(1));
await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(2));
expect(mockStartPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -363,10 +516,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-deleting-id" />);
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-deleting-id" />);

await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(1));
// Should poll getSubmission + submissionQCResults
await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(2));
expect(mockStopPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -395,10 +565,27 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

render(<TestParent mocks={mocks} _id="test-deleting-id" />);
render(<TestParent mocks={[...mocks, ...qcMocks]} _id="test-deleting-id" />);

await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(1));
// Should stop polling getSubmission + submissionQCResults
await waitFor(() => expect(mockStopPolling).toHaveBeenCalledTimes(2));
expect(mockStartPolling).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -430,10 +617,26 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

const { result } = renderHook(() => useSubmissionContext(), {
wrapper: ({ children }) => (
<TestParent mocks={mocks} _id="test-wrapper-id">
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-wrapper-id">
{children}
</TestParent>
),
Expand All @@ -447,6 +650,7 @@ describe("SubmissionProvider", () => {
startPolling(1000);
});

await waitFor(() => expect(mockStartPolling).toHaveBeenCalledTimes(2));
expect(mockStartPolling).toHaveBeenCalledWith(1000);

act(() => {
Expand Down Expand Up @@ -479,10 +683,26 @@ describe("SubmissionProvider", () => {
},
},
];
const qcMocks: MockedResponse<SubmissionQCResultsResp<true>>[] = [
{
request: {
query: SUBMISSION_QC_RESULTS,
},
variableMatcher: () => true,
result: {
data: {
submissionQCResults: {
total: 0,
results: [],
},
},
},
},
];

const { result } = renderHook(() => useSubmissionContext(), {
wrapper: ({ children }) => (
<TestParent mocks={mocks} _id="test-polling-id">
<TestParent mocks={[...mocks, ...qcMocks]} _id="test-polling-id">
{children}
</TestParent>
),
Expand Down
Loading

0 comments on commit b2f17c2

Please sign in to comment.