Skip to content

Commit

Permalink
Merge pull request #83 from craigatk/cleanup-message
Browse files Browse the repository at this point in the history
(feature) Show message on UI when report was cleaned up
  • Loading branch information
craigatk authored Apr 29, 2020
2 parents b11349c + f77dbe8 commit 1d10daa
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 79 deletions.
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"clean-results": "rimraf test-results/*.xml"
},
"devDependencies": {
"@testing-library/jest-dom": "5.3.0",
"@testing-library/react": "10.0.2",
"@testing-library/jest-dom": "5.5.0",
"@testing-library/react": "10.0.3",
"@types/jest": "25.1.4",
"axios-mock-adapter": "1.17.0",
"chai-colors": "1.0.1",
Expand Down
12 changes: 8 additions & 4 deletions ui/src/Dashboard/__tests__/TestRunCleanupDate.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, getNodeText } from "@testing-library/react";
import { render, getNodeText, waitFor } from "@testing-library/react";
import { axiosInstanceWithoutCache } from "../../service/AxiosService";
import TestRunCleanupDate from "../TestRunCleanupDate";
import {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("TestRunCleanupDate", () => {
await findByTestId("test-run-header-pin-link");
});

it("when cleanup not enabled should not display anything", () => {
it("when cleanup not enabled should not display anything", async () => {
const cleanupConfig = {
enabled: false,
} as ServerCleanupConfig;
Expand All @@ -126,7 +126,11 @@ describe("TestRunCleanupDate", () => {
</PinState>
);

expect(queryByTestId("test-run-header-unpin-link")).toBeNull();
expect(queryByTestId("test-run-header-pin-link")).toBeNull();
await waitFor(() =>
expect(queryByTestId("test-run-header-unpin-link")).toBeNull()
);
await waitFor(() =>
expect(queryByTestId("test-run-header-pin-link")).toBeNull()
);
});
});
9 changes: 8 additions & 1 deletion ui/src/Loading/LoadingSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makeStyles } from "@material-ui/core/styles";
import LinearProgress from "@material-ui/core/LinearProgress";
import LoadingState from "./LoadingState";
import { Paper, Typography } from "@material-ui/core";
import CleanLink from "../Link/CleanLink";

const useStyles = makeStyles((theme) => ({
progress: {
Expand All @@ -24,6 +25,10 @@ interface LoadingSectionProps {
errorComponent?: any;
}

const reloadPage = () => {
window.location.reload();
};

const LoadingSection = ({
loadingState,
successComponent,
Expand All @@ -40,7 +45,9 @@ const LoadingSection = ({
<Paper elevation={1} className={classes.errorPaper}>
<Typography>
Error loading data from server. Please{" "}
<a href="javascript:window.location.reload()">refresh the page</a>{" "}
<CleanLink to="" onClick={reloadPage}>
refresh the page
</CleanLink>{" "}
and try again.
</Typography>
</Paper>
Expand Down
8 changes: 4 additions & 4 deletions ui/src/Pin/__tests__/PinSideMenuItem.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render } from "@testing-library/react";
import { render, waitFor } from "@testing-library/react";
import { axiosInstanceWithoutCache } from "../../service/AxiosService";
import PinSideMenuItem from "../PinSideMenuItem";
import {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe("PinSideMenuItem", () => {
await findByTestId("nav-link-pin");
});

it("when cleanup not enabled should not display anything", () => {
it("when cleanup not enabled should not display anything", async () => {
const cleanupConfig = {
enabled: false,
} as ServerCleanupConfig;
Expand All @@ -115,7 +115,7 @@ describe("PinSideMenuItem", () => {
</PinState>
);

expect(queryByTestId("nav-link-unpin")).toBeNull();
expect(queryByTestId("nav-link-pin")).toBeNull();
await waitFor(() => expect(queryByTestId("nav-link-unpin")).toBeNull());
await waitFor(() => expect(queryByTestId("nav-link-pin")).toBeNull());
});
});
8 changes: 4 additions & 4 deletions ui/src/TestCase/__tests__/TestCasePage.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, wait } from "@testing-library/react";
import { TestCase, TestSuite } from "../../model/TestRunModel";
import { render, waitFor } from "@testing-library/react";
import { TestCase } from "../../model/TestRunModel";
import { axiosInstance } from "../../service/AxiosService";
import TestCasePage from "../TestCasePage";

Expand Down Expand Up @@ -50,7 +50,7 @@ describe("TestCasePage", () => {
/>
);

await wait(() => getByTestId("test-case-details"));
await waitFor(() => getByTestId("test-case-details"));

expect(queryByTestId("test-case-details")).not.toBeNull();
expect(queryByTestId("loading-section-error")).toBeNull();
Expand All @@ -75,7 +75,7 @@ describe("TestCasePage", () => {
/>
);

await wait(() => getByTestId("loading-section-error"));
await waitFor(() => getByTestId("loading-section-error"));

expect(queryByTestId("loading-section-error")).not.toBeNull();
expect(queryByTestId("test-case-details")).toBeNull();
Expand Down
4 changes: 2 additions & 2 deletions ui/src/TestOutput/__tests__/TestSuiteSystemErr.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, wait, getNodeText } from "@testing-library/react";
import { render, waitFor, getNodeText } from "@testing-library/react";
import { TestSuiteOutput } from "../../model/TestRunModel";
import { axiosInstance } from "../../service/AxiosService";
import TestSuiteSystemErr from "../TestSuiteSystemErr";
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("TestSuiteSystemErr", () => {
<TestSuiteSystemErr publicId={publicId} testSuiteIdx={testSuiteIdx} />
);

await wait(() => getByTestId("code-text"));
await waitFor(() => getByTestId("code-text"));

expect(queryByTestId("code-text")).not.toBeNull();
expect(queryByTestId("loading-section-error")).toBeNull();
Expand Down
4 changes: 2 additions & 2 deletions ui/src/TestOutput/__tests__/TestSuiteSystemOut.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, wait, getNodeText } from "@testing-library/react";
import { render, waitFor, getNodeText } from "@testing-library/react";
import { TestSuiteOutput } from "../../model/TestRunModel";
import { axiosInstance } from "../../service/AxiosService";
import TestSuiteSystemOut from "../TestSuiteSystemOut";
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("TestSuiteSystemOut", () => {
<TestSuiteSystemOut publicId={publicId} testSuiteIdx={testSuiteIdx} />
);

await wait(() => getByTestId("code-text"));
await waitFor(() => getByTestId("code-text"));

expect(queryByTestId("code-text")).not.toBeNull();
expect(queryByTestId("loading-section-error")).toBeNull();
Expand Down
6 changes: 3 additions & 3 deletions ui/src/TestOutput/__tests__/TestSystemOutput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, wait } from "@testing-library/react";
import { render, waitFor } from "@testing-library/react";
import { TestSuiteOutput } from "../../model/TestRunModel";
import { axiosInstance } from "../../service/AxiosService";
import TestSuiteOutputType from "../../service/TestSuiteOutputType";
Expand Down Expand Up @@ -42,7 +42,7 @@ describe("TestSystemOut", () => {
/>
);

await wait(() => getByTestId("code-text"));
await waitFor(() => getByTestId("code-text"));

expect(queryByTestId("code-text")).not.toBeNull();
expect(queryByTestId("loading-section-error")).toBeNull();
Expand All @@ -67,7 +67,7 @@ describe("TestSystemOut", () => {
/>
);

await wait(() => getByTestId("loading-section-error"));
await waitFor(() => getByTestId("loading-section-error"));

expect(queryByTestId("loading-section-error")).not.toBeNull();
expect(queryByTestId("code-text")).toBeNull();
Expand Down
33 changes: 23 additions & 10 deletions ui/src/TestResults/TestResultsProcessingCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ const useStyles = makeStyles((theme) => ({
},
}));

const resultsAreStillProcessing = (
processing: TestResultsProcessing
): boolean => {
return (
!processing ||
processing.status === TestResultsProcessingStatus.RECEIVED ||
processing.status === TestResultsProcessingStatus.PROCESSING
);
};

const TestResultsProcessingCheck = ({
publicId,
processingSucceeded,
Expand All @@ -46,16 +56,6 @@ const TestResultsProcessingCheck = ({
LoadingState.Loading
);

const resultsAreStillProcessing = (
processing: TestResultsProcessing
): boolean => {
return (
!processing ||
processing.status === TestResultsProcessingStatus.RECEIVED ||
processing.status === TestResultsProcessingStatus.PROCESSING
);
};

const loadTestResultsProcessing = () => {
fetchTestResultsProcessing(publicId)
.then((response) => {
Expand All @@ -82,6 +82,9 @@ const TestResultsProcessingCheck = ({
const resultsProcessingFailed =
resultsProcessing &&
resultsProcessing.status === TestResultsProcessingStatus.ERROR;
const resultsDeleted =
resultsProcessing &&
resultsProcessing.status === TestResultsProcessingStatus.DELETED;

if (resultsProcessingSuccessful) {
processingSucceeded();
Expand Down Expand Up @@ -112,6 +115,16 @@ const TestResultsProcessingCheck = ({
</pre>
</Paper>
);
} else if (resultsDeleted) {
return (
<Paper
elevation={2}
className={classes.paper}
data-testid="results-deleted"
>
<Typography>Test results cleaned up to save disk space</Typography>
</Paper>
);
} else {
return null;
}
Expand Down
106 changes: 106 additions & 0 deletions ui/src/TestResults/__tests__/TestResultsProcessingCheck.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render, waitFor } from "@testing-library/react";
import { axiosInstanceWithoutCache } from "../../service/AxiosService";
import MockAdapter from "axios-mock-adapter";
import {
TestResultsProcessing,
TestResultsProcessingStatus,
} from "../../model/TestRunModel";
import TestResultsProcessingCheck from "../TestResultsProcessingCheck";

describe("TestResultsProcessingCheck", () => {
let mockAxios;

const publicId = "12345";

beforeEach(() => {
// @ts-ignore
mockAxios = new MockAdapter(axiosInstanceWithoutCache);
});

afterEach(() => {
mockAxios.restore();
});

const mockProcessingStatus = (status: TestResultsProcessingStatus) => {
const processingStatus = {
id: publicId,
status,
} as TestResultsProcessing;

mockAxios
.onGet(`http://localhost:8080/results/${publicId}/status`)
.reply(200, processingStatus);
};

it("should display message when results still processing", async () => {
const succeededFunc = jest.fn();

mockProcessingStatus(TestResultsProcessingStatus.PROCESSING);

const { findByTestId } = render(
<TestResultsProcessingCheck
publicId={publicId}
processingSucceeded={succeededFunc}
refreshInterval={5000}
/>
);

await findByTestId("results-still-processing");

expect(succeededFunc).not.toHaveBeenCalled();
});

it("should display failure message when results processing failed", async () => {
const succeededFunc = jest.fn();

mockProcessingStatus(TestResultsProcessingStatus.ERROR);

const { findByTestId } = render(
<TestResultsProcessingCheck
publicId={publicId}
processingSucceeded={succeededFunc}
refreshInterval={5000}
/>
);

await findByTestId("results-processing-failed");

expect(succeededFunc).not.toHaveBeenCalled();
});

it("should display message when results were deleted", async () => {
const succeededFunc = jest.fn();

mockProcessingStatus(TestResultsProcessingStatus.DELETED);

const { findByTestId } = render(
<TestResultsProcessingCheck
publicId={publicId}
processingSucceeded={succeededFunc}
refreshInterval={5000}
/>
);

await findByTestId("results-deleted");

expect(succeededFunc).not.toHaveBeenCalled();
});

it("should call success function when results successfully processed", async () => {
const succeededFunc = jest.fn();

mockProcessingStatus(TestResultsProcessingStatus.SUCCESS);

render(
<TestResultsProcessingCheck
publicId={publicId}
processingSucceeded={succeededFunc}
refreshInterval={5000}
/>
);

await waitFor(() => expect(succeededFunc).toHaveBeenCalled());
});
});
6 changes: 3 additions & 3 deletions ui/src/TestRun/__tests__/TestRunAllTests.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import MockAdapter from "axios-mock-adapter";
import { render, wait } from "@testing-library/react";
import { render, waitFor } from "@testing-library/react";
import { TestRun, TestSuite } from "../../model/TestRunModel";
import TestRunAllTests from "../TestRunAllTests";
import { axiosInstance } from "../../service/AxiosService";
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("TestRunAllTests", () => {
<TestRunAllTests publicId={publicId} />
);

await wait(() => getByTestId("test-suite-list"));
await waitFor(() => getByTestId("test-suite-list"));

expect(queryByTestId("test-suite-list")).not.toBeNull();
expect(queryByTestId("loading-section-error")).toBeNull();
Expand All @@ -55,7 +55,7 @@ describe("TestRunAllTests", () => {
<TestRunAllTests publicId={publicId} />
);

await wait(() => getByTestId("loading-section-error"));
await waitFor(() => getByTestId("loading-section-error"));

expect(queryByTestId("loading-section-error")).not.toBeNull();
expect(queryByTestId("test-suite-list")).toBeNull();
Expand Down
Loading

0 comments on commit 1d10daa

Please sign in to comment.