Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion src/UniqueProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
offsetY={offsetY}
popupSize={popupSize}
motion={options.popupMotion}
uniqueBgClassName={options.uniqueBgClassName}
uniqueBgClassName={classNames(
options.uniqueBgClassName,
alignedClassName,
)}
uniqueBgStyle={options.uniqueBgStyle}
/>
</Popup>
Expand Down
44 changes: 40 additions & 4 deletions tests/unique.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ describe('Trigger.Unique', () => {

// There should only be one popup element
expect(document.querySelectorAll('.rc-trigger-popup').length).toBe(1);
expect(document.querySelectorAll('.rc-trigger-popup-unique-body').length).toBe(
1,
);
expect(
document.querySelectorAll('.rc-trigger-popup-unique-body').length,
).toBe(1);

// FloatBg open prop should not have changed during transition (no close animation)
expect(global.openChangeLog).toHaveLength(0);
Expand Down Expand Up @@ -192,7 +192,9 @@ describe('Trigger.Unique', () => {
});

it('should apply uniqueBgStyle to UniqueBody component', async () => {
await setupAndOpenPopup({ uniqueBgStyle: { backgroundColor: 'red', border: '1px solid blue' } });
await setupAndOpenPopup({
uniqueBgStyle: { backgroundColor: 'red', border: '1px solid blue' },
});

// Check that UniqueBody has the custom background style
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
Expand All @@ -211,4 +213,38 @@ describe('Trigger.Unique', () => {
expect(uniqueBody).toBeTruthy();
expect(uniqueBody.className).not.toContain('undefined');
});

it('should combine alignedClassName with uniqueBgClassName', async () => {
const getPopupClassNameFromAlign = () => 'bamboo';

render(
<UniqueProvider>
<Trigger
action={['click']}
popup={<strong className="x-content">tooltip</strong>}
unique
popupVisible
popupPlacement="bottomLeft"
getPopupClassNameFromAlign={getPopupClassNameFromAlign}
builtinPlacements={{
bottomLeft: {
points: ['tl', 'bl'],
offset: [0, 4],
overflow: {
adjustX: 0,
adjustY: 1,
},
},
}}
>
<div className="target">click me</div>
</Trigger>
</UniqueProvider>,
);

expect(document.querySelector('.rc-trigger-popup')).toHaveClass('bamboo');
expect(document.querySelector('.rc-trigger-popup-unique-body')).toHaveClass(
'bamboo',
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个测试用例的标题是 should combine alignedClassName with uniqueBgClassName,但它目前只验证了 alignedClassName (bamboo) 是否被应用,而没有验证与 uniqueBgClassName 的合并行为。为了让测试更完整并与标题完全对应,建议在 Trigger 组件上添加 uniqueBgClassName 属性,并断言 UniqueBody 同时包含这两个类名。

另外,由于此测试用例中没有使用 await,可以移除 async 关键字。

  it('should combine alignedClassName with uniqueBgClassName', () => {
    const getPopupClassNameFromAlign = () => 'bamboo';

    render(
      <UniqueProvider>
        <Trigger
          action={['click']}
          popup={<strong className="x-content">tooltip</strong>}
          unique
          popupVisible
          popupPlacement="bottomLeft"
          getPopupClassNameFromAlign={getPopupClassNameFromAlign}
          uniqueBgClassName="custom-bg"
          builtinPlacements={{
            bottomLeft: {
              points: ['tl', 'bl'],
              offset: [0, 4],
              overflow: {
                adjustX: 0,
                adjustY: 1,
              },
            },
          }}
        >
          <div className="target">click me</div>
        </Trigger>
      </UniqueProvider>,
    );

    const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
    expect(document.querySelector('.rc-trigger-popup')).toHaveClass('bamboo');
    expect(uniqueBody).toHaveClass('bamboo');
    expect(uniqueBody).toHaveClass('custom-bg');
  });

});
Loading