-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb1c35e
commit 481408a
Showing
7 changed files
with
169 additions
and
18 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/manager/src/features/PlacementGroups/PlacementGroupsCreateDrawer.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,70 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsCreateDrawer } from './PlacementGroupsCreateDrawer'; | ||
|
||
describe('PlacementGroupsCreateDrawer', () => { | ||
it('should render have its fields enabled', () => { | ||
const { getByLabelText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
onClose={vi.fn()} | ||
onPlacementGroupCreated={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Label')).toBeEnabled(); | ||
expect(getByLabelText('Region')).toBeEnabled(); | ||
expect(getByLabelText('Affinity Type')).toBeEnabled(); | ||
}); | ||
|
||
it('Affinity Type select should have the correct options', async () => { | ||
const { getByPlaceholderText, getByText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
onClose={vi.fn()} | ||
onPlacementGroupCreated={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
const inputElement = getByPlaceholderText('Select an Affinity Type'); | ||
fireEvent.focus(inputElement); | ||
|
||
fireEvent.change(inputElement, { target: { value: 'Affinity' } }); | ||
expect(getByText('Affinity')).toBeInTheDocument(); | ||
|
||
fireEvent.change(inputElement, { target: { value: 'Anti-affinity' } }); | ||
expect(getByText('Anti-affinity')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should disable the submit button when the number of placement groups created is >= to the max', () => { | ||
const { getByTestId } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={5} | ||
onClose={vi.fn()} | ||
onPlacementGroupCreated={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
expect(getByTestId('submit')).toHaveAttribute('aria-disabled', 'true'); | ||
}); | ||
|
||
it('should populate the region select with the selected region prop', () => { | ||
const { getByLabelText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
onClose={vi.fn()} | ||
onPlacementGroupCreated={vi.fn()} | ||
open={true} | ||
selectedRegionId="us-east" | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Region')).toHaveValue('Newark, NJ (us-east)'); | ||
}); | ||
}); |
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
43 changes: 43 additions & 0 deletions
43
packages/manager/src/features/PlacementGroups/PlacementGroupsDrawerContent.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,43 @@ | ||
import { FormikProps } from 'formik'; | ||
import * as React from 'react'; | ||
|
||
import { placementGroupFactory } from 'src/factories'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsDrawerContent } from './PlacementGroupsDrawerContent'; | ||
|
||
import type { PlacementGroupDrawerFormikProps } from './types'; | ||
|
||
describe('PlacementGroupsDrawerContent', () => { | ||
it('should render the right form elements', () => { | ||
const { getByLabelText, getByRole } = renderWithTheme( | ||
<PlacementGroupsDrawerContent | ||
formik={ | ||
({ | ||
errors: {}, | ||
resetForm: vi.fn(), | ||
values: { | ||
affinity_type: 'affinity', | ||
label: '', | ||
region: '', | ||
}, | ||
} as unknown) as FormikProps<PlacementGroupDrawerFormikProps> | ||
} | ||
mode="create" | ||
onClose={vi.fn()} | ||
open={true} | ||
regions={[]} | ||
selectedPlacementGroup={placementGroupFactory.build()} | ||
setIsFormDirty={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Label')).toBeInTheDocument(); | ||
expect(getByLabelText('Region')).toBeInTheDocument(); | ||
expect(getByLabelText('Affinity Type')).toBeInTheDocument(); | ||
expect(getByRole('button', { name: 'Cancel' })).toBeInTheDocument(); | ||
expect( | ||
getByRole('button', { name: 'Create Placement Group' }) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
packages/manager/src/features/PlacementGroups/PlacementGroupsRenameDrawer.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,33 @@ | ||
import * as React from 'react'; | ||
|
||
import { placementGroupFactory } from 'src/factories/placementGroups'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsRenameDrawer } from './PlacementGroupsRenameDrawer'; | ||
|
||
describe('PlacementGroupsCreateDrawer', () => { | ||
it('should render have the proper fields populated with PG values, and disabled', () => { | ||
const { getByLabelText } = renderWithTheme( | ||
<PlacementGroupsRenameDrawer | ||
selectedPlacementGroup={placementGroupFactory.build({ | ||
affinity_type: 'anti_affinity', | ||
label: 'PG-1', | ||
region: 'us-east', | ||
})} | ||
numberOfPlacementGroupsCreated={0} | ||
onClose={vi.fn()} | ||
onPlacementGroupRenamed={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Label')).toBeEnabled(); | ||
expect(getByLabelText('Label')).toHaveValue('PG-1'); | ||
|
||
expect(getByLabelText('Region')).toBeDisabled(); | ||
expect(getByLabelText('Region')).toHaveValue('Newark, NJ (us-east)'); | ||
|
||
expect(getByLabelText('Affinity Type')).toBeDisabled(); | ||
expect(getByLabelText('Affinity Type')).toHaveValue('Anti-affinity'); | ||
}); | ||
}); |
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