Skip to content

Commit

Permalink
fix(users): Adding/editing user no longer shows "Deleted" message MAA…
Browse files Browse the repository at this point in the history
…SENG-2797 (#5339)
  • Loading branch information
ndv99 committed Mar 12, 2024
1 parent 48836ea commit d9346e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
17 changes: 17 additions & 0 deletions src/app/settings/views/Users/UserDelete/UserDelete.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import configureStore from "redux-mock-store";

import UserDelete from "./UserDelete";

import type { RootState } from "@/app/store/root/types";
Expand All @@ -11,6 +13,8 @@ import { renderWithBrowserRouter, screen } from "@/testing/utils";

let state: RootState;

const mockStore = configureStore<RootState>();

beforeEach(() => {
state = rootStateFactory({
status: statusStateFactory({
Expand Down Expand Up @@ -41,3 +45,16 @@ it("renders", () => {
});
expect(screen.getByRole("form", { name: "Delete user" }));
});

it("can add a message when a user is deleted", () => {
state.user.saved = true;
const store = mockStore(state);
renderWithBrowserRouter(<UserDelete />, {
store,
route: "/settings/users/1/edit",
routePattern: "/settings/users/:id/edit",
});
const actions = store.getActions();
expect(actions.some((action) => action.type === "user/cleanup")).toBe(true);
expect(actions.some((action) => action.type === "message/add")).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const UserDeleteForm = ({ user }: UserDeleteProps) => {
useAddMessage(
saved && !errors,
userActions.cleanup,
`Deleted ${deletedUser} from list`
`${deletedUser} removed successfully`
);

return (
Expand Down
19 changes: 0 additions & 19 deletions src/app/settings/views/Users/UsersList/UsersList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,6 @@ describe("UsersList", () => {
);
});

it("can add a message when a user is deleted", () => {
state.user.saved = true;
const store = mockStore(state);
render(
<Provider store={store}>
<MemoryRouter
initialEntries={[{ pathname: "/settings/users", key: "testKey" }]}
>
<CompatRouter>
<UsersList />
</CompatRouter>
</MemoryRouter>
</Provider>
);
const actions = store.getActions();
expect(actions.some((action) => action.type === "user/cleanup")).toBe(true);
expect(actions.some((action) => action.type === "message/add")).toBe(true);
});

it("can filter users", async () => {
const store = mockStore(state);
const { rerender } = render(
Expand Down
10 changes: 0 additions & 10 deletions src/app/settings/views/Users/UsersList/UsersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import TableActions from "@/app/base/components/TableActions";
import TableHeader from "@/app/base/components/TableHeader";
import {
useFetchActions,
useAddMessage,
useTableSort,
useWindowTitle,
} from "@/app/base/hooks";
Expand Down Expand Up @@ -101,14 +100,12 @@ const getSortValue = (sortKey: SortKey, user: User) => {
const UsersList = (): JSX.Element => {
const [searchText, setSearchText] = useState("");
const [displayUsername, setDisplayUsername] = useState(true);
const [deletingUser, setDeleting] = useState<User["username"] | null>(null);
const users = useSelector((state: RootState) =>
userSelectors.search(state, searchText)
);
const loading = useSelector(userSelectors.loading);
const loaded = useSelector(userSelectors.loaded);
const authUser = useSelector(authSelectors.get);
const saved = useSelector(userSelectors.saved);
const externalAuthURL = useSelector(statusSelectors.externalAuthURL);
const dispatch = useDispatch();

Expand All @@ -124,13 +121,6 @@ const UsersList = (): JSX.Element => {

useWindowTitle("Users");

useAddMessage(
saved,
userActions.cleanup,
`${deletingUser} removed successfully.`,
() => setDeleting(null)
);

useFetchActions([userActions.fetch]);

useEffect(() => {
Expand Down

0 comments on commit d9346e6

Please sign in to comment.