Skip to content

Commit

Permalink
Migrated organization/__tests__/view.test.tsx to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmacalintal committed Jan 6, 2025
1 parent 2ae994f commit cafc879
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import OrganizationEditPage, {
} from "../../../pages/organization/edit";
import { mountWithAppContext2 } from "../../../test-util/mock-app-context";
import { Organization } from "../../../types/agent-api/resources/Organization";
import { fireEvent, screen } from "@testing-library/react";
import { fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom";
import userEvent from "@testing-library/user-event";

// Mock out the Link component, which normally fails when used outside of a Next app.
jest.mock("next/link", () => ({ children }) => <div>{children}</div>);
Expand Down
24 changes: 9 additions & 15 deletions packages/dina-ui/page-tests/organization/__tests__/view.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OrganizationDetailsPage from "../../../pages/organization/view";
import { mountWithAppContext } from "../../../test-util/mock-app-context";
import { mountWithAppContext2 } from "../../../test-util/mock-app-context";
import { Organization } from "../../../types/agent-api/resources/Organization";
import "@testing-library/jest-dom";

/** Test organization with all fields defined. */
const TEST_ORGANIZATION: Organization = {
Expand Down Expand Up @@ -35,35 +36,28 @@ jest.mock("next/router", () => ({

describe("Organization details page", () => {
it("Renders initially with a loading spinner.", () => {
const wrapper = mountWithAppContext(<OrganizationDetailsPage />, {
const wrapper = mountWithAppContext2(<OrganizationDetailsPage />, {
apiContext
});

expect(wrapper.find(".spinner-border").exists()).toEqual(true);
expect(wrapper.getByText(/loading\.\.\./i)).toBeInTheDocument();
});

it("Render the Organization details", async () => {
const wrapper = mountWithAppContext(<OrganizationDetailsPage />, {
const wrapper = mountWithAppContext2(<OrganizationDetailsPage />, {
apiContext
});

// Wait for the page to load.
await new Promise(setImmediate);
wrapper.update();

expect(wrapper.find(".spinner-border").exists()).toEqual(false);
expect(wrapper.queryByText(/loading\.\.\./i)).not.toBeInTheDocument();

// The organization's name should be rendered in a FieldView.
expect(
wrapper.containsMatchingElement(<strong>English Name</strong>)
).toEqual(true);
expect(wrapper.containsMatchingElement(<div>organization a</div>)).toEqual(
true
);
expect(wrapper.getByText("English Name")).toBeInTheDocument();
expect(wrapper.getAllByText(/organization a/i)).not.toBeNull();

// The organization's email should be rendered in a FieldView.
expect(wrapper.find(".aliases-field .field-view").text()).toEqual(
"org1, org2"
);
expect(wrapper.getByText("org1, org2")).toBeInTheDocument();
});
});

0 comments on commit cafc879

Please sign in to comment.