-
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.
feat(disable export button): Disable export button when no records av…
…ailable (#739) * disable export button when no records displayed * add tooltip only when export button disabled * wip useOsUrl not found * add role to button * useOsUrl is not a function wip * delete other unused code * useLocation() may be used only in the context of a <Router> component. * useOsData is not a function * still not a function... * Component finally rendering, changed import to use '@/' * wip mock disable export button * test hover disabled export button * remove unused export and return handleExport if no records/disabled even if button is enabled * change role to data-testid to fix e2e --------- Co-authored-by: Tiffany Vu <[email protected]> Co-authored-by: Tiffany Vu <[email protected]>
- Loading branch information
1 parent
d2f2c68
commit bf9455f
Showing
8 changed files
with
32,264 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
32 changes: 32 additions & 0 deletions
32
react-app/src/components/Opensearch/main/Filtering/Export/Export.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,32 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { describe, expect, test, vi, beforeEach } from "vitest"; | ||
import { OsExportData } from "@/components"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
vi.mock("@/components/Opensearch/main/useOpensearch.ts", () => ({ | ||
useOsUrl: vi.fn(), | ||
})); | ||
|
||
describe("Tooltip component within export button", () => { | ||
beforeEach(() => { | ||
render(<OsExportData columns={[]} disabled={true} />); | ||
}); | ||
|
||
test("Tooltip content hidden when not hovering", async () => { | ||
const tooltipTrigger = screen.queryByTestId("tooltip-trigger"); | ||
expect(tooltipTrigger).toBeInTheDocument(); | ||
|
||
const tooltipContent = screen.queryByText("No records available"); | ||
expect(tooltipContent).not.toBeInTheDocument(); | ||
}); | ||
|
||
test("Tooltip content shown on hover", async () => { | ||
const tooltipTrigger = screen.queryByTestId("tooltip-trigger"); | ||
expect(tooltipTrigger).toBeDisabled(); | ||
|
||
userEvent.hover(screen.queryByTestId("tooltip-trigger")); | ||
|
||
await waitFor(() => screen.getByTestId("tooltip-content")); | ||
expect(screen.queryAllByText("No records available")[0]).toBeVisible(); | ||
}); | ||
}); |
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
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,26 @@ | ||
import * as React from "react"; | ||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"; | ||
import { cn } from "@/utils"; | ||
const TooltipProvider = TooltipPrimitive.Provider | ||
|
||
const Tooltip = TooltipPrimitive.Root | ||
|
||
const TooltipTrigger = TooltipPrimitive.Trigger | ||
|
||
const TooltipContent = React.forwardRef< | ||
React.ElementRef<typeof TooltipPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> | ||
>(({ className, sideOffset = 4, ...props }, ref) => ( | ||
<TooltipPrimitive.Content | ||
ref={ref} | ||
sideOffset={sideOffset} | ||
className={cn( | ||
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
TooltipContent.displayName = TooltipPrimitive.Content.displayName | ||
|
||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } |
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