Skip to content

Commit d07cb80

Browse files
refactor(kvm): Refactor RamResources to GenericTable MAASENG-5682 (#5866)
1 parent 3346a84 commit d07cb80

File tree

10 files changed

+402
-284
lines changed

10 files changed

+402
-284
lines changed

cypress/e2e/with-users/login/login.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ context("Login page", () => {
66
cy.expandMainNavigation();
77
});
88

9-
it("is disabled by default", () => {
10-
cy.findByRole("button", { name: "Login" }).should("be.disabled");
11-
});
12-
139
it("displays an error message if submitted invalid login credentials", () => {
1410
cy.findByRole("textbox", { name: /Username/ }).type("invalid-username");
1511
cy.findByRole("button", { name: /Next/ }).click();

src/app/base/components/AppSideNavigation/AppSideNavigation.test.tsx

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -359,43 +359,6 @@ describe("GlobalSideNav", () => {
359359
).toHaveAttribute("href", "/machines");
360360
});
361361

362-
it("redirects to the intro page if intro not completed", async () => {
363-
state.config.items = [
364-
factory.config({ name: ConfigNames.COMPLETED_INTRO, value: false }),
365-
];
366-
renderWithProviders(<AppSideNavigation />, {
367-
initialEntries: ["/machines"],
368-
state,
369-
});
370-
await waitFor(() => {
371-
expect(authResolvers.getCurrentUser.resolved).toBe(true);
372-
});
373-
await waitFor(() => {
374-
expect(mockUseNavigate.mock.calls[0][0].pathname).toBe(urls.intro.index);
375-
});
376-
});
377-
378-
it("redirects to the user intro page if user intro not completed", async () => {
379-
state.config.items = [
380-
factory.config({ name: ConfigNames.COMPLETED_INTRO, value: true }),
381-
];
382-
mockServer.use(
383-
authResolvers.getCurrentUser.handler(
384-
factory.user({ completed_intro: false })
385-
)
386-
);
387-
renderWithProviders(<AppSideNavigation />, {
388-
initialEntries: ["/machines"],
389-
state,
390-
});
391-
await waitFor(() => {
392-
expect(authResolvers.getCurrentUser.resolved).toBe(true);
393-
});
394-
await waitFor(() => {
395-
expect(mockUseNavigate.mock.calls[0][0].pathname).toBe(urls.intro.user);
396-
});
397-
});
398-
399362
it("does not redirect if the intro is being displayed", async () => {
400363
state.config.items = [
401364
factory.config({ name: ConfigNames.COMPLETED_INTRO, value: false }),

src/app/base/components/AppSideNavigation/AppSideNavigation.tsx

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactElement } from "react";
2-
import { useEffect, useMemo } from "react";
2+
import { useMemo } from "react";
33

44
import { Navigation, NavigationBar } from "@canonical/maas-react-components";
55
import {
@@ -9,7 +9,7 @@ import {
99
Tooltip,
1010
} from "@canonical/react-components";
1111
import { useSelector } from "react-redux";
12-
import { useLocation, useMatch, useNavigate } from "react-router";
12+
import { useLocation } from "react-router";
1313
import { useStorageState } from "react-storage-hooks";
1414

1515
import { useLogout } from "../../hooks/logout";
@@ -29,9 +29,6 @@ import {
2929
} from "@/app/base/hooks";
3030
import { useGlobalKeyShortcut } from "@/app/base/hooks/base";
3131
import { useThemeContext } from "@/app/base/theme-context";
32-
import type { SyncNavigateFunction } from "@/app/base/types";
33-
import urls from "@/app/base/urls";
34-
import configSelectors from "@/app/store/config/selectors";
3532
import { controllerActions } from "@/app/store/controller";
3633
import controllerSelectors from "@/app/store/controller/selectors";
3734
import { podActions } from "@/app/store/pod";
@@ -136,46 +133,19 @@ export const AppSideNavigation = ({
136133
);
137134

138135
const AppSideNavigationContainer = (): React.ReactElement => {
139-
const navigate: SyncNavigateFunction = useNavigate();
140136
const location = useLocation();
141-
const configLoaded = useSelector(configSelectors.loaded);
142137
const path = location.pathname;
143138
const user = useGetCurrentUser();
144139
const completedIntro = useCompletedIntro();
145140
const completedUserIntro = useCompletedUserIntro();
146141
const isAuthenticated = !!user.data;
147-
const introMatch = useMatch({ path: urls.intro.index, end: false });
148-
const isAtIntro = !!introMatch;
149142
const showLinks = isAuthenticated && completedIntro && completedUserIntro;
150143
useGoogleAnalytics();
151144

152145
const logout = useLogout();
153146

154147
const [isDarkMode, toggleDarkMode] = useDarkMode();
155148

156-
// Redirect to the intro pages if not completed.
157-
useEffect(() => {
158-
// Check that we're not already at the intro to allow navigation through the
159-
// intro pages. This is necessary beacuse this useEffect runs every time
160-
// there is a navigation change as the `navigate` function is regenerated
161-
// for every route change, see:
162-
// https://github.com/remix-run/react-router/issues/7634
163-
if (!isAtIntro && configLoaded) {
164-
if (!completedIntro) {
165-
navigate({ pathname: urls.intro.index }, { replace: true });
166-
} else if (isAuthenticated && !completedUserIntro) {
167-
navigate({ pathname: urls.intro.user }, { replace: true });
168-
}
169-
}
170-
}, [
171-
completedIntro,
172-
completedUserIntro,
173-
configLoaded,
174-
isAtIntro,
175-
isAuthenticated,
176-
navigate,
177-
]);
178-
179149
useFetchActions([controllerActions.fetch]);
180150

181151
useFetchActions([podActions.fetch]);

src/app/kvm/components/LXDHostVMs/NumaResources/NumaResourcesCard/NumaResourcesCard.test.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import configureStore from "redux-mock-store";
2-
31
import NumaResourcesCard from "./NumaResourcesCard";
42

53
import { machineActions } from "@/app/store/machine";
6-
import type { RootState } from "@/app/store/root/types";
74
import * as factory from "@/testing/factories";
8-
import { renderWithMockStore, screen, within } from "@/testing/utils";
9-
10-
const mockStore = configureStore<RootState>();
5+
import { renderWithProviders, screen, within } from "@/testing/utils";
116

127
describe("NumaResourcesCard", () => {
138
afterEach(() => {
@@ -25,11 +20,12 @@ describe("NumaResourcesCard", () => {
2520
const state = factory.rootState({
2621
pod: factory.podState({ items: [pod] }),
2722
});
28-
const store = mockStore(state);
29-
30-
renderWithMockStore(<NumaResourcesCard numaId={111} podId={1} />, {
31-
store,
32-
});
23+
const { store } = renderWithProviders(
24+
<NumaResourcesCard numaId={111} podId={1} />,
25+
{
26+
state,
27+
}
28+
);
3329

3430
const expectedAction = machineActions.fetch("mocked-nanoid");
3531
expect(
@@ -66,9 +62,11 @@ describe("NumaResourcesCard", () => {
6662
pod: factory.podState({ items: [pod] }),
6763
});
6864

69-
renderWithMockStore(<NumaResourcesCard numaId={11} podId={1} />, { state });
65+
renderWithProviders(<NumaResourcesCard numaId={11} podId={1} />, { state });
7066

71-
const hugepagesData = screen.getByTestId("hugepages-data");
67+
const hugepagesData = screen.getByRole("row", {
68+
name: new RegExp(`^Hugepage`, "i"),
69+
});
7270
expect(within(hugepagesData).getByText("(Size: 1KiB)")).toBeInTheDocument();
7371
expect(within(hugepagesData).getAllByRole("cell")[1]).toHaveTextContent(
7472
"5B"
@@ -96,7 +94,7 @@ describe("NumaResourcesCard", () => {
9694
pod: factory.podState({ items: [pod] }),
9795
});
9896

99-
renderWithMockStore(<NumaResourcesCard numaId={111} podId={1} />, {
97+
renderWithProviders(<NumaResourcesCard numaId={111} podId={1} />, {
10098
state,
10199
});
102100

@@ -138,9 +136,10 @@ describe("NumaResourcesCard", () => {
138136
machine: factory.machineState({ items: machines }),
139137
pod: factory.podState({ items: [pod] }),
140138
});
141-
const store = mockStore(state);
142-
143-
renderWithMockStore(<NumaResourcesCard numaId={11} podId={1} />, { store });
139+
const { store } = renderWithProviders(
140+
<NumaResourcesCard numaId={11} podId={1} />,
141+
{ state }
142+
);
144143

145144
const expected = machineActions.fetch("mocked-nanoid");
146145
const result = store

0 commit comments

Comments
 (0)