@agility/plenum-ui 2.1.20-rc6 → 2.1.20-rc7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ import { vi } from "vitest";
2
+ import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
3
+ import DropdownWithMultiSelect from "../DropdownWithMultiSelect";
4
+ import { render, screen, fireEvent, waitFor } from "@testing-library/react";
5
+ import Checkbox from "@/stories/molecules/inputs/checkbox/Checkbox";
6
+ import { DynamicIcon } from "@/stories/atoms/icons";
7
+
8
+ const defaultProps = {
9
+ label: "Filters",
10
+ options: [
11
+ {
12
+ label: "Option 1",
13
+ key: "1",
14
+ isSelected: false,
15
+ onClick: vi.fn()
16
+ },
17
+ {
18
+ label: "Option 2",
19
+ key: "2",
20
+ isSelected: false,
21
+ onClick: vi.fn()
22
+ },
23
+ {
24
+ label: "Option 3",
25
+ key: "3",
26
+ isSelected: false,
27
+ onClick: vi.fn()
28
+ }
29
+ ]
30
+ };
31
+
32
+ describe("DropdownWithMultiSelect", () => {
33
+ beforeAll(() => {
34
+ class ResizeObserver {
35
+ observe() {}
36
+ unobserve() {}
37
+ disconnect() {}
38
+ }
39
+ vi.stubGlobal("ResizeObserver", ResizeObserver);
40
+ });
41
+
42
+ it("renders a button", () => {
43
+ const { container } = render(<DropdownWithMultiSelect {...defaultProps} />);
44
+ const button = screen.getByRole("button", { name: /Filters/i });
45
+ expect(button).toBeInTheDocument();
46
+ const icon = container.querySelector("svg");
47
+ expect(icon).toBeInTheDocument();
48
+ });
49
+
50
+ it("opens the popover and shows options", async () => {
51
+ render(<DropdownWithMultiSelect {...defaultProps} />);
52
+ const button = screen.getByRole("button", { name: /Filters/i });
53
+ fireEvent.click(button);
54
+ const checkboxes = screen.getAllByRole("checkbox");
55
+ expect(checkboxes).toHaveLength(3);
56
+ });
57
+
58
+ it("calls the onClick for an option", async () => {
59
+ const optionSpy = vi.fn();
60
+ render(
61
+ <DropdownWithMultiSelect {...defaultProps} options={[{ ...defaultProps.options[0], onClick: optionSpy }]} />
62
+ );
63
+ const button = screen.getByRole("button", { name: /Filters/i });
64
+ fireEvent.click(button);
65
+ const checkbox = screen.getByRole("checkbox", { name: /Option 1/i });
66
+ fireEvent.click(checkbox);
67
+ await waitFor(() => expect(optionSpy).toHaveBeenCalled());
68
+ });
69
+ });
package/tsconfig.json CHANGED
@@ -23,8 +23,7 @@
23
23
  "paths": {
24
24
  "@/*": ["./*"]
25
25
  },
26
- "types": ["vitest/globals"],
27
- "typeRoots": ["./node_modules/@types"]
26
+ "types": ["vitest"]
28
27
  },
29
28
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
30
29
  "exclude": ["node_modules"]
package/vitest.config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineConfig } from "vitest/config";
2
2
  import react from "@vitejs/plugin-react";
3
+ import path from "path";
3
4
 
4
5
  export default defineConfig({
5
6
  plugins: [react()],
@@ -7,5 +8,10 @@ export default defineConfig({
7
8
  globals: true,
8
9
  environment: "jsdom",
9
10
  setupFiles: "./setupTests.js"
11
+ },
12
+ resolve: {
13
+ alias: {
14
+ "@": path.resolve(__dirname, "./")
15
+ }
10
16
  }
11
17
  });