UI - GitOps mode, part 2 (#26509)

## For #26229 

This is the 2nd iterative PR for this ticket. It includes:
- tests with a new testing utility
- refactored argument and class names
- another batch of UI updates

- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
jacobshandling
2025-02-21 12:22:08 -08:00
committed by GitHub
co-authored by Jacob Shandling
parent a748e923c8
commit 391bd0a5a0
53 changed files with 1303 additions and 867 deletions
@@ -0,0 +1,89 @@
import React from "react";
import { noop } from "lodash";
import { screen } from "@testing-library/react";
import { createCustomRenderer } from "test/test-utils";
import Button from "components/buttons/Button";
import GitOpsModeTooltipWrapper from "./GitOpsModeTooltipWrapper";
describe("GitOpsModeTooltipWrapper", () => {
it("renders clickable children without a tooltip when GOM is not enabled", async () => {
const render = createCustomRenderer({
context: {
app: {
isGlobalAdmin: true,
isTeamAdmin: false,
// thanks, DeepPartial!
config: {
gitops: {
gitops_mode_enabled: false,
repository_url: "",
},
},
},
},
});
const onSave = jest.fn();
const { user } = render(
<GitOpsModeTooltipWrapper
renderChildren={(disableChildren) => (
<Button disabled={disableChildren} onClick={onSave} variant="brand">
Save
</Button>
)}
/>
);
const btn = screen.getByText("Save");
expect(btn).toBeInTheDocument();
await user.hover(btn);
expect(screen.queryByRole("tooltip")).toBeNull();
await user.click(btn);
expect(onSave).toHaveBeenCalled();
});
it("renders non-clickable children with the tooltip when GOM is enabled", async () => {
const render = createCustomRenderer({
context: {
app: {
isGlobalAdmin: true,
isTeamAdmin: false,
// thanks, DeepPartial!
config: {
gitops: {
gitops_mode_enabled: true,
repository_url: "a.b.cc",
},
},
},
},
});
const onSave = jest.fn();
const { user } = render(
<GitOpsModeTooltipWrapper
renderChildren={(disableChildren) => (
<Button disabled={disableChildren} onClick={onSave} variant="brand">
Save
</Button>
)}
/>
);
const btn = screen.getByText("Save");
expect(btn).toBeInTheDocument();
await user.hover(btn);
expect(screen.getByRole("tooltip")).toBeInTheDocument();
await user.click(btn);
expect(onSave).not.toHaveBeenCalled();
});
});
@@ -21,10 +21,10 @@ const GitOpsModeTooltipWrapper = ({
fixedPositionStrategy,
}: IGitOpsModeTooltipWrapper) => {
const { config } = useContext(AppContext);
const gomEnabled = config?.gitops.gitops_mode_enabled;
const gitOpsModeEnabled = config?.gitops.gitops_mode_enabled;
const repoURL = config?.gitops.repository_url;
if (!gomEnabled) {
if (!gitOpsModeEnabled) {
return <>{renderChildren()}</>;
}