Skip to content
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

fix(users): Adding/editing user no longer shows "Deleted" message MAASENG-2797 #5339

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading