Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Replace Formik with React Hook Form in DatabaseManageNetworkingDrawer ([#13002](https://github.com/linode/manager/pull/13002))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to add a changeset to the other PR so adding it here!

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Replace Formik with React Hook Form in ManageAccessControlDrawer ([#13044](https://github.com/linode/manager/pull/13044))
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TableBody } from 'src/components/TableBody';
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';

import AddAccessControlDrawer from './AddAccessControlDrawer';
import { ManageAccessControlDrawer } from './ManageAccessControlDrawer';

import type { APIError, Database } from '@linode/api-v4';
import type { Theme } from '@mui/material/styles';
Expand Down Expand Up @@ -93,7 +93,7 @@ export const AccessControls = (props: Props) => {
const [accessControlToBeRemoved, setAccessControlToBeRemoved] =
React.useState<null | string>(null);

const [addAccessControlDrawerOpen, setAddAccessControlDrawerOpen] =
const [manageAccessControlDrawerOpen, setManageAccessControlDrawerOpen] =
React.useState<boolean>(false);

const { isPending: databaseUpdating, mutateAsync: updateDatabase } =
Expand Down Expand Up @@ -176,7 +176,7 @@ export const AccessControls = (props: Props) => {
className={classes.addAccessControlBtn}
data-testid="button-access-control"
disabled={disabled}
onClick={() => setAddAccessControlDrawerOpen(true)}
onClick={() => setManageAccessControlDrawerOpen(true)}
variant="secondary"
>
Manage Access
Expand All @@ -197,10 +197,10 @@ export const AccessControls = (props: Props) => {
address.
</Typography>
</ConfirmationDialog>
<AddAccessControlDrawer
<ManageAccessControlDrawer
database={database}
onClose={() => setAddAccessControlDrawerOpen(false)}
open={addAccessControlDrawerOpen}
onClose={() => setManageAccessControlDrawerOpen(false)}
open={manageAccessControlDrawerOpen}
/>
</>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, screen } from '@testing-library/react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';

Expand All @@ -7,22 +7,21 @@
import { mockMatchMedia, renderWithTheme } from 'src/utilities/testHelpers';

import AccessControls from './AccessControls';
import AddAccessControlDrawer from './AddAccessControlDrawer';
import { ManageAccessControlDrawer } from './ManageAccessControlDrawer';

import type { DatabaseInstance } from '@linode/api-v4';

Comment thread
hana-akamai marked this conversation as resolved.
beforeAll(() => mockMatchMedia());

describe('Add Access Controls drawer', () => {
const database = databaseFactory.build();
const { getByTestId } = renderWithTheme(
<AccessControls database={database} />
);

const button = getByTestId('button-access-control');
fireEvent.click(button);
describe('Manage Access Controls drawer', () => {
it('Should open when a user clicks the Manage Access Controls button', async () => {
const database = databaseFactory.build();
const { getByTestId } = renderWithTheme(
<AccessControls database={database} />
);

it('Should open when a user clicks the Add Access Controls button', () => {
const button = getByTestId('button-access-control');
await userEvent.click(button);
// 'drawer' is the data-testid of the <Drawer /> component
expect(getByTestId('drawer')).toBeVisible();
});
Expand All @@ -35,7 +34,11 @@
id: 123,
} as DatabaseInstance;
const { getAllByTestId } = renderWithTheme(
<AddAccessControlDrawer database={db} onClose={() => null} open={true} />
<ManageAccessControlDrawer
database={db}
onClose={() => null}
open={true}
/>
);

expect(getAllByTestId('domain-transfer-input')).toHaveLength(
Expand All @@ -54,19 +57,26 @@
id: 123,
} as DatabaseInstance;
const { getByText } = renderWithTheme(
<AddAccessControlDrawer database={db} onClose={() => null} open={true} />
<ManageAccessControlDrawer
database={db}
onClose={() => null}
open={true}
/>
);

const addAccessControlsButton = getByText('Update Access Controls').closest(
'button'
);
const updateAccessControlsButton = getByText(
'Update Access Controls'
).closest('button');

Check warning on line 69 in packages/manager/src/features/Databases/DatabaseDetail/ManageAccessControlDrawer.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Avoid direct Node access. Prefer using the methods from Testing Library. Raw Output: {"ruleId":"testing-library/no-node-access","severity":1,"message":"Avoid direct Node access. Prefer using the methods from Testing Library.","line":69,"column":7,"nodeType":"MemberExpression","messageId":"noNodeAccess"}

Check warning on line 69 in packages/manager/src/features/Databases/DatabaseDetail/ManageAccessControlDrawer.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Avoid direct Node access. Prefer using the methods from Testing Library. Raw Output: {"ruleId":"testing-library/no-node-access","severity":1,"message":"Avoid direct Node access. Prefer using the methods from Testing Library.","line":69,"column":7,"nodeType":"MemberExpression","messageId":"noNodeAccess"}

// Before making a change to the IP addresses, the "Add Inbound Sources" button should be disabled.
expect(addAccessControlsButton).toHaveAttribute('aria-disabled', 'true');
expect(updateAccessControlsButton).toHaveAttribute('aria-disabled', 'true');

const addAnIPButton = getByText('Add Another IP');
await userEvent.click(addAnIPButton);

expect(addAccessControlsButton).toHaveAttribute('aria-disabled', 'false');
expect(updateAccessControlsButton).toHaveAttribute(
'aria-disabled',
'false'
);
});
});
Loading