Files
SCM-Manager/scm-ui/ui-extensions/src/binder.test.ts

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-10-19 17:15:53 +02:00
import { Binder } from "./binder";
2019-10-19 17:15:53 +02:00
describe("binder tests", () => {
let binder: Binder;
beforeEach(() => {
binder = new Binder();
});
2019-10-19 17:15:53 +02:00
it("should return an empty array for non existing extension points", () => {
const extensions = binder.getExtensions("hitchhiker");
expect(extensions).toEqual([]);
});
2019-10-19 17:15:53 +02:00
it("should return the binded extensions", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
binder.bind("hitchhicker.trillian", "earth");
2019-10-19 17:15:53 +02:00
const extensions = binder.getExtensions("hitchhicker.trillian");
expect(extensions).toEqual(["heartOfGold", "earth"]);
});
2019-10-19 17:15:53 +02:00
it("should return the first bound extension", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
binder.bind("hitchhicker.trillian", "earth");
2019-10-19 17:15:53 +02:00
expect(binder.getExtension("hitchhicker.trillian")).toBe("heartOfGold");
});
2019-10-19 17:15:53 +02:00
it("should return null if no extension was bound", () => {
expect(binder.getExtension("hitchhicker.trillian")).toBe(null);
});
2019-10-19 17:15:53 +02:00
it("should return true, if an extension is bound", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
expect(binder.hasExtension("hitchhicker.trillian")).toBe(true);
});
2019-10-19 17:15:53 +02:00
it("should return false, if no extension is bound", () => {
expect(binder.hasExtension("hitchhicker.trillian")).toBe(false);
});
2019-10-19 17:15:53 +02:00
type Props = {
category: string
};
it("should return only extensions which predicates matches", () => {
binder.bind(
2019-10-19 17:15:53 +02:00
"hitchhicker.trillian",
"heartOfGold",
(props: Props) => props.category === "a"
);
binder.bind(
2019-10-19 17:15:53 +02:00
"hitchhicker.trillian",
"earth",
(props: Props) => props.category === "b"
);
binder.bind(
2019-10-19 17:15:53 +02:00
"hitchhicker.trillian",
"earth2",
(props: Props) => props.category === "a"
);
2019-10-19 17:15:53 +02:00
const extensions = binder.getExtensions("hitchhicker.trillian", {
category: "b"
});
2019-10-19 17:15:53 +02:00
expect(extensions).toEqual(["earth"]);
});
});