mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix topbar to inject isLinux and isWindows to fix tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4efb6b5b00
commit
0b400d2b34
13
src/common/vars/is-linux.injectable.ts
Normal file
13
src/common/vars/is-linux.injectable.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { isLinux } from "../vars";
|
||||
|
||||
const isLinuxInjectable = getInjectable({
|
||||
instantiate: () => isLinux,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default isLinuxInjectable;
|
||||
13
src/common/vars/is-windows.injectable.ts
Normal file
13
src/common/vars/is-windows.injectable.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { isWindows } from "../vars";
|
||||
|
||||
const isWindowsInjectable = getInjectable({
|
||||
instantiate: () => isWindows,
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
});
|
||||
|
||||
export default isWindowsInjectable;
|
||||
@ -14,13 +14,14 @@ import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||
import { computed } from "mobx";
|
||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import mockFs from "mock-fs";
|
||||
import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
|
||||
import isWindowsInjectable from "../../../../common/vars/is-windows.injectable";
|
||||
|
||||
jest.mock("../../../../common/vars", () => {
|
||||
const { SemVer } = require("semver");
|
||||
|
||||
return {
|
||||
...jest.requireActual<{}>("../../../../common/vars"),
|
||||
isMac: true,
|
||||
appSemVer: new SemVer("1.0.0"),
|
||||
};
|
||||
});
|
||||
@ -93,30 +94,30 @@ describe("<TopBar/>", () => {
|
||||
});
|
||||
|
||||
it("renders home button", async () => {
|
||||
const { getByTestId } = render(<TopBar/>);
|
||||
const { findByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(await getByTestId("home-button")).toBeInTheDocument();
|
||||
expect(await findByTestId("home-button")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders history arrows", async () => {
|
||||
const { getByTestId } = render(<TopBar/>);
|
||||
const { findByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(await getByTestId("history-back")).toBeInTheDocument();
|
||||
expect(await getByTestId("history-forward")).toBeInTheDocument();
|
||||
expect(await findByTestId("history-back")).toBeInTheDocument();
|
||||
expect(await findByTestId("history-forward")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("enables arrow by ipc event", async () => {
|
||||
const { getByTestId } = render(<TopBar/>);
|
||||
const { findByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(await getByTestId("history-back")).not.toHaveClass("disabled");
|
||||
expect(await getByTestId("history-forward")).not.toHaveClass("disabled");
|
||||
expect(await findByTestId("history-back")).not.toHaveClass("disabled");
|
||||
expect(await findByTestId("history-forward")).not.toHaveClass("disabled");
|
||||
});
|
||||
|
||||
it("triggers browser history back and forward", async () => {
|
||||
const { getByTestId } = render(<TopBar/>);
|
||||
const { findByTestId } = render(<TopBar/>);
|
||||
|
||||
const prevButton = await getByTestId("history-back");
|
||||
const nextButton = await getByTestId("history-forward");
|
||||
const prevButton = await findByTestId("history-back");
|
||||
const nextButton = await findByTestId("history-forward");
|
||||
|
||||
fireEvent.click(prevButton);
|
||||
|
||||
@ -139,12 +140,15 @@ describe("<TopBar/>", () => {
|
||||
},
|
||||
]));
|
||||
|
||||
const { getByTestId } = render(<TopBar/>);
|
||||
const { findByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(await getByTestId(testId)).toHaveTextContent(text);
|
||||
expect(await findByTestId(testId)).toHaveTextContent(text);
|
||||
});
|
||||
|
||||
it("doesn't show windows title buttons", () => {
|
||||
it("doesn't show windows title buttons on macos", () => {
|
||||
di.override(isLinuxInjectable, () => false);
|
||||
di.override(isWindowsInjectable, () => false);
|
||||
|
||||
const { queryByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(queryByTestId("window-menu")).not.toBeInTheDocument();
|
||||
@ -152,4 +156,16 @@ describe("<TopBar/>", () => {
|
||||
expect(queryByTestId("window-maximize")).not.toBeInTheDocument();
|
||||
expect(queryByTestId("window-close")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does show windows title buttons on linux", () => {
|
||||
di.override(isLinuxInjectable, () => true);
|
||||
di.override(isWindowsInjectable, () => false);
|
||||
|
||||
const { queryByTestId } = render(<TopBar/>);
|
||||
|
||||
expect(queryByTestId("window-menu")).toBeInTheDocument();
|
||||
expect(queryByTestId("window-minimize")).toBeInTheDocument();
|
||||
expect(queryByTestId("window-maximize")).toBeInTheDocument();
|
||||
expect(queryByTestId("window-close")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@ -15,16 +15,19 @@ import { watchHistoryState } from "../../../remote-helpers/history-updater";
|
||||
import { isActiveRoute, navigate } from "../../../navigation";
|
||||
import { catalogRoute, catalogURL } from "../../../../common/routes";
|
||||
import { IpcMainWindowEvents } from "../../../../main/window-manager";
|
||||
import { isLinux, isWindows } from "../../../../common/vars";
|
||||
import { cssNames } from "../../../utils";
|
||||
import topBarItemsInjectable from "./top-bar-items/top-bar-items.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { TopBarRegistration } from "./top-bar-registration";
|
||||
import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
|
||||
import isWindowsInjectable from "../../../../common/vars/is-windows.injectable";
|
||||
|
||||
interface Props extends React.HTMLAttributes<any> {}
|
||||
export interface TopBarProps extends React.HTMLAttributes<any> {}
|
||||
|
||||
interface Dependencies {
|
||||
items: IComputedValue<TopBarRegistration[]>;
|
||||
isWindows: boolean;
|
||||
isLinux: boolean;
|
||||
}
|
||||
|
||||
const prevEnabled = observable.box(false);
|
||||
@ -38,7 +41,7 @@ ipcRendererOn("history:can-go-forward", (event, state: boolean) => {
|
||||
nextEnabled.set(state);
|
||||
});
|
||||
|
||||
const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies) => {
|
||||
const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...rest }: TopBarProps & Dependencies) => {
|
||||
const elem = useRef<HTMLDivElement>();
|
||||
const window = useMemo(() => getCurrentWindow(), []);
|
||||
|
||||
@ -159,10 +162,11 @@ const renderRegisteredItems = (items: TopBarRegistration[]) => (
|
||||
|
||||
|
||||
|
||||
export const TopBar = withInjectables(observer(NonInjectedTopBar), {
|
||||
export const TopBar = withInjectables<Dependencies, TopBarProps>(NonInjectedTopBar, {
|
||||
getProps: (di, props) => ({
|
||||
items: di.inject(topBarItemsInjectable),
|
||||
|
||||
isLinux: di.inject(isLinuxInjectable),
|
||||
isWindows: di.inject(isWindowsInjectable),
|
||||
...props,
|
||||
}),
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user