Skip to content

Commit

Permalink
#1803 add test
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 8, 2024
1 parent 152f0a6 commit ec05a48
Showing 1 changed file with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,43 @@ describe("MenuOptionDesktopEditorOpenSingle", () => {
);
});

it("should render without errors", () => {
const component = render(
<MenuOptionDesktopEditorOpenSingle
isDirectory={true}
subPath=""
collections={false}
isReadOnly={true}
/>
);
const element = screen.getByTestId("menu-option-desktop-editor-open-single");
const displayTextTheoryData = [
{ isDirectory: true, expectedText: localization.MessageDesktopEditorOpenSingleFolder.en },
{ isDirectory: false, expectedText: localization.MessageDesktopEditorOpenSingleFile.en }
];

test.each(displayTextTheoryData)(
"should render text correctly for isDirectory=$isDirectory",
({ isDirectory, expectedText }) => {
const mockGetIConnectionDefaultFeatureToggle = {
statusCode: 200,
data: {
openEditorEnabled: true
} as IEnvFeatures
} as IConnectionDefault;

const useFetchSpy = jest
.spyOn(useFetch, "default")
.mockImplementationOnce(() => mockGetIConnectionDefaultFeatureToggle);

const component = render(
<MenuOptionDesktopEditorOpenSingle
isDirectory={isDirectory}
subPath="/test.jpg"
collections={false}
isReadOnly={true}
/>
);

expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(element).toBe("");
});
const element = component.getByTestId("menu-option-desktop-editor-open-single");

expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(element.textContent).toBe(expectedText);
expect(useFetchSpy).toHaveBeenCalled();
component.unmount();
}
);

it("should call OpenDesktopSingle when MenuOption is clicked", () => {
const mockGetIConnectionDefaultFeatureToggle = {
Expand Down

0 comments on commit ec05a48

Please sign in to comment.