From bcdc2687de162b57451a4b25506ce00d31f4cc2e Mon Sep 17 00:00:00 2001 From: zombiej Date: Fri, 28 May 2021 11:20:35 +0800 Subject: [PATCH 1/2] fix:keyPath is inverse --- src/MenuItem.tsx | 3 ++- tests/Menu.spec.js | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/MenuItem.tsx b/src/MenuItem.tsx index ff9ad750..b48ec56a 100644 --- a/src/MenuItem.tsx +++ b/src/MenuItem.tsx @@ -135,7 +135,8 @@ const InternalMenuItem = (props: MenuItemProps) => { ): MenuInfo => { return { key: eventKey, - keyPath: connectedKeys, + // Note: For legacy code is reversed which not like other antd component + keyPath: [...connectedKeys].reverse(), item: legacyMenuItemRef.current, domEvent: e, }; diff --git a/tests/Menu.spec.js b/tests/Menu.spec.js index 6835b897..4f2b93c9 100644 --- a/tests/Menu.spec.js +++ b/tests/Menu.spec.js @@ -331,18 +331,29 @@ describe('Menu', () => { }); it('fires click event', () => { + jest.useFakeTimers(); + resetWarned(); const errorSpy = jest.spyOn(console, 'error'); const handleClick = jest.fn(); const wrapper = mount( - + 1 2 + + 3 + , ); - wrapper.find('MenuItem').first().simulate('click'); + + act(() => { + jest.runAllTimers(); + wrapper.update(); + }); + + wrapper.find('.rc-menu-item').first().simulate('click'); const info = handleClick.mock.calls[0][0]; expect(info.key).toBe('1'); expect(info.item).toBeTruthy(); @@ -351,7 +362,13 @@ describe('Menu', () => { 'Warning: `info.item` is deprecated since we will move to function component that not provides React Node instance in future.', ); + handleClick.mockReset(); + wrapper.find('.rc-menu-item').last().simulate('click'); + expect(handleClick.mock.calls[0][0].keyPath).toEqual(['3', 'parent']); + errorSpy.mockRestore(); + + jest.useRealTimers(); }); it('fires deselect event', () => { From 955cf17974678ef96d6d1981589e26417aae7802 Mon Sep 17 00:00:00 2001 From: zombiej Date: Fri, 28 May 2021 11:23:06 +0800 Subject: [PATCH 2/2] test: Update snapshot --- src/Menu.tsx | 12 +- tests/__snapshots__/Keyboard.spec.tsx.snap | 74 +- tests/__snapshots__/Menu.spec.js.snap | 1320 +++++++++--------- tests/__snapshots__/MenuItem.spec.js.snap | 150 +- tests/__snapshots__/Responsive.spec.tsx.snap | 7 +- 5 files changed, 814 insertions(+), 749 deletions(-) diff --git a/src/Menu.tsx b/src/Menu.tsx index 14c6a9bc..754bfe9f 100644 --- a/src/Menu.tsx +++ b/src/Menu.tsx @@ -535,12 +535,12 @@ const Menu: React.FC = props => { {container} - {/* Measure menu keys */} - {/*
*/} - - {childList} - - {/*
*/} + {/* Measure menu keys. Add `display: none` to avoid some developer miss use the Menu */} +
+ + {childList} + +
); diff --git a/tests/__snapshots__/Keyboard.spec.tsx.snap b/tests/__snapshots__/Keyboard.spec.tsx.snap index 32635ef6..4eff8d3e 100644 --- a/tests/__snapshots__/Keyboard.spec.tsx.snap +++ b/tests/__snapshots__/Keyboard.spec.tsx.snap @@ -1,43 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Menu.Keyboard no data-menu-id by init 1`] = ` - + + , + + + , + -
    +
  • -
  • +
  • +
  • -
- -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + - - -
  • -
  • + +
  • + - - + 6 + + , + -
      +
    • -
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + -
      +
    • -
    • -
    • +
        + + +
      +
    • +
    • +
    • -
    - -
  • - -
  • - + submenu + + + + , + +
      + +
    + +
  • -
  • - - - + title + +
      + +
    + + , + , - "Bamboo", + , ] `;