-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [M3-7448] - Migrate ActionMenu story to v7 stories (#9927)
* remove index file and update imports * stories.tsx file and added tests * Added changeset: ActionMenu V7 story migration * Update ActionMenu.stories.tsx * fix typo
- Loading branch information
1 parent
e6ce6c7
commit 1910e8f
Showing
44 changed files
with
177 additions
and
155 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9927-tech-stories-1700672701188.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
ActionMenu V7 story migration ([#9927](https://github.com/linode/manager/pull/9927)) |
60 changes: 0 additions & 60 deletions
60
packages/manager/src/components/ActionMenu/ActionMenu.stories.mdx
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/manager/src/components/ActionMenu/ActionMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import React from 'react'; | ||
|
||
import { ActionMenu } from './ActionMenu'; | ||
|
||
import type { Action, ActionMenuProps } from './ActionMenu'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const standardActions = [ | ||
{ | ||
onClick: action('First Action clicked'), | ||
title: 'First Action', | ||
}, | ||
{ | ||
onClick: action('Second Action clicked'), | ||
title: 'Second Action', | ||
}, | ||
] as Action[]; | ||
|
||
const standardAndDisabledActions = [ | ||
...standardActions, | ||
{ | ||
disabled: true, | ||
onClick: action('Disabled Action clicked'), | ||
title: 'Disabled Action', | ||
tooltip: 'An explanation as to why this item is disabled', | ||
}, | ||
]; | ||
|
||
export const Default: StoryObj<ActionMenuProps> = { | ||
render: (args) => <ActionMenu {...args} />, | ||
}; | ||
|
||
const meta: Meta<ActionMenuProps> = { | ||
argTypes: { | ||
actionsList: { | ||
options: { | ||
'disabled actions': standardAndDisabledActions, | ||
'standard actions': standardActions, | ||
}, | ||
}, | ||
}, | ||
args: { actionsList: standardActions, ariaLabel: 'action menu' }, | ||
component: ActionMenu, | ||
title: 'Components/Action Menu', | ||
}; | ||
|
||
export default meta; |
67 changes: 56 additions & 11 deletions
67
packages/manager/src/components/ActionMenu/ActionMenu.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,65 @@ | ||
import { mount } from 'enzyme'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { ActionMenu } from './ActionMenu'; | ||
|
||
describe('ActionMenu', () => { | ||
const action = { onClick: () => undefined, title: 'whatever' }; | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
const manyActions = [action, action, action]; | ||
describe('ActionMenu', () => { | ||
const action1 = { onClick: vi.fn(), title: 'whatever' }; | ||
const action2 = { onClick: vi.fn(), title: 'whatever2' }; | ||
const action3 = { | ||
disabled: true, | ||
onClick: vi.fn(), | ||
title: 'whatever3', | ||
tooltip: 'helper text for tooltip', | ||
}; | ||
|
||
it.skip('should render a menu when provided many or one action(s).', () => { | ||
const result = mount( | ||
<ActionMenu actionsList={manyActions} ariaLabel="label" /> | ||
const standardActions = [action1, action2]; | ||
const standardAndDisabledActions = [...standardActions, action3]; | ||
it('should include the correct actions', () => { | ||
const { getByLabelText, getByText } = renderWithTheme( | ||
<ActionMenu actionsList={standardActions} ariaLabel="action menu" /> | ||
); | ||
expect(result.find('WithStyles(ActionMenu)')).toHaveLength(1); | ||
|
||
result.find('IconButton').simulate('click'); | ||
expect(result.find('WithStyles(MenuItem)')).toHaveLength(4); | ||
const actionMenu = getByLabelText('action menu'); | ||
fireEvent.click(actionMenu); | ||
const a1 = getByText('whatever'); | ||
expect(a1).toBeVisible(); | ||
const a2 = getByText('whatever2'); | ||
expect(a2).toBeVisible(); | ||
}); | ||
it('should call the associated onClick function when clicking on an enabled action', () => { | ||
const { getByLabelText, getByText } = renderWithTheme( | ||
<ActionMenu actionsList={standardActions} ariaLabel="action menu" /> | ||
); | ||
const actionMenu = getByLabelText('action menu'); | ||
fireEvent.click(actionMenu); | ||
const a1 = getByText('whatever'); | ||
fireEvent.click(a1); | ||
expect(action1.onClick).toHaveBeenCalled(); | ||
const a2 = getByText('whatever2'); | ||
fireEvent.click(a2); | ||
expect(action2.onClick).toHaveBeenCalled(); | ||
}); | ||
it('should have a tooltip if provided and not call the associated onClick function when clicking on a disabled action', () => { | ||
const { getByLabelText, getByText } = renderWithTheme( | ||
<ActionMenu | ||
actionsList={standardAndDisabledActions} | ||
ariaLabel="action menu" | ||
/> | ||
); | ||
const actionMenu = getByLabelText('action menu'); | ||
fireEvent.click(actionMenu); | ||
const a3 = getByText('whatever3'); | ||
fireEvent.click(a3); | ||
expect(action3.onClick).not.toHaveBeenCalled(); | ||
const tooltip = getByLabelText('helper text for tooltip'); | ||
expect(tooltip).toBeInTheDocument(); | ||
fireEvent.click(tooltip); | ||
expect(tooltip).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
packages/manager/src/components/PaymentMethodRow/PaymentMethodRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/manager/src/features/Databases/DatabaseLanding/DatabaseActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/manager/src/features/EntityTransfers/TransfersPendingActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/manager/src/features/Firewalls/FirewallLanding/FirewallActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/manager/src/features/Kubernetes/ClusterList/ClusterActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/manager/src/features/Linodes/LinodesDetail/LinodeBackup/LinodeBackupActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/manager/src/features/Linodes/LinodesDetail/LinodeConfigs/LinodeConfigActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ures/Linodes/LinodesDetail/LinodeNetworking/LinodeFirewalls/LinodeFirewallsActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...anager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeNetworkingActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.