mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-06 19:08:11 +08:00
* Added typings to annoMatrix directory. (#2365) * Added review point updates. (#2365) * Fixed viewOf defect. Added review point updates. (#2365) * Updated test to use Field key interpolation. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Updated test to use Field key interpolation. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Updated test to use Field key interpolation. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Updated test to use Field key interpolation. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Linting. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Simplified while condition in middleware GC. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com> * Reverted embedding.ts prettier to resolve conflict. (#2365) Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
This commit is contained in:
co-authored by
Timmy Huang
parent
08b03ace60
commit
b814489328
@@ -10,6 +10,7 @@ import {
|
||||
isubsetMask,
|
||||
} from "../../../src/annoMatrix";
|
||||
import { Dataframe } from "../../../src/util/dataframe";
|
||||
import { Field } from "../../../src/common/types/schema";
|
||||
|
||||
enableFetchMocks();
|
||||
|
||||
@@ -34,7 +35,7 @@ describe("AnnoMatrix", () => {
|
||||
expect(annoMatrix.nObs).toEqual(serverMocks.schema.schema.dataframe.nObs);
|
||||
expect(annoMatrix.nVar).toEqual(serverMocks.schema.schema.dataframe.nVar);
|
||||
expect(annoMatrix.isView).toBeFalsy();
|
||||
expect(annoMatrix.viewOf).toBeUndefined();
|
||||
expect(annoMatrix.viewOf).toBe(annoMatrix);
|
||||
expect(annoMatrix.rowIndex).toBeDefined();
|
||||
});
|
||||
|
||||
@@ -42,7 +43,7 @@ describe("AnnoMatrix", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).once(serverMocks.annotationsObs(["name_0"]));
|
||||
|
||||
const df = await annoMatrix.fetch("obs", "name_0");
|
||||
const df = await annoMatrix.fetch(Field.obs, "name_0");
|
||||
expect(df).toBeInstanceOf(Dataframe);
|
||||
expect(df.colIndex.labels()).toEqual(["name_0"]);
|
||||
expect(df.dims).toEqual([annoMatrix.nObs, 1]);
|
||||
@@ -55,7 +56,7 @@ describe("AnnoMatrix", () => {
|
||||
.once(serverMocks.annotationsObs(["n_genes"]));
|
||||
|
||||
await expect(
|
||||
annoMatrix.fetch("obs", ["name_0", "n_genes"])
|
||||
annoMatrix.fetch(Field.obs, ["name_0", "n_genes"])
|
||||
).resolves.toBeInstanceOf(Dataframe);
|
||||
});
|
||||
|
||||
@@ -72,7 +73,7 @@ describe("AnnoMatrix", () => {
|
||||
).resolves.toBeInstanceOf(Dataframe);
|
||||
};
|
||||
|
||||
test("obs", async () => getLastTwo("obs"));
|
||||
test(Field.obs, async () => getLastTwo(Field.obs));
|
||||
test("var", async () => getLastTwo("var"));
|
||||
test("emb", async () => getLastTwo("emb"));
|
||||
});
|
||||
@@ -81,15 +82,15 @@ describe("AnnoMatrix", () => {
|
||||
// single string is a column name
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).once(serverMocks.annotationsObs(["n_genes"]));
|
||||
await expect(annoMatrix.fetch("obs", "n_genes")).resolves.toBeInstanceOf(
|
||||
Dataframe
|
||||
);
|
||||
await expect(
|
||||
annoMatrix.fetch(Field.obs, "n_genes")
|
||||
).resolves.toBeInstanceOf(Dataframe);
|
||||
|
||||
// array of column names, expecting n_genes to be cached.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).once(serverMocks.annotationsObs(["percent_mito"]));
|
||||
await expect(
|
||||
annoMatrix.fetch("obs", ["n_genes", "percent_mito"])
|
||||
annoMatrix.fetch(Field.obs, ["n_genes", "percent_mito"])
|
||||
).resolves.toBeInstanceOf(Dataframe);
|
||||
|
||||
// more complex value filter query, enumerated
|
||||
@@ -151,9 +152,9 @@ describe("AnnoMatrix", () => {
|
||||
|
||||
test("schema accessors", () => {
|
||||
expect(annoMatrix.getMatrixFields()).toEqual(
|
||||
expect.arrayContaining(["X", "obs", "emb", "var"])
|
||||
expect.arrayContaining(["X", Field.obs, "emb", "var"])
|
||||
);
|
||||
expect(annoMatrix.getMatrixColumns("obs")).toEqual(
|
||||
expect(annoMatrix.getMatrixColumns(Field.obs)).toEqual(
|
||||
expect.arrayContaining(["name_0", "n_genes", "louvain"])
|
||||
);
|
||||
expect(annoMatrix.getColumnSchema("emb", "umap")).toEqual({
|
||||
@@ -171,7 +172,7 @@ describe("AnnoMatrix", () => {
|
||||
test the mask & label access to subset via isubset and isubsetMask
|
||||
*/
|
||||
test("isubset", async () => {
|
||||
const rowList = [0, 10];
|
||||
const rowList = new Int32Array([0, 10]);
|
||||
const rowMask = new Uint8Array(annoMatrix.nObs);
|
||||
for (let i = 0; i < rowList.length; i += 1) {
|
||||
rowMask[rowList[i]] = 1;
|
||||
@@ -188,8 +189,8 @@ describe("AnnoMatrix", () => {
|
||||
(fetch as any)
|
||||
.once(serverMocks.annotationsObs(["n_genes"]))
|
||||
.once(serverMocks.annotationsObs(["n_genes"]));
|
||||
const ng1 = (await am1.fetch("obs", "n_genes")) as Dataframe;
|
||||
const ng2 = (await am2.fetch("obs", "n_genes")) as Dataframe;
|
||||
const ng1 = (await am1.fetch(Field.obs, "n_genes")) as Dataframe;
|
||||
const ng2 = (await am2.fetch(Field.obs, "n_genes")) as Dataframe;
|
||||
expect(ng1).toBeDefined();
|
||||
expect(ng2).toBeDefined();
|
||||
expect(ng1).toHaveLength(ng2.length);
|
||||
@@ -203,10 +204,10 @@ describe("AnnoMatrix", () => {
|
||||
describe("add/drop column", () => {
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'base' implicitly has an 'any' type.
|
||||
async function addDrop(base) {
|
||||
expect(base.getMatrixColumns("obs")).not.toContain("foo");
|
||||
expect(base.getMatrixColumns(Field.obs)).not.toContain("foo");
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(base.fetch("obs", "foo")).rejects.toThrow(
|
||||
await expect(base.fetch(Field.obs, "foo")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
|
||||
@@ -216,9 +217,9 @@ describe("AnnoMatrix", () => {
|
||||
Float32Array,
|
||||
0
|
||||
);
|
||||
expect(base.getMatrixColumns("obs")).not.toContain("foo");
|
||||
expect(am1.getMatrixColumns("obs")).toContain("foo");
|
||||
const foo: Dataframe = await am1.fetch("obs", "foo");
|
||||
expect(base.getMatrixColumns(Field.obs)).not.toContain("foo");
|
||||
expect(am1.getMatrixColumns(Field.obs)).toContain("foo");
|
||||
const foo: Dataframe = await am1.fetch(Field.obs, "foo");
|
||||
expect(foo).toBeDefined();
|
||||
expect(foo).toBeInstanceOf(Dataframe);
|
||||
expect(foo).toHaveLength(am1.nObs);
|
||||
@@ -228,11 +229,11 @@ describe("AnnoMatrix", () => {
|
||||
|
||||
/* drop */
|
||||
const am2 = am1.dropObsColumn("foo");
|
||||
expect(base.getMatrixColumns("obs")).not.toContain("foo");
|
||||
expect(am2.getMatrixColumns("obs")).not.toContain("foo");
|
||||
expect(base.getMatrixColumns(Field.obs)).not.toContain("foo");
|
||||
expect(am2.getMatrixColumns(Field.obs)).not.toContain("foo");
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(am2.fetch("obs", "foo")).rejects.toThrow(
|
||||
await expect(am2.fetch(Field.obs, "foo")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
}
|
||||
@@ -245,10 +246,10 @@ describe("AnnoMatrix", () => {
|
||||
const am1 = clip(annoMatrix, 0.1, 0.9);
|
||||
await addDrop(am1);
|
||||
|
||||
const am2 = isubset(am1, [0, 1, 2, 20, 30, 400]);
|
||||
const am2 = isubset(am1, new Int32Array([0, 1, 2, 20, 30, 400]));
|
||||
await addDrop(am2);
|
||||
|
||||
const am3 = isubset(annoMatrix, [10, 0, 7, 3]);
|
||||
const am3 = isubset(annoMatrix, new Int32Array([10, 0, 7, 3]));
|
||||
await addDrop(am3);
|
||||
|
||||
const am4 = clip(am3, 0, 1);
|
||||
@@ -257,10 +258,10 @@ describe("AnnoMatrix", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockResponse(serverMocks.responder);
|
||||
|
||||
await am1.fetch("obs", am1.getMatrixColumns("obs"));
|
||||
await am2.fetch("obs", am2.getMatrixColumns("obs"));
|
||||
await am3.fetch("obs", am3.getMatrixColumns("obs"));
|
||||
await am4.fetch("obs", am4.getMatrixColumns("obs"));
|
||||
await am1.fetch(Field.obs, am1.getMatrixColumns(Field.obs));
|
||||
await am2.fetch(Field.obs, am2.getMatrixColumns(Field.obs));
|
||||
await am3.fetch(Field.obs, am3.getMatrixColumns(Field.obs));
|
||||
await am4.fetch(Field.obs, am4.getMatrixColumns(Field.obs));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).resetMocks();
|
||||
@@ -287,7 +288,7 @@ describe("AnnoMatrix", () => {
|
||||
"unassigned"
|
||||
);
|
||||
|
||||
const testVal = await am.fetch("obs", "test");
|
||||
const testVal = await am.fetch(Field.obs, "test");
|
||||
expect(testVal.col("test").asArray()).toEqual(
|
||||
new Array(am.nObs).fill("unassigned")
|
||||
);
|
||||
@@ -295,7 +296,7 @@ describe("AnnoMatrix", () => {
|
||||
/* set values in column */
|
||||
const whichRows = [1, 2, 10];
|
||||
const am1 = await am.setObsColumnValues("test", whichRows, "yo");
|
||||
const testVal1 = await am1.fetch("obs", "test");
|
||||
const testVal1 = await am1.fetch(Field.obs, "test");
|
||||
const expt = new Array(am1.nObs).fill("unassigned");
|
||||
for (let i = 0; i < whichRows.length; i += 1) {
|
||||
const offset = am1.rowIndex.getOffset(whichRows[i]);
|
||||
@@ -303,8 +304,8 @@ describe("AnnoMatrix", () => {
|
||||
}
|
||||
expect(testVal1).not.toBe(testVal);
|
||||
expect(testVal1.col("test").asArray()).toEqual(expt);
|
||||
expect(am1.getColumnSchema("obs", "test").type).toBe("categorical");
|
||||
expect(am1.getColumnSchema("obs", "test").categories).toEqual(
|
||||
expect(am1.getColumnSchema(Field.obs, "test").type).toBe("categorical");
|
||||
expect(am1.getColumnSchema(Field.obs, "test").categories).toEqual(
|
||||
expect.arrayContaining(["unassigned", "red", "green", "yo"])
|
||||
);
|
||||
|
||||
@@ -312,7 +313,7 @@ describe("AnnoMatrix", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
am = am1.dropObsColumn("test");
|
||||
await expect(am.fetch("obs", "test")).rejects.toThrow(
|
||||
await expect(am.fetch(Field.obs, "test")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
}
|
||||
@@ -325,18 +326,18 @@ describe("AnnoMatrix", () => {
|
||||
const am1 = clip(annoMatrix, 0.1, 0.9);
|
||||
await addSetDrop(am1);
|
||||
|
||||
const am2 = isubset(am1, [0, 1, 2, 10, 20, 30, 400]);
|
||||
const am2 = isubset(am1, new Int32Array([0, 1, 2, 10, 20, 30, 400]));
|
||||
await addSetDrop(am2);
|
||||
|
||||
const am3 = isubset(annoMatrix, [10, 1, 0, 30, 2]);
|
||||
const am3 = isubset(annoMatrix, new Int32Array([10, 1, 0, 30, 2]));
|
||||
await addSetDrop(am3);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockResponse(serverMocks.responder);
|
||||
|
||||
await am1.fetch("obs", am1.getMatrixColumns("obs"));
|
||||
await am2.fetch("obs", am2.getMatrixColumns("obs"));
|
||||
await am3.fetch("obs", am3.getMatrixColumns("obs"));
|
||||
await am1.fetch(Field.obs, am1.getMatrixColumns(Field.obs));
|
||||
await am2.fetch(Field.obs, am2.getMatrixColumns(Field.obs));
|
||||
await am3.fetch(Field.obs, am3.getMatrixColumns(Field.obs));
|
||||
|
||||
await addSetDrop(am1);
|
||||
await addSetDrop(am2);
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from "../../../src/annoMatrix";
|
||||
import { Dataframe } from "../../../src/util/dataframe";
|
||||
import { rangeFill } from "../../../src/util/range";
|
||||
import { Field, Schema } from "../../../src/common/types/schema";
|
||||
|
||||
enableFetchMocks();
|
||||
|
||||
@@ -29,7 +30,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// reset all fetch mocking state
|
||||
annoMatrix = new AnnoMatrixLoader(
|
||||
serverMocks.baseDataURL,
|
||||
serverMocks.schema.schema
|
||||
serverMocks.schema.schema as Schema
|
||||
);
|
||||
crossfilter = new AnnoMatrixObsCrossfilter(annoMatrix);
|
||||
});
|
||||
@@ -76,7 +77,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(fetch as any).once(
|
||||
serverMocks.dataframeResponse(["louvain"], [obsLouvain])
|
||||
);
|
||||
let newCrossfilter = await crossfilter.select("obs", "louvain", {
|
||||
let newCrossfilter = await crossfilter.select(Field.obs, "louvain", {
|
||||
mode: "none",
|
||||
});
|
||||
|
||||
@@ -87,7 +88,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
expect((fetch as any).mock.calls).toHaveLength(1);
|
||||
|
||||
newCrossfilter = await crossfilter.select("obs", "louvain", {
|
||||
newCrossfilter = await crossfilter.select(Field.obs, "louvain", {
|
||||
mode: "all",
|
||||
});
|
||||
expect(newCrossfilter.countSelected()).toEqual(annoMatrix.nObs);
|
||||
@@ -100,7 +101,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(fetch as any).once(
|
||||
serverMocks.dataframeResponse(["louvain"], [obsLouvain])
|
||||
);
|
||||
xfltr = await crossfilter.select("obs", "louvain", {
|
||||
xfltr = await crossfilter.select(Field.obs, "louvain", {
|
||||
mode: "exact",
|
||||
values: ["NK cells", "B cells"],
|
||||
});
|
||||
@@ -133,7 +134,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
)
|
||||
);
|
||||
|
||||
const df: Dataframe = await annoMatrix.fetch("obs", "louvain");
|
||||
const df: Dataframe = await annoMatrix.fetch(Field.obs, "louvain");
|
||||
const values = df.col("louvain").asArray();
|
||||
const selected = xfltr.allSelectedMask();
|
||||
values.every(
|
||||
@@ -146,7 +147,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(fetch as any).once(
|
||||
serverMocks.dataframeResponse(["n_genes"], [new Int32Array(obsNGenes)])
|
||||
);
|
||||
xfltr = await xfltr.select("obs", "n_genes", {
|
||||
xfltr = await xfltr.select(Field.obs, "n_genes", {
|
||||
mode: "range",
|
||||
lo: 0,
|
||||
hi: 500,
|
||||
@@ -258,7 +259,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(fetch as any).once(
|
||||
serverMocks.dataframeResponse(["louvain"], [obsLouvain])
|
||||
);
|
||||
xfltr = await xfltr.select("obs", "louvain", {
|
||||
xfltr = await xfltr.select(Field.obs, "louvain", {
|
||||
mode: "exact",
|
||||
values: ["NK cells", "B cells"],
|
||||
});
|
||||
@@ -267,7 +268,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
expect(xfltr.countSelected()).toEqual(240);
|
||||
|
||||
const df: Dataframe = (await annoMatrixSubset.fetch(
|
||||
"obs",
|
||||
Field.obs,
|
||||
"louvain"
|
||||
)) as Dataframe;
|
||||
expect(df).toBeDefined();
|
||||
@@ -291,7 +292,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(crossfilter.select("obs", "foo")).rejects.toThrow(
|
||||
await expect(crossfilter.select(Field.obs, "foo")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
});
|
||||
@@ -304,7 +305,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
async function helperAddTestCol(cf: any, colName: any, colSchema = null) {
|
||||
expect(
|
||||
cf.annoMatrix.getMatrixColumns("obs").includes(colName)
|
||||
cf.annoMatrix.getMatrixColumns(Field.obs).includes(colName)
|
||||
).toBeFalsy();
|
||||
|
||||
if (colSchema === null) {
|
||||
@@ -326,7 +327,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(v: any) => v.name === colName
|
||||
)
|
||||
).toHaveLength(1);
|
||||
const df = await xfltr.annoMatrix.fetch("obs", colName);
|
||||
const df = await xfltr.annoMatrix.fetch(Field.obs, colName);
|
||||
expect(df.hasCol(colName)).toBeTruthy();
|
||||
return xfltr;
|
||||
}
|
||||
@@ -334,7 +335,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
test("addObsColumn", async () => {
|
||||
expect(crossfilter.countSelected()).toBe(annoMatrix.nObs);
|
||||
expect(
|
||||
crossfilter.annoMatrix.getMatrixColumns("obs").includes("foo")
|
||||
crossfilter.annoMatrix.getMatrixColumns(Field.obs).includes("foo")
|
||||
).toBeFalsy();
|
||||
const xfltr = crossfilter.addObsColumn(
|
||||
{ name: "foo", type: "categorical", categories: ["A"] },
|
||||
@@ -345,7 +346,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// check schema updates correctly.
|
||||
expect(xfltr.countSelected()).toBe(annoMatrix.nObs);
|
||||
expect(
|
||||
xfltr.annoMatrix.getMatrixColumns("obs").includes("foo")
|
||||
xfltr.annoMatrix.getMatrixColumns(Field.obs).includes("foo")
|
||||
).toBeTruthy();
|
||||
expect(xfltr.annoMatrix.schema.annotations.obsByName.foo).toMatchObject({
|
||||
name: "foo",
|
||||
@@ -359,7 +360,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
).toHaveLength(1);
|
||||
|
||||
// check data update.
|
||||
const df: Dataframe = await xfltr.annoMatrix.fetch("obs", "foo");
|
||||
const df: Dataframe = await xfltr.annoMatrix.fetch(Field.obs, "foo");
|
||||
expect(
|
||||
df
|
||||
.col("foo")
|
||||
@@ -408,13 +409,13 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
expect(xfltr.annoMatrix.schema.annotations.obsByName.foo).toBeUndefined();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(xfltr.annoMatrix.fetch("obs", "foo")).rejects.toThrow(
|
||||
await expect(xfltr.annoMatrix.fetch(Field.obs, "foo")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
|
||||
// now same, but ensure we have built an index before doing the drop
|
||||
xfltr = await helperAddTestCol(crossfilter, "bar");
|
||||
xfltr = await xfltr.select("obs", "bar", {
|
||||
xfltr = await xfltr.select(Field.obs, "bar", {
|
||||
mode: "exact",
|
||||
values: "whatever",
|
||||
});
|
||||
@@ -422,9 +423,9 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(xfltr.select("obs", "bar", { mode: "all" })).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
await expect(
|
||||
xfltr.select(Field.obs, "bar", { mode: "all" })
|
||||
).rejects.toThrow("unknown column name");
|
||||
});
|
||||
|
||||
test("renameObsColumn", async () => {
|
||||
@@ -441,23 +442,25 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// add a column, then rename it.
|
||||
xfltr = await helperAddTestCol(crossfilter, "foo");
|
||||
xfltr = xfltr.renameObsColumn("foo", "bar");
|
||||
expect(xfltr.annoMatrix.getColumnSchema("obs", "foo")).toBeUndefined();
|
||||
expect(xfltr.annoMatrix.getColumnSchema("obs", "bar")).toMatchObject({
|
||||
expect(
|
||||
xfltr.annoMatrix.getColumnSchema(Field.obs, "foo")
|
||||
).toBeUndefined();
|
||||
expect(xfltr.annoMatrix.getColumnSchema(Field.obs, "bar")).toMatchObject({
|
||||
name: "bar",
|
||||
type: "categorical",
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(xfltr.annoMatrix.fetch("obs", "foo")).rejects.toThrow(
|
||||
await expect(xfltr.annoMatrix.fetch(Field.obs, "foo")).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
const df = await xfltr.annoMatrix.fetch("obs", "bar");
|
||||
const df = await xfltr.annoMatrix.fetch(Field.obs, "bar");
|
||||
expect(df.hasCol("bar")).toBeTruthy();
|
||||
|
||||
// now same, but ensure we have built an index before doing the rename
|
||||
xfltr = await helperAddTestCol(crossfilter, "bar");
|
||||
xfltr = await xfltr.select("obs", "bar", {
|
||||
xfltr = await xfltr.select(Field.obs, "bar", {
|
||||
mode: "exact",
|
||||
values: "whatever",
|
||||
});
|
||||
@@ -465,11 +468,11 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(fetch as any).mockRejectOnce(new Error("unknown column name"));
|
||||
await expect(xfltr.select("obs", "bar", { mode: "all" })).rejects.toThrow(
|
||||
"unknown column name"
|
||||
);
|
||||
await expect(
|
||||
xfltr.select("obs", "xyz", { mode: "none" })
|
||||
xfltr.select(Field.obs, "bar", { mode: "all" })
|
||||
).rejects.toThrow("unknown column name");
|
||||
await expect(
|
||||
xfltr.select(Field.obs, "xyz", { mode: "none" })
|
||||
).resolves.toBeInstanceOf(AnnoMatrixObsCrossfilter);
|
||||
});
|
||||
|
||||
@@ -493,7 +496,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
categories: ["unassigned"],
|
||||
});
|
||||
xfltr = xfltr.addObsAnnoCategory("foo", "a-new-label");
|
||||
expect(xfltr.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
expect(xfltr.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining(["a-new-label", "unassigned"]),
|
||||
@@ -511,12 +514,12 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
type: "categorical",
|
||||
categories: ["unassigned"],
|
||||
});
|
||||
xfltr = await xfltr.select("obs", "bar", {
|
||||
xfltr = await xfltr.select(Field.obs, "bar", {
|
||||
mode: "exact",
|
||||
values: "something",
|
||||
});
|
||||
xfltr = xfltr.addObsAnnoCategory("bar", "a-new-label");
|
||||
expect(xfltr.annoMatrix.getColumnSchema("obs", "bar")).toMatchObject({
|
||||
expect(xfltr.annoMatrix.getColumnSchema(Field.obs, "bar")).toMatchObject({
|
||||
name: "bar",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining(["a-new-label", "unassigned"]),
|
||||
@@ -540,14 +543,14 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
type: "categorical",
|
||||
categories: ["unassigned", "red", "green", "blue"],
|
||||
});
|
||||
xfltr = await xfltr.select("obs", "foo", { mode: "all" });
|
||||
xfltr = await xfltr.select(Field.obs, "foo", { mode: "all" });
|
||||
expect(
|
||||
(await xfltr.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.every((v: any) => v === "unassigned")
|
||||
).toBeTruthy();
|
||||
expect(xfltr.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
expect(xfltr.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
@@ -561,21 +564,23 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
// remove an unused category
|
||||
const xfltr1 = await xfltr.removeObsAnnoCategory("foo", "red", "mumble");
|
||||
expect(
|
||||
(await xfltr1.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr1.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.every((v: any) => v === "unassigned")
|
||||
).toBeTruthy();
|
||||
expect(xfltr1.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"green",
|
||||
"blue",
|
||||
"mumble",
|
||||
]),
|
||||
});
|
||||
expect(xfltr1.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject(
|
||||
{
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"green",
|
||||
"blue",
|
||||
"mumble",
|
||||
]),
|
||||
}
|
||||
);
|
||||
|
||||
// remove a used category
|
||||
const xfltr2 = await xfltr.removeObsAnnoCategory(
|
||||
@@ -584,16 +589,18 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
"red"
|
||||
);
|
||||
expect(
|
||||
(await xfltr2.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr2.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.every((v: any) => v === "red")
|
||||
).toBeTruthy();
|
||||
expect(xfltr2.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining(["green", "blue", "red"]),
|
||||
});
|
||||
expect(xfltr2.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject(
|
||||
{
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining(["green", "blue", "red"]),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("setObsColumnValues", async () => {
|
||||
@@ -611,7 +618,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
type: "categorical",
|
||||
categories: ["unassigned", "red", "green", "blue"],
|
||||
});
|
||||
xfltr = await xfltr.select("obs", "foo", { mode: "all" });
|
||||
xfltr = await xfltr.select(Field.obs, "foo", { mode: "all" });
|
||||
|
||||
// catch unknown row label
|
||||
await expect(() =>
|
||||
@@ -620,14 +627,14 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
|
||||
// set a few rows
|
||||
expect(
|
||||
(await xfltr.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.every((v: any) => v === "unassigned")
|
||||
).toBeTruthy();
|
||||
const xfltr1 = await xfltr.setObsColumnValues("foo", [0, 10], "purple");
|
||||
expect(
|
||||
(await xfltr1.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr1.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray()
|
||||
.every(
|
||||
@@ -636,20 +643,22 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
v === "unassigned" || (v === "purple" && (i === 0 || i === 10))
|
||||
)
|
||||
).toBeTruthy();
|
||||
expect(xfltr1.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
]),
|
||||
});
|
||||
expect(xfltr1.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject(
|
||||
{
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
]),
|
||||
}
|
||||
);
|
||||
|
||||
expect(xfltr1.countSelected()).toEqual(xfltr1.annoMatrix.nObs);
|
||||
const xfltr2 = await xfltr1.select("obs", "foo", {
|
||||
const xfltr2 = await xfltr1.select(Field.obs, "foo", {
|
||||
mode: "exact",
|
||||
values: ["purple"],
|
||||
});
|
||||
@@ -672,7 +681,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
type: "categorical",
|
||||
categories: ["unassigned", "red", "green", "blue"],
|
||||
});
|
||||
xfltr = await xfltr.select("obs", "foo", {
|
||||
xfltr = await xfltr.select(Field.obs, "foo", {
|
||||
mode: "exact",
|
||||
values: "red",
|
||||
});
|
||||
@@ -683,12 +692,12 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
).rejects.toThrow("unknown category");
|
||||
|
||||
let xfltr1 = await xfltr.setObsColumnValues("foo", [0, 10], "purple");
|
||||
xfltr1 = await xfltr1.select("obs", "foo", {
|
||||
xfltr1 = await xfltr1.select(Field.obs, "foo", {
|
||||
mode: "exact",
|
||||
values: "purple",
|
||||
});
|
||||
expect(
|
||||
(await xfltr1.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr1.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.filter((v: any) => v === "purple")
|
||||
@@ -696,29 +705,31 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
|
||||
xfltr1 = await xfltr1.resetObsColumnValues("foo", "purple", "magenta");
|
||||
expect(
|
||||
(await xfltr1.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr1.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.filter((v: any) => v === "magenta")
|
||||
).toHaveLength(2);
|
||||
expect(
|
||||
(await xfltr1.annoMatrix.fetch("obs", "foo"))
|
||||
(await xfltr1.annoMatrix.fetch(Field.obs, "foo"))
|
||||
.col("foo")
|
||||
.asArray() // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
.filter((v: any) => v === "purple")
|
||||
).toHaveLength(0);
|
||||
expect(xfltr1.annoMatrix.getColumnSchema("obs", "foo")).toMatchObject({
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
"magenta",
|
||||
]),
|
||||
});
|
||||
expect(xfltr1.annoMatrix.getColumnSchema(Field.obs, "foo")).toMatchObject(
|
||||
{
|
||||
name: "foo",
|
||||
type: "categorical",
|
||||
categories: expect.arrayContaining([
|
||||
"unassigned",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
"magenta",
|
||||
]),
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -729,7 +740,7 @@ describe("AnnoMatrixCrossfilter", () => {
|
||||
(fetch as any).once(
|
||||
serverMocks.dataframeResponse(["louvain"], [obsLouvain])
|
||||
);
|
||||
const xfltr = await crossfilter.select("obs", "louvain", {
|
||||
const xfltr = await crossfilter.select(Field.obs, "louvain", {
|
||||
mode: "exact",
|
||||
values: "B cells",
|
||||
});
|
||||
|
||||
@@ -4,31 +4,34 @@ import {
|
||||
_whereCacheCreate,
|
||||
_whereCacheMerge,
|
||||
} from "../../../src/annoMatrix/whereCache";
|
||||
import { Field, Schema } from "../../../src/common/types/schema";
|
||||
import { Query } from "../../../src/annoMatrix/query";
|
||||
|
||||
const schema = {};
|
||||
const schema = {} as Schema;
|
||||
|
||||
describe("whereCache", () => {
|
||||
test("whereCacheGet - where query, missing cache values", () => {
|
||||
expect(
|
||||
_whereCacheGet({}, schema, "X", {
|
||||
_whereCacheGet({}, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
field: Field.var,
|
||||
column: "foo",
|
||||
value: "bar",
|
||||
},
|
||||
})
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet({}, schema, "X", {
|
||||
_whereCacheGet({}, schema, Field.X, {
|
||||
summarize: {
|
||||
field: "var",
|
||||
method: "mean",
|
||||
field: Field.var,
|
||||
column: "foo",
|
||||
values: ["bar"],
|
||||
},
|
||||
})
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet({ where: { X: {} } }, schema, "X", {
|
||||
_whereCacheGet({ where: { X: {} } }, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "foo",
|
||||
@@ -37,7 +40,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet({ where: { X: { var: new Map() } } }, schema, "X", {
|
||||
_whereCacheGet({ where: { X: { var: new Map() } } }, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "foo",
|
||||
@@ -49,7 +52,7 @@ describe("whereCache", () => {
|
||||
_whereCacheGet(
|
||||
{ where: { X: { var: new Map([["foo", new Map()]]) } } },
|
||||
schema,
|
||||
"X",
|
||||
Field.X,
|
||||
{
|
||||
where: {
|
||||
field: "var",
|
||||
@@ -63,7 +66,7 @@ describe("whereCache", () => {
|
||||
|
||||
test("whereCacheGet - summarize query, missing cache values", () => {
|
||||
expect(
|
||||
_whereCacheGet({}, schema, "X", {
|
||||
_whereCacheGet({}, schema, Field.X, {
|
||||
summarize: {
|
||||
method: "mean",
|
||||
field: "var",
|
||||
@@ -76,7 +79,7 @@ describe("whereCache", () => {
|
||||
_whereCacheGet(
|
||||
{ summarize: { X: { mean: { var: new Map() } } } },
|
||||
schema,
|
||||
"X",
|
||||
Field.X,
|
||||
{
|
||||
summarize: {
|
||||
method: "mean",
|
||||
@@ -122,7 +125,7 @@ describe("whereCache", () => {
|
||||
};
|
||||
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "foo",
|
||||
@@ -131,7 +134,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([0]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
summarize: {
|
||||
method: "mean",
|
||||
field: "var",
|
||||
@@ -141,7 +144,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([0]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "foo",
|
||||
@@ -150,7 +153,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([1, 2]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
summarize: {
|
||||
method: "mean",
|
||||
field: "var",
|
||||
@@ -159,9 +162,12 @@ describe("whereCache", () => {
|
||||
},
|
||||
})
|
||||
).toEqual([1, 2]);
|
||||
expect(_whereCacheGet(whereCache, schema, "Y", {})).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
// Force invalid field value Y
|
||||
_whereCacheGet(whereCache, schema, "Y" as Field, {} as Query)
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
where: {
|
||||
field: "whoknows",
|
||||
column: "whatever",
|
||||
@@ -170,7 +176,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "whatever",
|
||||
@@ -179,7 +185,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual([undefined]);
|
||||
expect(
|
||||
_whereCacheGet(whereCache, schema, "X", {
|
||||
_whereCacheGet(whereCache, schema, Field.X, {
|
||||
where: {
|
||||
field: "var",
|
||||
column: "foo",
|
||||
@@ -198,7 +204,7 @@ describe("whereCache", () => {
|
||||
},
|
||||
};
|
||||
const wc = _whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{
|
||||
where: {
|
||||
field: "queryField",
|
||||
@@ -212,7 +218,7 @@ describe("whereCache", () => {
|
||||
expect(wc).toEqual(
|
||||
expect.objectContaining({
|
||||
where: {
|
||||
field: {
|
||||
[Field.obs]: {
|
||||
queryField: expect.any(Map),
|
||||
},
|
||||
},
|
||||
@@ -220,18 +226,19 @@ describe("whereCache", () => {
|
||||
);
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
expect((wc.where as any).field.queryField.has("queryColumn")).toEqual(true);
|
||||
expect((wc.where as any)[Field.obs].queryField.has("queryColumn")).toEqual(true);
|
||||
expect(
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(wc.where as any).field.queryField.get("queryColumn")
|
||||
(wc.where as any)[Field.obs].queryField.get("queryColumn")
|
||||
).toBeInstanceOf(Map);
|
||||
expect(
|
||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
|
||||
(wc.where as any).field.queryField.get("queryColumn").has("queryValue")
|
||||
(wc.where as any)[Field.obs].queryField.get("queryColumn").has("queryValue")
|
||||
).toEqual(true);
|
||||
expect(_whereCacheGet(wc, schema, "field", query)).toEqual([0, 1, 2]);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
|
||||
expect(_whereCacheGet(wc!, schema, Field.obs, query)).toEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
test("whereCacheCreate, summarize query", () => {
|
||||
@@ -243,12 +250,14 @@ describe("whereCache", () => {
|
||||
values: ["queryValue"],
|
||||
},
|
||||
};
|
||||
const wc = _whereCacheCreate("field", query, [0, 1, 2]);
|
||||
expect(_whereCacheGet(wc, schema, "field", query)).toEqual([0, 1, 2]);
|
||||
const wc = _whereCacheCreate(Field.obs, query, [0, 1, 2]);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
|
||||
expect(_whereCacheGet(wc!, schema, Field.obs, query)).toEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
test("whereCacheCreate, unknown query type", () => {
|
||||
expect(_whereCacheCreate("field", { foobar: true }, [1])).toEqual({});
|
||||
// @ts-expect-error --- force invalid query {foobar: true}
|
||||
expect(_whereCacheCreate(Field.obs, { foobar: true }, [1])).toEqual({});
|
||||
});
|
||||
|
||||
test("whereCacheMerge, where queries", () => {
|
||||
@@ -256,19 +265,20 @@ describe("whereCache", () => {
|
||||
|
||||
// remember, will mutate dst
|
||||
const src = _whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{ where: { field: "queryField", column: "queryColumn", value: "foo" } },
|
||||
["foo"]
|
||||
);
|
||||
|
||||
const dst1 = _whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{ where: { field: "queryField", column: "queryColumn", value: "bar" } },
|
||||
["dst1"]
|
||||
);
|
||||
wc = _whereCacheMerge(dst1, src);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert dst1 and src to be non-null
|
||||
wc = _whereCacheMerge(dst1!, src!);
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -277,7 +287,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual(["foo"]);
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -287,13 +297,14 @@ describe("whereCache", () => {
|
||||
).toEqual(["dst1"]);
|
||||
|
||||
const dst2 = _whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{ where: { field: "queryField", column: "queryColumn", value: "bar" } },
|
||||
["dst2"]
|
||||
);
|
||||
wc = _whereCacheMerge(dst2, dst1, src);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert dst2m, dst1 and src to be non-null
|
||||
wc = _whereCacheMerge(dst2!, dst1!, src!);
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -302,7 +313,7 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual(["foo"]);
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -311,17 +322,20 @@ describe("whereCache", () => {
|
||||
})
|
||||
).toEqual(["dst1"]);
|
||||
|
||||
wc = _whereCacheMerge({}, src);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert src to be non-null
|
||||
wc = _whereCacheMerge({}, src!);
|
||||
expect(wc).toEqual(src);
|
||||
|
||||
wc = _whereCacheMerge({ where: { field: { queryField: new Map() } } }, src);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert src to be non-null
|
||||
wc = _whereCacheMerge({ where: { obs: { queryField: new Map() } } }, src!);
|
||||
expect(wc).toEqual(src);
|
||||
});
|
||||
|
||||
test("whereCacheMerge, mixed queries", () => {
|
||||
const wc = _whereCacheMerge(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
|
||||
_whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{
|
||||
where: {
|
||||
field: "queryField",
|
||||
@@ -330,9 +344,10 @@ describe("whereCache", () => {
|
||||
},
|
||||
},
|
||||
["a"]
|
||||
),
|
||||
)!,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion --- assert wc to be non-null
|
||||
_whereCacheCreate(
|
||||
"field",
|
||||
Field.obs,
|
||||
{
|
||||
summarize: {
|
||||
method: "mean",
|
||||
@@ -342,11 +357,11 @@ describe("whereCache", () => {
|
||||
},
|
||||
},
|
||||
["b"]
|
||||
)
|
||||
)!
|
||||
);
|
||||
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -356,7 +371,7 @@ describe("whereCache", () => {
|
||||
).toEqual(["a"]);
|
||||
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
summarize: {
|
||||
method: "mean",
|
||||
field: "queryField",
|
||||
@@ -367,7 +382,7 @@ describe("whereCache", () => {
|
||||
).toEqual(["b"]);
|
||||
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
where: {
|
||||
field: "queryField",
|
||||
column: "queryColumn",
|
||||
@@ -377,7 +392,7 @@ describe("whereCache", () => {
|
||||
).toEqual([undefined]);
|
||||
|
||||
expect(
|
||||
_whereCacheGet(wc, schema, "field", {
|
||||
_whereCacheGet(wc, schema, Field.obs, {
|
||||
summarize: {
|
||||
method: "no-such-method",
|
||||
field: "queryField",
|
||||
|
||||
Reference in New Issue
Block a user