-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(delete-nodes): separate into its own plugin
Currently each plugin match one to one with a menu item. We want one menu item for deleting nodes, so a plugin for it is created. In the future it will be usefull to keep related functionality in the same plugin, and allow them to have more than one menu item associated.
- Loading branch information
1 parent
5c70a0a
commit 6388915
Showing
13 changed files
with
178 additions
and
33 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { h } from 'preact'; | ||
import { fireEvent, act, screen } from '@testing-library/preact'; | ||
import '@testing-library/jest-dom'; | ||
import waitForExpect from 'wait-for-expect'; | ||
|
||
import DeleteNodesPage from './src/deleteNodesPage'; | ||
import queryCache from 'utils/queryCache'; | ||
import { getNodes, markNodesAsGone } from 'plugins/lime-plugin-network-nodes/src/networkNodesApi'; | ||
import { render } from 'utils/test_utils'; | ||
|
||
jest.mock('plugins/lime-plugin-network-nodes/src/networkNodesApi'); | ||
|
||
describe('delete nodes page', () => { | ||
beforeEach(() => { | ||
getNodes.mockImplementation(async () => [ | ||
{ hostname: 'node1', status: 'recently_connected' }, | ||
{ hostname: 'node2', status: 'recently_connected' }, | ||
{ hostname: 'node3', status: 'recently_connected' }, | ||
{ hostname: 'node4', status: 'disconnected' }, | ||
{ hostname: 'node5', status: 'disconnected' }, | ||
{ hostname: 'node6', status: 'disconnected' }, | ||
{ hostname: 'node7', status: 'disconnected' }, | ||
{ hostname: 'node8', status: 'gone' }, | ||
{ hostname: 'node9', status: 'gone' }, | ||
]); | ||
markNodesAsGone.mockImplementation(async () => []); | ||
}); | ||
|
||
afterEach(() => { | ||
act(() => queryCache.clear()); | ||
getNodes.mockClear(); | ||
markNodesAsGone.mockClear(); | ||
}); | ||
|
||
it('shows the list of disconnected nodes only', async () => { | ||
render(<DeleteNodesPage />); | ||
expect(await screen.findByText('node4')).toBeVisible(); | ||
expect(await screen.findByText('node5')).toBeVisible(); | ||
expect(await screen.findByText('node6')).toBeVisible(); | ||
expect(await screen.findByText('node7')).toBeVisible(); | ||
expect(screen.queryByText('node1')).toBeNull(); | ||
expect(screen.queryByText('node2')).toBeNull(); | ||
expect(screen.queryByText('node3')).toBeNull(); | ||
expect(screen.queryByText('node8')).toBeNull(); | ||
expect(screen.queryByText('node9')).toBeNull(); | ||
}); | ||
|
||
it('calls the markNodesAsGone api when deleting', async () => { | ||
markNodesAsGone.mockImplementation(async () => ['node6']); | ||
render(<DeleteNodesPage />); | ||
fireEvent.click(await screen.findByText('node6')); | ||
fireEvent.click(await screen.findByRole('button', { name: /delete/i })); | ||
await waitForExpect(() => { | ||
expect(markNodesAsGone).toBeCalledWith(['node6']); | ||
}) | ||
}) | ||
|
||
it('hide nodes from the list after deletion', async () => { | ||
markNodesAsGone.mockImplementation(async () => ['node6', 'node7']); | ||
render(<DeleteNodesPage />); | ||
fireEvent.click(await screen.findByText('node6')); | ||
fireEvent.click(await screen.findByText('node7')); | ||
fireEvent.click(await screen.findByRole('button', { name: /delete/i })); | ||
expect(await screen.findByText('node4')).toBeVisible(); | ||
expect(await screen.queryByText('node5')).toBeVisible(); | ||
expect(await screen.queryByText('node6')).toBeNull(); | ||
expect(await screen.queryByText('node7')).toBeNull(); | ||
}) | ||
|
||
it('show success message after deletion', async () => { | ||
markNodesAsGone.mockImplementation(async () => ['node6', 'node7']); | ||
render(<DeleteNodesPage />); | ||
fireEvent.click(await screen.findByText('node6')); | ||
fireEvent.click(await screen.findByText('node7')); | ||
fireEvent.click(await screen.findByRole('button', { name: /delete/i })); | ||
expect(await screen.findByText(/successfully deleted/i)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DeleteNodesPage_ } from './src/deleteNodesPage'; | ||
|
||
export default { | ||
title: 'Containers/Remove Nodes' | ||
}; | ||
|
||
const nodes = [ | ||
{ hostname: "ql-refu-bbone", status: "unreachable" }, | ||
{ hostname: "si-soniam", status: "unreachable" }, | ||
{ hostname: "si-giordano", status: "unreachable" }, | ||
{ hostname: "si-mario", status: "unreachable" }, | ||
{ hostname: "si-manu", status: "unreachable" }, | ||
]; | ||
|
||
export const deleteNodesPage = (args) => ( | ||
<DeleteNodesPage_ nodes={nodes} {...args} /> | ||
); | ||
|
||
deleteNodesPage.argTypes = { | ||
onDelete: { action: 'deleted' } | ||
}; |
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,9 @@ | ||
import Page from './src/deleteNodesPage'; | ||
import Menu from './src/deleteNodesMenu'; | ||
|
||
export default { | ||
name: 'deleteNodes', | ||
page: Page, | ||
menu: Menu, | ||
isCommunityProtected: false | ||
}; |
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,8 @@ | ||
import { h } from 'preact'; | ||
import I18n from 'i18n-js'; | ||
|
||
const Menu = () => ( | ||
<a href={'#/deletenodes'}>{I18n.t('Remove Nodes')}</a> | ||
); | ||
|
||
export default Menu; |
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
File renamed without changes.
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
16 changes: 14 additions & 2 deletions
16
plugins/lime-plugin-network-nodes/src/networkNodesQueries.js
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,5 +1,17 @@ | ||
import { useQuery } from 'react-query'; | ||
import { getNodes } from './networkNodesApi'; | ||
import { useQuery, useMutation } from 'react-query'; | ||
import { getNodes, markNodesAsGone } from './networkNodesApi'; | ||
import queryCache from 'utils/queryCache'; | ||
|
||
export const useNetworkNodes = () => | ||
useQuery(['network-nodes', 'get_nodes'], getNodes); | ||
|
||
export const useMarkNodesAsGone = () => useMutation(markNodesAsGone, { | ||
onSuccess: hostnames => queryCache.setQueryData(['network-nodes', 'get_nodes'], | ||
old => { | ||
const result = old.map( | ||
node => hostnames.indexOf(node.hostname) != -1 ? { ...node, status: "gone" } : node | ||
) | ||
return result; | ||
} | ||
) | ||
}) |
2 changes: 0 additions & 2 deletions
2
plugins/lime-plugin-reachable-nodes/src/containers/deleteNodesPage/index.js
This file was deleted.
Oops, something went wrong.