-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [M3-7726] - Assign Linodes to Placement Group Drawer (#10140)
* Improve add IP drawer * Initial commit - save work * Post rebase fixes * Cleanup and sorting improvements * Cleanup and sorting improvements * Adding unit tests * Cleanup * Added changeset: Placement GroupLinode List * Save progress * Save progress * Save progress * saving work * wrap up * Cleanup and tests * Post rebase diff fix * Text fix and cleanup * Better querying * Added changeset: Add AssignLinodesToPlacementGroup drawer * Better test * Fix typo * Feedback * Ooops await
- Loading branch information
1 parent
c8e291e
commit ebc3f76
Showing
21 changed files
with
613 additions
and
72 deletions.
There are no files selected for viewing
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: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10140-upcoming-features-1707331683987.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 AssignLinodesToPlacementGroup drawer ([#10140](https://github.com/linode/manager/pull/10140)) |
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
140 changes: 140 additions & 0 deletions
140
packages/manager/src/features/PlacementGroups/PlacementGroupsAssignLinodesDrawer.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,140 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { | ||
linodeFactory, | ||
placementGroupFactory, | ||
regionFactory, | ||
} from 'src/factories'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsAssignLinodesDrawer } from './PlacementGroupsAssignLinodesDrawer'; | ||
|
||
const queryMocks = vi.hoisted(() => ({ | ||
useAllLinodesQuery: vi.fn().mockReturnValue({}), | ||
useAssignLinodesToPlacementGroup: vi.fn().mockReturnValue({}), | ||
useRegionsQuery: vi.fn().mockReturnValue({}), | ||
useUnpaginatedPlacementGroupsQuery: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('src/queries/linodes/linodes', async () => { | ||
const actual = await vi.importActual('src/queries/linodes/linodes'); | ||
return { | ||
...actual, | ||
useAllLinodesQuery: queryMocks.useAllLinodesQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/placementGroups', async () => { | ||
const actual = await vi.importActual('src/queries/placementGroups'); | ||
return { | ||
...actual, | ||
useUnpaginatedPlacementGroupsQuery: | ||
queryMocks.useUnpaginatedPlacementGroupsQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/regions', async () => { | ||
const actual = await vi.importActual('src/queries/regions'); | ||
return { | ||
...actual, | ||
useRegionsQuery: queryMocks.useRegionsQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/placementGroups', async () => { | ||
const actual = await vi.importActual('src/queries/placementGroups'); | ||
return { | ||
...actual, | ||
useAssignLinodesToPlacementGroup: | ||
queryMocks.useAssignLinodesToPlacementGroup, | ||
}; | ||
}); | ||
|
||
describe('PlacementGroupsAssignLinodesDrawer', () => { | ||
it('should render the error state', () => { | ||
queryMocks.useAllLinodesQuery.mockReturnValue({ | ||
error: [{ reason: 'Not found' }], | ||
}); | ||
|
||
const { getByText } = renderWithTheme( | ||
<PlacementGroupsAssignLinodesDrawer | ||
numberOfPlacementGroupsCreated={9} | ||
onClose={vi.fn()} | ||
open={true} | ||
selectedPlacementGroup={placementGroupFactory.build()} | ||
/> | ||
); | ||
|
||
expect( | ||
getByText( | ||
'There was a problem retrieving your placement group. Please try again' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the drawer components', () => { | ||
queryMocks.useAllLinodesQuery.mockReturnValue({ | ||
data: [ | ||
linodeFactory.build({ id: 1, label: 'Linode-1', region: 'us-east' }), | ||
linodeFactory.build({ id: 2, label: 'Linode-2', region: 'us-east' }), | ||
linodeFactory.build({ id: 11, label: 'Linode-11', region: 'us-east' }), | ||
], | ||
}); | ||
queryMocks.useRegionsQuery.mockReturnValue(regionFactory.buildList(5)); | ||
queryMocks.useUnpaginatedPlacementGroupsQuery.mockReturnValue({ | ||
data: placementGroupFactory.build(), | ||
}); | ||
queryMocks.useAssignLinodesToPlacementGroup.mockReturnValue( | ||
placementGroupFactory.build({ | ||
linode_ids: [1, 2, 0, 1, 2, 3, 5, 6, 7, 8, 43, 11], | ||
}) | ||
); | ||
|
||
const { | ||
getByPlaceholderText, | ||
getByRole, | ||
getByTestId, | ||
getByText, | ||
} = renderWithTheme( | ||
<PlacementGroupsAssignLinodesDrawer | ||
selectedPlacementGroup={placementGroupFactory.build({ | ||
affinity_type: 'anti_affinity', | ||
label: 'PG-1', | ||
region: 'us-east', | ||
})} | ||
onClose={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
const linodesSelect = getByPlaceholderText('Select a Linode'); | ||
const addLinodeButton = getByRole('button', { name: 'Add Linode' }); | ||
const removableLinodesList = getByTestId('pg-linode-removable-list'); | ||
|
||
expect(linodesSelect).toBeInTheDocument(); | ||
expect(addLinodeButton).toHaveAttribute('aria-disabled', 'true'); | ||
expect(removableLinodesList).toHaveTextContent( | ||
'No Linodes have been assigned.' | ||
); | ||
|
||
fireEvent.focus(linodesSelect); | ||
fireEvent.change(linodesSelect, { target: { value: 'Linode-11' } }); | ||
const optionElement = getByText('Linode-11'); | ||
fireEvent.click(optionElement); | ||
|
||
expect(addLinodeButton).not.toHaveAttribute('aria-disabled', 'true'); | ||
|
||
fireEvent.click(getByRole('button', { name: 'Add Linode' })); | ||
|
||
expect(addLinodeButton).toHaveAttribute('aria-disabled', 'true'); | ||
expect(removableLinodesList).toHaveTextContent('Linode-11'); | ||
|
||
const removeButton = getByRole('button', { name: 'remove Linode-11' }); | ||
fireEvent.click(removeButton); | ||
|
||
expect(removableLinodesList).toHaveTextContent( | ||
'No Linodes have been assigned.' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.