-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(LXD): Link to VMs tab for single LXD hosts MAASENG-2412 (#5216)
Co-authored-by: Peter Makowski <peter.makowski@canonical.com>
- Loading branch information
1 parent
4baef7f
commit 3031600
Showing
3 changed files
with
53 additions
and
18 deletions.
There are no files selected for viewing
47 changes: 30 additions & 17 deletions
47
src/app/kvm/components/KVMResourcesCard/KVMResourcesCard.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,68 @@ | ||
import configureStore from "redux-mock-store"; | ||
|
||
import KVMResourcesCard from "./KVMResourcesCard"; | ||
|
||
import { actions as machineActions } from "app/store/machine"; | ||
import urls from "app/base/urls"; | ||
import { PodType } from "app/store/pod/constants"; | ||
import type { RootState } from "app/store/root/types"; | ||
import { | ||
podState as podStateFactory, | ||
rootState as rootStateFactory, | ||
pod as podFactory, | ||
} from "testing/factories"; | ||
import { renderWithBrowserRouter, screen } from "testing/utils"; | ||
|
||
const mockStore = configureStore<RootState>(); | ||
|
||
describe("KVMResourcesCard", () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it("fetches machines on load", () => { | ||
it("shows a spinner if pods have not loaded yet", () => { | ||
const state = rootStateFactory({ | ||
pod: podStateFactory({ | ||
items: [], | ||
loaded: false, | ||
}), | ||
}); | ||
renderWithBrowserRouter(<KVMResourcesCard id={1} />, { | ||
state, | ||
route: "/kvm/1/project", | ||
}); | ||
|
||
expect(screen.getByText(/Loading/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it("links to the VMs tab for a LXD pod", () => { | ||
const state = rootStateFactory({ | ||
pod: podStateFactory({ | ||
items: [podFactory({ id: 1, type: PodType.LXD })], | ||
loaded: true, | ||
}), | ||
}); | ||
const store = mockStore(state); | ||
|
||
renderWithBrowserRouter(<KVMResourcesCard id={1} />, { | ||
store, | ||
state, | ||
route: "/kvm/1/project", | ||
}); | ||
|
||
const expectedAction = machineActions.fetch("mocked-nanoid"); | ||
expect( | ||
store.getActions().some((action) => action.type === expectedAction.type) | ||
).toBe(true); | ||
expect(screen.getByRole("link", { name: /Total VMs/ })).toHaveAttribute( | ||
"href", | ||
urls.kvm.lxd.single.vms({ id: 1 }) | ||
); | ||
}); | ||
|
||
it("shows a spinner if pods have not loaded yet", () => { | ||
it("displays VmResources for a Virsh pod", () => { | ||
const state = rootStateFactory({ | ||
pod: podStateFactory({ | ||
items: [], | ||
loaded: false, | ||
items: [podFactory({ id: 1, type: PodType.VIRSH })], | ||
loaded: true, | ||
}), | ||
}); | ||
|
||
renderWithBrowserRouter(<KVMResourcesCard id={1} />, { | ||
state, | ||
route: "/kvm/1/project", | ||
}); | ||
|
||
expect(screen.getByText(/Loading/i)).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole("button", { name: /Resource VMs/ }) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,8 @@ | |
} | ||
} | ||
} | ||
|
||
.vms-link { | ||
padding: $spv--large; | ||
} | ||
} |