Skip to content

Commit

Permalink
fix: actions height in components
Browse files Browse the repository at this point in the history
- remove theme override & fallback on button sizes
  - it's the default (sm) in all the use cases (AFAIK)
  - covers HvActionsGeneric, HvSnackbar, HvBanner, HvBulkActions
  • Loading branch information
zettca committed Jun 21, 2023
1 parent 22a1f36 commit b9b386a
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
Preview,
Upload,
} from "@hitachivantara/uikit-react-icons";
import { fireEvent, render } from "@testing-library/react";
import { HvProvider } from "@core/providers";
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { HvActionsGeneric } from "./ActionsGeneric";

Expand All @@ -17,47 +16,25 @@ const actions = [
];

describe("ActionsGeneric", () => {
it("should be defined", () => {
const { container } = render(<HvActionsGeneric actions={actions} />);
expect(container).toBeDefined();
});

it("should render correctly", () => {
const { container } = render(<HvActionsGeneric actions={actions} />);
expect(container).toMatchSnapshot();
});

it("should only show maxVisibleActions actions", () => {
const { queryAllByRole, getByLabelText } = render(
<HvProvider>
<HvActionsGeneric actions={actions} maxVisibleActions={2} />
</HvProvider>
);
expect(queryAllByRole("button").length).toBe(3);
render(<HvActionsGeneric actions={actions} maxVisibleActions={2} />);
expect(screen.queryAllByRole("button").length).toBe(3);

expect(getByLabelText("Dropdown menu")).toBeInTheDocument();
expect(screen.getByLabelText("Dropdown menu")).toBeInTheDocument();
});

it("should call actionsCallback on button click", () => {
const mockFn = vi.fn();
const { queryAllByRole } = render(
<HvProvider>
<HvActionsGeneric actions={actions} actionsCallback={mockFn} />
</HvProvider>
);
const button = queryAllByRole("button")[1];
render(<HvActionsGeneric actions={actions} actionsCallback={mockFn} />);
const button = screen.queryAllByRole("button")[1];
fireEvent.click(button);
expect(mockFn).toHaveBeenCalled();
});

it("should not call actionsCallback if the button is disabled", () => {
const mockFn = vi.fn();
const { queryAllByRole } = render(
<HvProvider>
<HvActionsGeneric actions={actions} actionsCallback={mockFn} />
</HvProvider>
);
const button = queryAllByRole("button")[0];
render(<HvActionsGeneric actions={actions} actionsCallback={mockFn} />);
const button = screen.queryAllByRole("button")[0];
fireEvent.click(button);
expect(mockFn).not.toHaveBeenCalled();
});
Expand Down
11 changes: 2 additions & 9 deletions packages/core/src/components/ActionsGeneric/ActionsGeneric.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { clsx } from "clsx";
import {
HvButtonSize,
HvButtonVariant,
HvDropDownMenu,
} from "@core/components";
import { HvButtonVariant, HvDropDownMenu } from "@core/components";
import { setId } from "@core/utils";
import React, { isValidElement } from "react";
import { HvBaseProps } from "@core/types";
Expand Down Expand Up @@ -73,15 +69,12 @@ export const HvActionsGeneric = ({
variant={category}
className={clsx(actionsGenericClasses.button, classes?.button)}
disabled={actDisabled ?? disabled}
onClick={(event: React.SyntheticEvent) =>
actionsCallback?.(event, id || "", action)
}
onClick={(event) => actionsCallback?.(event, id || "", action)}
startIcon={renderedIcon}
$baseColor={
activeTheme?.colors?.modes[selectedMode].base_light ||
theme.colors.base_light
}
size={(activeTheme?.actionsGeneric?.buttonSize as HvButtonSize) || "md"}
{...other}
>
{label}
Expand Down

This file was deleted.

32 changes: 4 additions & 28 deletions packages/core/src/components/BulkActions/BulkActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ const WithActions = () => {

describe("BulkActions", () => {
describe("Without actions", () => {
it("should be defined", () => {
const { container } = render(<WithoutActions />);

expect(container).toBeDefined();
});

it("should render correctly", () => {
const { container } = render(<WithoutActions />);

expect(container).toMatchSnapshot();
});

it("should render select all component correctly", async () => {
const { getByRole, getByLabelText } = render(<WithoutActions />);

Expand All @@ -67,7 +55,7 @@ describe("BulkActions", () => {
expect(getByLabelText("All (8)")).toBeInTheDocument();

// Select all
await fireEvent.click(checkbox);
fireEvent.click(checkbox);

expect(checkbox).toBeChecked();
expect(getByLabelText("8 / 8")).toBeInTheDocument();
Expand All @@ -89,7 +77,7 @@ describe("BulkActions", () => {
const selectAll = checkboxes[0];

// Select all
await fireEvent.click(selectAll);
fireEvent.click(selectAll);

expect(onSelectAllMock).toBeCalledTimes(1);
});
Expand All @@ -108,18 +96,6 @@ describe("BulkActions", () => {
});

describe("With actions", () => {
it("should be defined", () => {
const { container } = render(<WithActions />);

expect(container).toBeDefined();
});

it("should render correctly", () => {
const { container } = render(<WithActions />);

expect(container).toMatchSnapshot();
});

it("should render the actions correctly", async () => {
const { getAllByRole, getByRole } = render(<WithActions />);

Expand All @@ -138,14 +114,14 @@ describe("BulkActions", () => {
const checkbox = getByRole("checkbox");

// Select all
await fireEvent.click(checkbox);
fireEvent.click(checkbox);

expect(button1).toBeEnabled();
expect(button2).toBeEnabled();
expect(button3).toBeEnabled();

// Open tooltip
await fireEvent.click(button3);
fireEvent.click(button3);

const tooltip = getByRole("tooltip");

Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/components/BulkActions/BulkActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HvBaseProps } from "@core/types";
import {
HvButton,
HvButtonProps,
HvButtonSize,
HvCheckBox,
HvCheckBoxProps,
HvActionGeneric,
Expand Down Expand Up @@ -184,9 +183,6 @@ export const HvBulkActions = ({
)}
variant={isSemantic ? "semantic" : "secondaryGhost"}
onClick={onSelectAllPages}
size={
(activeTheme?.bulkActions?.buttonSize as HvButtonSize) || "md"
}
>
{selectAllPagesLabel ??
`Select all ${numTotal} items across all pages`}
Expand Down

0 comments on commit b9b386a

Please sign in to comment.