Skip to content

Commit

Permalink
tests: remove client tests that render (#3365) (#3367)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciyer authored Oct 21, 2024
1 parent 2523dec commit fbc6671
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 975 deletions.
68 changes: 0 additions & 68 deletions client/src/App.test.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,11 @@
* Tests for datasets function.
*/

import { createMemoryHistory } from "history";
import { createRoot } from "react-dom/client";
import { act } from "react-dom/test-utils";
import { Provider } from "react-redux";
import { describe, expect, it } from "vitest";

import { testClient as client } from "../api-client";
import MemoryRouter from "../components/router/MemoryRouter";
import { StateModel, globalSchema } from "../model";
import ShowDataset from "./Dataset.container";
import { mapDataset } from "./DatasetFunctions";

describe("Dataset functions", () => {
const model = new StateModel(globalSchema);
const fakeHistory = createMemoryHistory({
initialEntries: ["/"],
initialIndex: 0,
});
fakeHistory.push({
pathname: "/projects",
search: "?page=1",
});
const migration = { core: { versionUrl: "" } };
const datasets = [
{
title: "Test dataset title",
identifier: "79215657-4319-4fcf-82b9-58267f2a1db8",
name: "test-dataset-name",
created_at: "2021-06-04 04:20:24.287936+00:00",
creators: [
{
name: "First, Creator",
email: null,
affiliation: "Some Affiliation",
},
],
},
];

it("renders dataset view without crashing", async () => {
const div = document.createElement("div");
const root = createRoot(div);
await act(async () => {
root.render(
<Provider store={model.reduxStore}>
<MemoryRouter>
<ShowDataset
client={client}
datasets={datasets}
datasetId="test-dataset-name"
identifier="79215657-4319-4fcf-82b9-58267f2a1db8"
insideProject={false}
location={fakeHistory.location}
logged={true}
migration={migration}
model={model}
projectsUrl="/projects"
selectedDataset="79215657-4319-4fcf-82b9-58267f2a1db8"
/>
</MemoryRouter>
</Provider>
);
});
});

const core_dataset = {
created_at: "01/01/2001",
description: "some description for a dataset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@
* Tests for notifications
*/

import { createRoot } from "react-dom/client";
import { act } from "react-test-renderer";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { describe, expect, it } from "vitest";

import { testClient as client } from "../api-client";
import MemoryRouter from "../components/router/MemoryRouter";
import { StateModel, globalSchema } from "../model";
import AppContext from "../utils/context/appContext";
import NotificationsPage from "./Notifications.container";
import { CloseToast } from "./Notifications.present";
import { NotificationsInfo } from "./Notifications.state";
import NotificationsManager, { Notification } from "./NotificationsManager";
import NotificationsMenu from "./NotificationsMenu";
import NotificationsManager from "./NotificationsManager";

const fakeLocation = { pathname: "" };

Expand Down Expand Up @@ -120,121 +113,3 @@ describe("setup and use notification system", () => {
);
});
});

const model = new StateModel(globalSchema);
const props = { client, model };
const notifications = new NotificationsManager(model, client, fakeLocation);
addMultipleNotifications(notifications, 1);

describe("rendering NotificationsPage", () => {
it("renders NotificationsPage", async () => {
const div = document.createElement("div");
document.body.appendChild(div);
const root = createRoot(div);
await act(async () => {
root.render(
<MemoryRouter>
<AppContext.Provider value={{ client, model, notifications }}>
<NotificationsPage />
</AppContext.Provider>
</MemoryRouter>
);
});
});
});

describe("rendering Notification", () => {
const notification = model.get("notifications.all")[0];
const settings = model.get("notifications.toast");

// setup a DOM element as a render target and cleanup on exit
let div, root;
beforeEach(async () => {
await act(async () => {
div = document.createElement("div");
document.body.appendChild(div);
root = createRoot(div);
});
});
afterEach(async () => {
await act(async () => {
root.unmount(div);
div.remove();
div = null;
});
});

it("renders Notification", async () => {
await act(async () => {
root.render(
<MemoryRouter>
<Notification
type="dropdown"
notification={notification}
markRead={() => null}
/>
</MemoryRouter>
);
});

await act(async () => {
root.render(
<MemoryRouter>
<Notification
type="complete"
notification={notification}
markRead={() => null}
/>
</MemoryRouter>
);
});

await act(async () => {
const closeToast = (
<CloseToast settings={settings} markRead={() => true} />
);

root.render(
<MemoryRouter>
<Notification
type="toast"
notification={notification}
markRead={() => null}
closeToast={closeToast}
/>
</MemoryRouter>
);
});

await act(async () => {
root.render(
<MemoryRouter>
<Notification
type="custom"
present={
<div>
<span>empty</span>
</div>
}
/>
</MemoryRouter>
);
});
});
});

describe("rendering NotificationsMenu", () => {
it("renders NotificationsMenu", async () => {
const div = document.createElement("div");
const root = createRoot(div);
document.body.appendChild(div);

await act(async () => {
root.render(
<MemoryRouter>
<NotificationsMenu {...props} notifications={notifications} />
</MemoryRouter>
);
});
});
});
Loading

0 comments on commit fbc6671

Please sign in to comment.