forked from linode/manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [M3-7618] - Delete Placement Group Modal (linode#10162)
* Initial commit: save work * Wrap up comment and add test * Cleanup * Error handling * Cleanup and more error handling * Add linode list * Add unassign logic * error handling * Test * Restore initial mock data * Cleanup * Test and story for changes in removable selection list * Added changeset: Add Delete Placement Group Modal * Invalidate related linode when removed from PG * Feedback
- Loading branch information
1 parent
455f09b
commit 42137a0
Showing
14 changed files
with
398 additions
and
41 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10162-upcoming-features-1708036002117.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": Upcoming Features | ||
--- | ||
|
||
Add Delete Placement Group Modal ([#10162](https://github.com/linode/manager/pull/10162)) |
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
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
125 changes: 125 additions & 0 deletions
125
packages/manager/src/features/PlacementGroups/PlacementGroupsDeleteModal.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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { linodeFactory, placementGroupFactory } from 'src/factories'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsDeleteModal } from './PlacementGroupsDeleteModal'; | ||
|
||
const queryMocks = vi.hoisted(() => ({ | ||
useAllLinodesQuery: vi.fn().mockReturnValue({}), | ||
useDeletePlacementGroup: vi.fn().mockReturnValue({ | ||
mutateAsync: vi.fn().mockResolvedValue({}), | ||
reset: vi.fn(), | ||
}), | ||
useParams: vi.fn().mockReturnValue({}), | ||
usePlacementGroupQuery: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('react-router-dom', async () => { | ||
const actual = await vi.importActual('react-router-dom'); | ||
return { | ||
...actual, | ||
useParams: queryMocks.useParams, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/placementGroups', async () => { | ||
const actual = await vi.importActual('src/queries/placementGroups'); | ||
return { | ||
...actual, | ||
useDeletePlacementGroup: queryMocks.useDeletePlacementGroup, | ||
usePlacementGroupQuery: queryMocks.usePlacementGroupQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/linodes/linodes', async () => { | ||
const actual = await vi.importActual('src/queries/linodes/linodes'); | ||
return { | ||
...actual, | ||
useAllLinodesQuery: queryMocks.useAllLinodesQuery, | ||
}; | ||
}); | ||
|
||
const props = { | ||
onClose: vi.fn(), | ||
open: true, | ||
}; | ||
|
||
describe('PlacementGroupsDeleteModal', () => { | ||
beforeAll(() => { | ||
queryMocks.useParams.mockReturnValue({ | ||
id: '1', | ||
}); | ||
queryMocks.useAllLinodesQuery.mockReturnValue({ | ||
data: [ | ||
linodeFactory.build({ | ||
id: 1, | ||
label: 'test-linode', | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it('should render the right form elements', () => { | ||
queryMocks.usePlacementGroupQuery.mockReturnValue({ | ||
data: placementGroupFactory.build({ | ||
affinity_type: 'anti_affinity', | ||
id: 1, | ||
label: 'PG-to-delete', | ||
linode_ids: [1], | ||
}), | ||
}); | ||
|
||
const { getByRole, getByTestId, getByText } = renderWithTheme( | ||
<PlacementGroupsDeleteModal {...props} /> | ||
); | ||
|
||
expect( | ||
getByRole('heading', { | ||
name: 'Delete Placement Group PG-to-delete (Anti-affinity)', | ||
}) | ||
).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
'Linodes assigned to Placement Group PG-to-delete (Anti-affinity)' | ||
) | ||
).toBeInTheDocument(); | ||
expect(getByTestId('assigned-linodes')).toContainElement( | ||
getByText('test-linode') | ||
); | ||
expect(getByTestId('textfield-input')).toBeDisabled(); | ||
expect(getByRole('button', { name: 'Close' })).toBeInTheDocument(); | ||
expect(getByRole('button', { name: 'Cancel' })).toBeInTheDocument(); | ||
expect(getByRole('button', { name: 'Delete' })).toBeDisabled(); | ||
}); | ||
|
||
it("should be enabled when there's no assigned linodes", () => { | ||
queryMocks.usePlacementGroupQuery.mockReturnValue({ | ||
data: placementGroupFactory.build({ | ||
affinity_type: 'anti_affinity', | ||
id: 1, | ||
label: 'PG-to-delete', | ||
linode_ids: [], | ||
}), | ||
}); | ||
const { getByRole, getByTestId, getByText } = renderWithTheme( | ||
<PlacementGroupsDeleteModal {...props} /> | ||
); | ||
|
||
expect(getByText('No Linodes assigned to this Placement Group.')); | ||
|
||
const textField = getByTestId('textfield-input'); | ||
const deleteButton = getByRole('button', { name: 'Delete' }); | ||
|
||
expect(textField).toBeEnabled(); | ||
expect(deleteButton).toBeDisabled(); | ||
|
||
fireEvent.change(textField, { target: { value: 'PG-to-delete' } }); | ||
|
||
expect(deleteButton).toBeEnabled(); | ||
fireEvent.click(deleteButton); | ||
|
||
expect(queryMocks.useDeletePlacementGroup).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.