mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix ClusterScoped kube APIs not subscribing (#2706)
* Fix ClusterScoped kube APIs not subscribing Signed-off-by: Sebastian Malton <sebastian@malton.name> * remove debug Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
768e1d14ca
commit
7b1b8e6321
4 files changed
+87
-25
No files matched your search
@@ -1,31 +1,61 @@
|
||||
import { splitArray } from "../splitArray";
|
||||
import { bifurcateArray, splitArray } from "../splitArray";
|
||||
|
||||
describe("split array on element tests", () => {
|
||||
test("empty array", () => {
|
||||
it("empty array", () => {
|
||||
expect(splitArray([], 10)).toStrictEqual([[], [], false]);
|
||||
});
|
||||
|
||||
test("one element, not in array", () => {
|
||||
it("one element, not in array", () => {
|
||||
expect(splitArray([1], 10)).toStrictEqual([[1], [], false]);
|
||||
});
|
||||
|
||||
test("ten elements, not in array", () => {
|
||||
it("ten elements, not in array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], false]);
|
||||
});
|
||||
|
||||
test("one elements, in array", () => {
|
||||
it("one elements, in array", () => {
|
||||
expect(splitArray([1], 1)).toStrictEqual([[], [], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in front array", () => {
|
||||
it("ten elements, in front array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0)).toStrictEqual([[], [1, 2, 3, 4, 5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in middle array", () => {
|
||||
it("ten elements, in middle array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)).toStrictEqual([[0, 1, 2, 3], [5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
test("ten elements, in end array", () => {
|
||||
it("ten elements, in end array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 9)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8], [], true]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bifurcateArray", () => {
|
||||
it("should return tuple of empty arrays from empty array", () => {
|
||||
const [left, right] = bifurcateArray([], () => true);
|
||||
|
||||
expect(left).toStrictEqual([]);
|
||||
expect(right).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should return all true condition returning items in the right array", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], () => true);
|
||||
|
||||
expect(left).toStrictEqual([]);
|
||||
expect(right).toStrictEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it("should return all false condition returning items in the right array", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], () => false);
|
||||
|
||||
expect(left).toStrictEqual([1, 2, 3]);
|
||||
expect(right).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should split array as specified", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], (i) => Boolean(i % 2));
|
||||
|
||||
expect(left).toStrictEqual([2]);
|
||||
expect(right).toStrictEqual([1, 3]);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
// Moved from dashboard/client/utils/arrays.ts
|
||||
/**
|
||||
* This function splits an array into two sub arrays on the first instance of
|
||||
* element (from the left). If the array does not contain the element. The
|
||||
@@ -19,3 +18,20 @@ export function splitArray<T>(array: T[], element: T): [T[], T[], boolean] {
|
||||
|
||||
return [array.slice(0, index), array.slice(index + 1, array.length), true];
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an array into two parts based on the outcome of `condition`. If `true`
|
||||
* the value will be returned as part of the right array. If `false` then part of
|
||||
* the left array.
|
||||
* @param src the full array to bifurcate
|
||||
* @param condition the function to determine which set each is in
|
||||
*/
|
||||
export function bifurcateArray<T>(src: T[], condition: (item: T) => boolean): [falses: T[], trues: T[]] {
|
||||
const res: [T[], T[]] = [[], []];
|
||||
|
||||
for (const item of src) {
|
||||
res[+condition(item)].push(item);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in new issue
Block a user