mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make tests more robust
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
bd082e24ee
commit
56f2cb9663
@ -55,6 +55,9 @@ function getRegisteredStatusBarItems({ registrations }: Dependencies): IComputed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is done so that the first ones registered are closest to the corner
|
||||||
|
res.right.reverse();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,24 +9,47 @@ import { StatusBar } from "./status-bar";
|
|||||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||||
import type { DiRender } from "../test-utils/renderFor";
|
import type { DiRender } from "../test-utils/renderFor";
|
||||||
import { renderFor } from "../test-utils/renderFor";
|
import { renderFor } from "../test-utils/renderFor";
|
||||||
import { computed } from "mobx";
|
import { computed, IObservableArray, observable } from "mobx";
|
||||||
import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||||
import statusBarItemsInjectable from "./status-bar-items.injectable";
|
import statusBarItemsInjectable from "./status-bar-items.injectable";
|
||||||
import type { StatusBarRegistration } from "./status-bar-registration";
|
import type { StatusBarRegistration } from "./status-bar-registration";
|
||||||
|
import { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||||
|
import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||||
|
|
||||||
|
class SomeTestExtension extends LensRendererExtension {
|
||||||
|
constructor(statusBarItems: IObservableArray<any>) {
|
||||||
|
super({
|
||||||
|
id: "some-id",
|
||||||
|
absolutePath: "irrelevant",
|
||||||
|
isBundled: false,
|
||||||
|
isCompatible: false,
|
||||||
|
isEnabled: false,
|
||||||
|
manifest: { name: "some-id", version: "some-version" },
|
||||||
|
manifestPath: "irrelevant",
|
||||||
|
});
|
||||||
|
|
||||||
|
this.statusBarItems = statusBarItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe("<StatusBar />", () => {
|
describe("<StatusBar />", () => {
|
||||||
let render: DiRender;
|
let render: DiRender;
|
||||||
let di: ConfigurableDependencyInjectionContainer;
|
let di: ConfigurableDependencyInjectionContainer;
|
||||||
|
let statusBarItems: IObservableArray<any>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
statusBarItems = observable.array([]);
|
||||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||||
render = renderFor(di);
|
render = renderFor(di);
|
||||||
|
|
||||||
|
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||||
|
di.override(rendererExtensionsInjectable, () => computed(() => [new SomeTestExtension(statusBarItems)]));
|
||||||
|
|
||||||
await di.runSetups();
|
await di.runSetups();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders w/o errors", () => {
|
it("renders w/o errors", () => {
|
||||||
di.override(statusBarItemsInjectable, () => computed(() => [] as StatusBarRegistration[]));
|
|
||||||
const { container } = render(<StatusBar />);
|
const { container } = render(<StatusBar />);
|
||||||
|
|
||||||
expect(container).toBeInstanceOf(HTMLElement);
|
expect(container).toBeInstanceOf(HTMLElement);
|
||||||
@ -41,7 +64,7 @@ describe("<StatusBar />", () => {
|
|||||||
[{}],
|
[{}],
|
||||||
{},
|
{},
|
||||||
])("renders w/o errors when registrations are not type compliant (%p)", val => {
|
])("renders w/o errors when registrations are not type compliant (%p)", val => {
|
||||||
di.override(statusBarItemsInjectable, () => computed(() => [val] as StatusBarRegistration[]));
|
statusBarItems.replace([val]);
|
||||||
|
|
||||||
expect(() => render(<StatusBar />)).not.toThrow();
|
expect(() => render(<StatusBar />)).not.toThrow();
|
||||||
});
|
});
|
||||||
@ -63,9 +86,9 @@ describe("<StatusBar />", () => {
|
|||||||
const testId = "testId";
|
const testId = "testId";
|
||||||
const text = "heee";
|
const text = "heee";
|
||||||
|
|
||||||
di.override(statusBarItemsInjectable, () => computed(() => [
|
statusBarItems.replace([{
|
||||||
{ item: () => <span data-testid={testId} >{text}</span> },
|
item: () => <span data-testid={testId} >{text}</span>,
|
||||||
] as StatusBarRegistration[]));
|
}]);
|
||||||
|
|
||||||
const { getByTestId } = render(<StatusBar />);
|
const { getByTestId } = render(<StatusBar />);
|
||||||
|
|
||||||
@ -74,36 +97,36 @@ describe("<StatusBar />", () => {
|
|||||||
|
|
||||||
|
|
||||||
it("sort positioned items properly", () => {
|
it("sort positioned items properly", () => {
|
||||||
di.override(statusBarItemsInjectable, () => computed(() => [
|
statusBarItems.replace([
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: () => <div data-testid="sortedElem">right</div>,
|
Item: () => <div data-testid="sortedElem">right1</div>,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: () => <div data-testid="sortedElem">right</div>,
|
Item: () => <div data-testid="sortedElem">right2</div>,
|
||||||
position: "right",
|
position: "right",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: () => <div data-testid="sortedElem">left</div>,
|
Item: () => <div data-testid="sortedElem">left1</div>,
|
||||||
position: "left",
|
position: "left",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
components: {
|
components: {
|
||||||
Item: () => <div data-testid="sortedElem">left</div>,
|
Item: () => <div data-testid="sortedElem">left2</div>,
|
||||||
position: "left",
|
position: "left",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] as StatusBarRegistration[]));
|
]);
|
||||||
|
|
||||||
const { getAllByTestId } = render(<StatusBar />);
|
const { getAllByTestId } = render(<StatusBar />);
|
||||||
const elems = getAllByTestId("sortedElem");
|
const elems = getAllByTestId("sortedElem");
|
||||||
const positions = elems.map(elem => elem.textContent);
|
const positions = elems.map(elem => elem.textContent);
|
||||||
|
|
||||||
expect(positions).toEqual(["left", "left", "right", "right"]);
|
expect(positions).toEqual(["left1", "left2", "right2", "right1"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user