1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/utility-features/utilities/src/observable-crate.test.ts
Sebastian Malton 2789bcebcb
Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)
* Convert runMany and runManySync to use injectManyWithMeta

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors due to new Runnable requirements

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add documentation for verifyRunnablesAreDAG

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify convertToWithIdWith

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move all utility functions to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move testing utilities to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move run-many and run-many-sync to separate package

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace all internal uses of utilities with new packages

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Use new @k8slens/run-many package in core

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add dep to open-lens

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of @k8slens/test-utils

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup getGlobalOverride

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move tests to new package too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup uses of AsyncResult and autoBind

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fixup remaining import issues

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Finial fixups to fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Revert moving "testUsingFakeTime" to separate package

- This fixes tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix integration tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix unit test failing due to spelling fix

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-03-10 10:07:28 +02:00

117 lines
2.9 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ObservableCrate } from "./observable-crate";
import { observableCrate } from "./observable-crate";
describe("observable-crate", () => {
it("can be constructed with initial value", () => {
expect(() => observableCrate(0)).not.toThrow();
});
it("has a definite type if the initial value is provided", () => {
expect (() => {
const res: ObservableCrate<number> = observableCrate(0);
void res;
}).not.toThrow();
});
it("accepts an array of transitionHandlers", () => {
expect(() => observableCrate(0, [])).not.toThrow();
});
describe("with a crate over an enum, and some transition handlers", () => {
enum Test {
Start,
T1,
End,
}
let crate: ObservableCrate<Test>;
let correctHandler: jest.MockedFunction<() => void>;
let incorrectHandler: jest.MockedFunction<() => void>;
beforeEach(() => {
correctHandler = jest.fn();
incorrectHandler = jest.fn();
crate = observableCrate(Test.Start, [
{
from: Test.Start,
to: Test.Start,
onTransition: incorrectHandler,
},
{
from: Test.Start,
to: Test.T1,
onTransition: correctHandler,
},
{
from: Test.Start,
to: Test.End,
onTransition: incorrectHandler,
},
{
from: Test.T1,
to: Test.Start,
onTransition: incorrectHandler,
},
{
from: Test.T1,
to: Test.T1,
onTransition: incorrectHandler,
},
{
from: Test.T1,
to: Test.End,
onTransition: incorrectHandler,
},
{
from: Test.End,
to: Test.Start,
onTransition: incorrectHandler,
},
{
from: Test.End,
to: Test.T1,
onTransition: incorrectHandler,
},
{
from: Test.End,
to: Test.End,
onTransition: incorrectHandler,
},
]);
});
it("initial value is available", () => {
expect(crate.get()).toBe(Test.Start);
});
it("does not call any transition handler", () => {
expect(correctHandler).not.toBeCalled();
expect(incorrectHandler).not.toBeCalled();
});
describe("when setting a new value", () => {
beforeEach(() => {
crate.set(Test.T1);
});
it("calls the associated transition handler", () => {
expect(correctHandler).toBeCalled();
});
it("does not call any other transition handler", () => {
expect(incorrectHandler).not.toBeCalled();
});
it("new value is available", () => {
expect(crate.get()).toBe(Test.T1);
});
});
});
});