Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/tooltip button #495

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 169 additions & 56 deletions packages/base/src/page/System/License/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ exports[`base/System/License click collect btn when request return blob data 1`]
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center ant-tooltip-open basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -165,6 +172,38 @@ exports[`base/System/License click collect btn when request return blob data 1`]
</div>
</section>
</div>
<div>
<div
class="ant-tooltip ant-zoom-big-fast-appear ant-zoom-big-fast-appear-prepare ant-zoom-big-fast css-dev-only-do-not-override-txh9fw ant-tooltip-placement-top"
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; box-sizing: border-box;"
>
<div
class="ant-tooltip-content"
>
<div
class="ant-tooltip-inner"
role="tooltip"
style="padding: 0px; border-radius: 10px;"
>
<div
class="css-1s6bzds"
width="326"
>
<div
class="ant-qrcode css-dev-only-do-not-override-txh9fw"
style="width: 300px; height: 300px; background-color: transparent;"
>
<canvas
height="274"
style="height: 274px; width: 274px;"
width="274"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
`;

Expand Down Expand Up @@ -218,15 +257,22 @@ exports[`base/System/License click collect btn when request return blob data 2`]
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -333,6 +379,38 @@ exports[`base/System/License click collect btn when request return blob data 2`]
</div>
</section>
</div>
<div>
<div
class="ant-tooltip ant-tooltip-hidden css-dev-only-do-not-override-txh9fw ant-tooltip-placement-top"
style="--arrow-x: 0px; --arrow-y: 0px; left: 0px; top: 0px; box-sizing: border-box; pointer-events: none;"
>
<div
class="ant-tooltip-content"
>
<div
class="ant-tooltip-inner"
role="tooltip"
style="padding: 0px; border-radius: 10px;"
>
<div
class="css-1s6bzds"
width="326"
>
<div
class="ant-qrcode css-dev-only-do-not-override-txh9fw"
style="width: 300px; height: 300px; background-color: transparent;"
>
<canvas
height="274"
style="height: 274px; width: 274px;"
width="274"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
`;

Expand Down Expand Up @@ -386,15 +464,22 @@ exports[`base/System/License click collect btn when request return error message
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -554,15 +639,22 @@ exports[`base/System/License render snap 1`] = `
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -746,15 +838,22 @@ exports[`base/System/License render snap 2`] = `
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -914,15 +1013,22 @@ exports[`base/System/License render snap when click import btn 1`] = `
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down Expand Up @@ -1082,15 +1188,22 @@ exports[`base/System/License render snap when limit data name is \`info\` 1`] =
class="ant-space-item"
style="margin-right: 8px;"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
tooltip="[object Object]"
type="button"
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center basic-tooltips-wrapper css-4jbtl9"
>
<span>
收集许可信息
</span>
</button>
<div
class="ant-space-item"
>
<button
class="ant-btn css-dev-only-do-not-override-674gwq ant-btn-primary basic-button-wrapper css-geipcv"
type="button"
>
<span>
收集许可信息
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
Expand Down
8 changes: 5 additions & 3 deletions packages/shared/lib/components/ActionButton/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
if (props.actionType === 'tooltip') {
const { actionType, text, tooltip, ...buttonProps } = props;

<BasicToolTips {...tooltip}>
<BasicButton {...buttonProps}>{text}</BasicButton>
</BasicToolTips>;
return (
<BasicToolTips {...tooltip}>
<BasicButton {...buttonProps}>{text}</BasicButton>
</BasicToolTips>
);
}

const { actionType, text, ...buttonProps } = props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { screen } from '@testing-library/react';
import { fireEvent, screen } from '@testing-library/react';
import ActionButton from '../ActionButton';
import { superRender } from '../../../testUtil/customRender';
import { act } from 'react-dom/test-utils';

describe('ActionButton', () => {
beforeEach(() => {
jest.useFakeTimers();
});

afterEach(() => {
jest.useRealTimers();
});

it('renders a basic button', () => {
superRender(<ActionButton text="Click me" />);
expect(screen.getByText('Click me')).toBeInTheDocument();
Expand Down Expand Up @@ -34,16 +43,16 @@ describe('ActionButton', () => {
expect(container).toMatchSnapshot();
});

it('renders a tooltip button', () => {
const { container } = superRender(
<ActionButton
actionType="tooltip"
text="Info"
tooltip={{ title: 'More information' }}
/>
it('renders a tooltip button', async () => {
const title = 'More information';
const { baseElement } = superRender(
<ActionButton actionType="tooltip" text="Info" tooltip={{ title }} />
);
const button = screen.getByText('Info');
expect(button).toBeInTheDocument();
expect(container).toMatchSnapshot();
fireEvent.mouseOver(button.closest('button')!);
await act(async () => jest.advanceTimersByTime(300));
expect(screen.getByText(title)).toBeInTheDocument();
expect(baseElement).toMatchSnapshot();
});
});
Loading
Loading