Skip to content

refactor(site): make minor design tweaks and fix issues on more options menus #10493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 3, 2023
Merged
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
BrunoQuaresma committed Nov 2, 2023
commit db70ee131b2b00389031844842e3aa2e00187a41
4 changes: 2 additions & 2 deletions site/src/components/MoreMenu/MoreMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export const MoreMenuTrigger = (props: IconButtonProps) => {

return (
<IconButton
aria-controls="menu-options"
aria-controls="more-options"
aria-label="More options"
aria-haspopup="true"
onClick={menu.open}
ref={menu.triggerRef}
arial-label="More options"
{...props}
>
<MoreVertOutlined />
Expand Down
31 changes: 13 additions & 18 deletions site/src/pages/UsersPage/UsersPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, screen, within } from "@testing-library/react";
import { fireEvent, prettyDOM, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { rest } from "msw";
import {
Expand All @@ -21,12 +21,11 @@ const renderPage = () => {
const suspendUser = async () => {
const user = userEvent.setup();
// Get the first user in the table
const moreButtons = await screen.findAllByLabelText("more");
const moreButtons = await screen.findAllByLabelText("More options");
const firstMoreButton = moreButtons[0];
await user.click(firstMoreButton);

const menu = await screen.findByRole("menu");
const suspendButton = within(menu).getByText(/Suspend/);
const suspendButton = screen.getByTestId("suspend-button");
await user.click(suspendButton);

// Check if the confirm message is displayed
Expand All @@ -39,17 +38,15 @@ const suspendUser = async () => {

const deleteUser = async () => {
const user = userEvent.setup();
// Click on the "more" button to display the "Delete" option
// Click on the "More options" button to display the "Delete" option
// Needs to await fetching users and fetching permissions, because they're needed to see the more button
const moreButtons = await screen.findAllByLabelText("more");
const moreButtons = await screen.findAllByLabelText("More options");
// get MockUser2
const selectedMoreButton = moreButtons[1];

await user.click(selectedMoreButton);

const menu = await screen.findByRole("menu");
const deleteButton = within(menu).getByText(/Delete/);

const deleteButton = screen.getByText(/Delete/);
await user.click(deleteButton);

// Check if the confirm message is displayed
Expand All @@ -67,12 +64,11 @@ const deleteUser = async () => {
};

const activateUser = async () => {
const moreButtons = await screen.findAllByLabelText("more");
const moreButtons = await screen.findAllByLabelText("More options");
const suspendedMoreButton = moreButtons[2];
fireEvent.click(suspendedMoreButton);

const menu = screen.getByRole("menu");
const activateButton = within(menu).getByText(/Activate/);
const activateButton = screen.getByText(/Activate/);
fireEvent.click(activateButton);

// Check if the confirm message is displayed
Expand All @@ -86,14 +82,11 @@ const activateUser = async () => {
};

const resetUserPassword = async (setupActionSpies: () => void) => {
const moreButtons = await screen.findAllByLabelText("more");
const moreButtons = await screen.findAllByLabelText("More options");
const firstMoreButton = moreButtons[0];

fireEvent.click(firstMoreButton);

const menu = screen.getByRole("menu");
const resetPasswordButton = within(menu).getByText(/Reset password/);

const resetPasswordButton = screen.getByText(/Reset password/);
fireEvent.click(resetPasswordButton);

// Check if the confirm message is displayed
Expand Down Expand Up @@ -135,10 +128,12 @@ const updateUserRole = async (role: Role) => {
};
};

jest.spyOn(console, "error").mockImplementation(() => {});

describe("UsersPage", () => {
describe("suspend user", () => {
describe("when it is success", () => {
it("shows a success message", async () => {
it.only("shows a success message", async () => {
renderPage();

server.use(
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/UsersPage/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const UsersTable: FC<React.PropsWithChildren<UsersTableProps>> = ({
}) => {
return (
<TableContainer>
<Table>
<Table data-testid="users-table">
<TableHead>
<TableRow>
<TableCell width="29%">{Language.usernameLabel}</TableCell>
Expand Down
9 changes: 7 additions & 2 deletions site/src/pages/UsersPage/UsersTable/UsersTableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ export const UsersTableBody: FC<
<TableCell>
<MoreMenu>
<MoreMenuTrigger />
<MoreMenuContent keepMounted>
<MoreMenuContent>
{user.status === "active" || user.status === "dormant" ? (
<MoreMenuItem onClick={() => onSuspendUser(user)}>
<MoreMenuItem
data-testid="suspend-button"
onClick={() => {
onSuspendUser(user);
}}
>
Suspend&hellip;
</MoreMenuItem>
) : (
Expand Down