-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [M3-7311] - Create Load Balancer flow - manage state (#9848)
* feat: [M3-7311] - Create Load Balancer flow - Mange state. * Code cleanup * Added changeset: Create Load Balancer flow - Mange state. * Update pr-9848-upcoming-features-1698675578462.md * Update update-database.spec.ts * Update packages/manager/.changeset/pr-9848-upcoming-features-1698675578462.md Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> * Fix typos * use useFormikContext instead of custom state management hook * PR feedback * Update loadbalancers.schema.ts * Update packages/validation/src/loadbalancers.schema.ts Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> * Update packages/validation/src/loadbalancers.schema.ts Co-authored-by: jdamore-linode <97627410+jdamore-linode@users.noreply.github.com> * Update loadbalancers.schema.ts * Update CreateLoadBalancerSchema and Endpoint Schema * Revert "Update CreateLoadBalancerSchema and Endpoint Schema" This reverts commit 106f4d1. * Code cleanup and update Endpoint schema. * Update the field names * Added changeset: Create Load Balancer flow - manage state --------- Co-authored-by: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> Co-authored-by: jdamore-linode <97627410+jdamore-linode@users.noreply.github.com>
- Loading branch information
1 parent
ec48b0e
commit 3ea7090
Showing
11 changed files
with
239 additions
and
82 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9848-upcoming-features-1698675578462.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 | ||
--- | ||
|
||
Create Load Balancer flow - manage state ([#9848](https://github.com/linode/manager/pull/9848)) |
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
27 changes: 27 additions & 0 deletions
27
packages/manager/src/features/LoadBalancers/LoadBalancerCreate/LoadBalancerActionPanel.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,27 @@ | ||
import { useFormikContext } from 'formik'; | ||
import * as React from 'react'; | ||
|
||
import { Box } from 'src/components/Box'; | ||
import { Button } from 'src/components/Button/Button'; | ||
|
||
export const LoadBalancerActionPanel = () => { | ||
const { submitForm } = useFormikContext(); | ||
return ( | ||
<Box | ||
columnGap={1} | ||
display="flex" | ||
flexWrap="wrap" | ||
justifyContent="space-between" | ||
rowGap={3} | ||
> | ||
<Button buttonType="outlined">Add Another Configuration</Button> | ||
<Button | ||
buttonType="primary" | ||
onClick={submitForm} | ||
sx={{ marginLeft: 'auto' }} | ||
> | ||
Review Load Balancer | ||
</Button> | ||
</Box> | ||
); | ||
}; |
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
79 changes: 52 additions & 27 deletions
79
packages/manager/src/features/LoadBalancers/LoadBalancerCreate/LoadBalancerLabel.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,49 +1,74 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import { Formik } from 'formik'; | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { LoadBalancerLabel } from './LoadBalancerLabel'; | ||
|
||
const loadBalancerLabelValue = 'Test Label'; | ||
const loadBalancerTestId = 'textfield-input'; | ||
|
||
import type { CreateLoadbalancerPayload } from '@linode/api-v4'; | ||
|
||
type MockFormikContext = { | ||
initialErrors?: {}; | ||
initialTouched?: {}; | ||
initialValues: CreateLoadbalancerPayload; | ||
}; | ||
|
||
const initialValues = { | ||
label: loadBalancerLabelValue, | ||
regions: [], | ||
}; | ||
|
||
const renderWithFormikWrapper = (mockFormikContext: MockFormikContext) => | ||
renderWithTheme( | ||
<Formik {...mockFormikContext} onSubmit={jest.fn()}> | ||
<LoadBalancerLabel /> | ||
</Formik> | ||
); | ||
|
||
describe('LoadBalancerLabel', () => { | ||
it('should render the component with a label and no error', () => { | ||
const labelFieldProps = { | ||
disabled: false, | ||
errorText: '', | ||
label: 'Load Balancer Label', | ||
onChange: jest.fn(), | ||
value: 'Test Label', | ||
}; | ||
|
||
const { getByTestId, queryByText } = renderWithTheme( | ||
<LoadBalancerLabel error="" labelFieldProps={labelFieldProps} /> | ||
); | ||
|
||
const labelInput = getByTestId('textfield-input'); | ||
const { getByTestId, queryByText } = renderWithFormikWrapper({ | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
const errorNotice = queryByText('Error Text'); | ||
|
||
expect(labelInput).toBeInTheDocument(); | ||
expect(labelInput).toHaveAttribute('placeholder', 'Enter a label'); | ||
expect(labelInput).toHaveValue('Test Label'); | ||
expect(labelInput).toHaveValue(loadBalancerLabelValue); | ||
expect(errorNotice).toBeNull(); | ||
}); | ||
|
||
it('should render the component with an error message', () => { | ||
const labelFieldProps = { | ||
disabled: false, | ||
errorText: 'This is an error', | ||
label: 'Load Balancer Label', | ||
onChange: jest.fn(), | ||
value: 'Test Label', | ||
}; | ||
|
||
const { getByTestId, getByText } = renderWithTheme( | ||
<LoadBalancerLabel error="Error Text" labelFieldProps={labelFieldProps} /> | ||
); | ||
|
||
const labelInput = getByTestId('textfield-input'); | ||
const { getByTestId, getByText } = renderWithFormikWrapper({ | ||
initialErrors: { label: 'This is an error' }, | ||
initialTouched: { label: true }, | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
const errorNotice = getByText('This is an error'); | ||
|
||
expect(labelInput).toBeInTheDocument(); | ||
expect(errorNotice).toBeInTheDocument(); | ||
}); | ||
|
||
it('should update formik values on input change', () => { | ||
const { getByTestId } = renderWithFormikWrapper({ | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
|
||
// Simulate typing 'New Label' in the input field | ||
fireEvent.change(labelInput, { target: { value: 'New Label' } }); | ||
|
||
// Expect the input to have the new value | ||
expect(labelInput).toHaveValue('New Label'); | ||
}); | ||
}); |
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/validation/.changeset/pr-9848-upcoming-features-1698944870213.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/validation": Upcoming Features | ||
--- | ||
|
||
Create Load Balancer flow - manage state ([#9848](https://github.com/linode/manager/pull/9848)) |
Oops, something went wrong.