Skip to content

test(site): move users page test to storybook #14579

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
Sep 6, 2024
Merged
2 changes: 1 addition & 1 deletion site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ class ApiMethods {
updateUserPassword = async (
userId: TypesGen.User["id"],
updatePassword: TypesGen.UpdateUserPasswordRequest,
): Promise<undefined> => {
): Promise<void> => {
await this.axios.put(`/api/v2/users/${userId}/password`, updatePassword);
};

Expand Down
4 changes: 3 additions & 1 deletion site/src/api/queries/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { API } from "api/api";

export const deploymentConfigQueryKey = ["deployment", "config"];

export const deploymentConfig = () => {
return {
queryKey: ["deployment", "config"],
queryKey: deploymentConfigQueryKey,
queryFn: API.getDeploymentConfig,
};
};
Expand Down
42 changes: 22 additions & 20 deletions site/src/api/queries/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { QueryClient, UseQueryOptions } from "react-query";

type GroupSortOrder = "asc" | "desc";

const groupsQueryKey = ["groups"];
export const groupsQueryKey = ["groups"];

export const groups = () => {
return {
Expand Down Expand Up @@ -49,27 +49,29 @@ export type GroupsByUserId = Readonly<Map<string, readonly Group[]>>;
export function groupsByUserId() {
return {
...groups(),
select: (allGroups) => {
// Sorting here means that nothing has to be sorted for the individual
// user arrays later
const sorted = sortGroupsByName(allGroups, "asc");
const userIdMapper = new Map<string, Group[]>();

for (const group of sorted) {
for (const user of group.members) {
let groupsForUser = userIdMapper.get(user.id);
if (groupsForUser === undefined) {
groupsForUser = [];
userIdMapper.set(user.id, groupsForUser);
}

groupsForUser.push(group);
}
select: selectGroupsByUserId,
} satisfies UseQueryOptions<Group[], unknown, GroupsByUserId>;
}

export function selectGroupsByUserId(groups: Group[]): GroupsByUserId {
// Sorting here means that nothing has to be sorted for the individual
// user arrays later
const sorted = sortGroupsByName(groups, "asc");
const userIdMapper = new Map<string, Group[]>();

for (const group of sorted) {
for (const user of group.members) {
let groupsForUser = userIdMapper.get(user.id);
if (groupsForUser === undefined) {
groupsForUser = [];
userIdMapper.set(user.id, groupsForUser);
}

return userIdMapper as GroupsByUserId;
},
} satisfies UseQueryOptions<Group[], unknown, GroupsByUserId>;
groupsForUser.push(group);
}
}

return userIdMapper as GroupsByUserId;
}

export function groupsForUser(userId: string) {
Expand Down
4 changes: 3 additions & 1 deletion site/src/api/queries/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const getRoleQueryKey = (organizationId: string, roleName: string) => [
roleName,
];

export const rolesQueryKey = ["roles"];

export const roles = () => {
return {
queryKey: ["roles"],
queryKey: rolesQueryKey,
queryFn: API.getRoles,
};
};
Expand Down
4 changes: 3 additions & 1 deletion site/src/api/queries/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ export const updateRoles = (queryClient: QueryClient) => {
};
};

export const authMethodsQueryKey = ["authMethods"];

export const authMethods = () => {
return {
// Even the endpoint being /users/authmethods we don't want to revalidate it
// when users change so its better add a unique query key
queryKey: ["authMethods"],
queryKey: authMethodsQueryKey,
queryFn: API.getAuthMethods,
};
};
Expand Down
30 changes: 15 additions & 15 deletions site/src/components/Filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,21 @@ const PresetMenu: FC<PresetMenuProps> = ({
</MenuItem>
))}
{learnMoreLink && (
<>
<Divider css={{ borderColor: theme.palette.divider }} />
<MenuItem
component="a"
href={learnMoreLink}
target="_blank"
css={{ fontSize: 13, fontWeight: 500 }}
onClick={() => {
setIsOpen(false);
}}
>
<OpenInNewOutlined css={{ fontSize: "14px !important" }} />
View advanced filtering
</MenuItem>
</>
<Divider css={{ borderColor: theme.palette.divider }} />
)}
{learnMoreLink && (
<MenuItem
component="a"
href={learnMoreLink}
target="_blank"
css={{ fontSize: 13, fontWeight: 500 }}
onClick={() => {
setIsOpen(false);
}}
>
<OpenInNewOutlined css={{ fontSize: "14px !important" }} />
View advanced filtering
</MenuItem>
)}
{learnMoreLink2 && learnMoreLabel2 && (
<MenuItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const updateUserRole = async (role: SlimRole) => {
}

// Click on the "edit icon" to display the role options
const editButton = within(userRow).getByTitle("Edit user roles");
const editButton = within(userRow).getByLabelText("Edit user roles");
fireEvent.click(editButton);

// Click on the role option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Interpolation, Theme } from "@emotion/react";
import UserIcon from "@mui/icons-material/PersonOutline";
import Checkbox from "@mui/material/Checkbox";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import type { SlimRole } from "api/typesGenerated";
import {
HelpTooltip,
Expand Down Expand Up @@ -116,13 +117,15 @@ export const EditRolesButton: FC<EditRolesButtonProps> = ({
return (
<Popover>
<PopoverTrigger>
<IconButton
size="small"
css={styles.editButton}
title="Edit user roles"
>
<EditSquare />
</IconButton>
<Tooltip title="Edit user roles">
<IconButton
aria-label="Edit user roles"
size="small"
css={styles.editButton}
>
<EditSquare />
</IconButton>
</Tooltip>
</PopoverTrigger>

<PopoverContent classes={{ paper }}>
Expand Down
Loading
Loading