This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
generated from MeasureAuthoringTool/madie-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAT-5981 added test suite for DataElementActions component
- Loading branch information
1 parent
935c330
commit 6157268
Showing
4 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...nel/ElementsTab/Elements/DataElementsTable/dataElementActions/DataElementActions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from "react"; | ||
import { render, screen, within } from "@testing-library/react"; | ||
import DataElementActions from "./DataElementActions"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const mockOnDelete = jest.fn(); | ||
const mockOnView = jest.fn(); | ||
|
||
describe("DatElementActions", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("Should display only View action button for a non owner", () => { | ||
render( | ||
<DataElementActions | ||
elementId={"exampleId"} | ||
canView={true} | ||
onDelete={mockOnDelete} | ||
onView={mockOnView} | ||
canEdit={false} | ||
/> | ||
); | ||
|
||
const viewButton = screen.getByRole("button", { name: "View" }); | ||
expect(viewButton).toBeInTheDocument(); | ||
userEvent.click(viewButton); | ||
expect(mockOnView).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Should display View action button along with popover for the owner", async () => { | ||
render( | ||
<DataElementActions | ||
elementId={"exampleId"} | ||
canView={true} | ||
onDelete={mockOnDelete} | ||
onView={mockOnView} | ||
canEdit={true} | ||
/> | ||
); | ||
|
||
const viewButton = screen.getByRole("button", { name: "View" }); | ||
expect(viewButton).toBeInTheDocument(); | ||
userEvent.click(viewButton); | ||
const popOver = await screen.findByTestId("popover-content"); | ||
const editButton = within(popOver).getByRole("button", { name: "Edit" }); | ||
userEvent.click(editButton); | ||
expect(mockOnView).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Should display the delete button if the user is owner and deletes a dataElement when clicked", async () => { | ||
render( | ||
<DataElementActions | ||
elementId={"exampleId"} | ||
canView={true} | ||
onDelete={mockOnDelete} | ||
onView={mockOnView} | ||
canEdit={true} | ||
/> | ||
); | ||
|
||
const viewButton = screen.getByRole("button", { name: "View" }); | ||
expect(viewButton).toBeInTheDocument(); | ||
userEvent.click(viewButton); | ||
const popOver = await screen.findByTestId("popover-content"); | ||
const deleteButton = within(popOver).getByRole("button", { | ||
name: "Delete", | ||
}); | ||
userEvent.click(deleteButton); | ||
expect(mockOnDelete).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
8 changes: 4 additions & 4 deletions
8
...s/DataElementsTable/DatElementActions.tsx → ...dataElementActions/DataElementActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters