Fix and add tests.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
import { CancellationTokenSource } from "vscode";
|
import { CancellationTokenSource } from "vscode";
|
||||||
import { QueryResultType } from "../../../src/query-server/legacy-messages";
|
import { QueryResultType } from "../../../src/query-server/legacy-messages";
|
||||||
import { QueryMetadata } from "../../../src/common/interface-types";
|
import { QueryMetadata } from "../../../src/common/interface-types";
|
||||||
|
import { QueryLanguage } from "../../../src/common/query-language";
|
||||||
|
|
||||||
export function createMockLocalQueryInfo({
|
export function createMockLocalQueryInfo({
|
||||||
startTime = new Date(),
|
startTime = new Date(),
|
||||||
@@ -16,6 +17,7 @@ export function createMockLocalQueryInfo({
|
|||||||
dbName = "db-name",
|
dbName = "db-name",
|
||||||
hasMetadata = false,
|
hasMetadata = false,
|
||||||
queryWithResults = undefined,
|
queryWithResults = undefined,
|
||||||
|
language = undefined,
|
||||||
}: {
|
}: {
|
||||||
startTime?: Date;
|
startTime?: Date;
|
||||||
resultCount?: number;
|
resultCount?: number;
|
||||||
@@ -24,6 +26,7 @@ export function createMockLocalQueryInfo({
|
|||||||
dbName?: string;
|
dbName?: string;
|
||||||
hasMetadata?: boolean;
|
hasMetadata?: boolean;
|
||||||
queryWithResults?: QueryWithResults | undefined;
|
queryWithResults?: QueryWithResults | undefined;
|
||||||
|
language?: QueryLanguage;
|
||||||
}): LocalQueryInfo {
|
}): LocalQueryInfo {
|
||||||
const cancellationToken = {
|
const cancellationToken = {
|
||||||
dispose: () => {
|
dispose: () => {
|
||||||
@@ -40,6 +43,7 @@ export function createMockLocalQueryInfo({
|
|||||||
databaseInfo: {
|
databaseInfo: {
|
||||||
databaseUri: "databaseUri",
|
databaseUri: "databaseUri",
|
||||||
name: dbName,
|
name: dbName,
|
||||||
|
language,
|
||||||
},
|
},
|
||||||
start: startTime,
|
start: startTime,
|
||||||
id: faker.number.int().toString(),
|
id: faker.number.int().toString(),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
VariantAnalysisStatus,
|
VariantAnalysisStatus,
|
||||||
} from "../../../src/variant-analysis/shared/variant-analysis";
|
} from "../../../src/variant-analysis/shared/variant-analysis";
|
||||||
import { createMockVariantAnalysis } from "../variant-analysis/shared/variant-analysis";
|
import { createMockVariantAnalysis } from "../variant-analysis/shared/variant-analysis";
|
||||||
|
import { QueryLanguage } from "../../../src/common/query-language";
|
||||||
|
|
||||||
export function createMockVariantAnalysisHistoryItem({
|
export function createMockVariantAnalysisHistoryItem({
|
||||||
historyItemStatus = QueryStatus.InProgress,
|
historyItemStatus = QueryStatus.InProgress,
|
||||||
@@ -14,6 +15,7 @@ export function createMockVariantAnalysisHistoryItem({
|
|||||||
userSpecifiedLabel = undefined,
|
userSpecifiedLabel = undefined,
|
||||||
executionStartTime = undefined,
|
executionStartTime = undefined,
|
||||||
variantAnalysis = undefined,
|
variantAnalysis = undefined,
|
||||||
|
language = QueryLanguage.Javascript,
|
||||||
}: {
|
}: {
|
||||||
historyItemStatus?: QueryStatus;
|
historyItemStatus?: QueryStatus;
|
||||||
variantAnalysisStatus?: VariantAnalysisStatus;
|
variantAnalysisStatus?: VariantAnalysisStatus;
|
||||||
@@ -22,6 +24,7 @@ export function createMockVariantAnalysisHistoryItem({
|
|||||||
userSpecifiedLabel?: string;
|
userSpecifiedLabel?: string;
|
||||||
executionStartTime?: number;
|
executionStartTime?: number;
|
||||||
variantAnalysis?: VariantAnalysis;
|
variantAnalysis?: VariantAnalysis;
|
||||||
|
language?: QueryLanguage;
|
||||||
}): VariantAnalysisHistoryItem {
|
}): VariantAnalysisHistoryItem {
|
||||||
return {
|
return {
|
||||||
t: "variant-analysis",
|
t: "variant-analysis",
|
||||||
@@ -34,6 +37,7 @@ export function createMockVariantAnalysisHistoryItem({
|
|||||||
createMockVariantAnalysis({
|
createMockVariantAnalysis({
|
||||||
status: variantAnalysisStatus,
|
status: variantAnalysisStatus,
|
||||||
executionStartTime,
|
executionStartTime,
|
||||||
|
language,
|
||||||
}),
|
}),
|
||||||
userSpecifiedLabel,
|
userSpecifiedLabel,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ export function createMockVariantAnalysis({
|
|||||||
scannedRepos = createMockScannedRepos(),
|
scannedRepos = createMockScannedRepos(),
|
||||||
skippedRepos = createMockSkippedRepos(),
|
skippedRepos = createMockSkippedRepos(),
|
||||||
executionStartTime = faker.number.int(),
|
executionStartTime = faker.number.int(),
|
||||||
|
language = QueryLanguage.Javascript,
|
||||||
}: {
|
}: {
|
||||||
status?: VariantAnalysisStatus;
|
status?: VariantAnalysisStatus;
|
||||||
scannedRepos?: VariantAnalysisScannedRepository[];
|
scannedRepos?: VariantAnalysisScannedRepository[];
|
||||||
skippedRepos?: VariantAnalysisSkippedRepositories;
|
skippedRepos?: VariantAnalysisSkippedRepositories;
|
||||||
executionStartTime?: number | undefined;
|
executionStartTime?: number | undefined;
|
||||||
|
language?: QueryLanguage;
|
||||||
}): VariantAnalysis {
|
}): VariantAnalysis {
|
||||||
return {
|
return {
|
||||||
id: faker.number.int(),
|
id: faker.number.int(),
|
||||||
@@ -32,7 +34,7 @@ export function createMockVariantAnalysis({
|
|||||||
query: {
|
query: {
|
||||||
name: "a-query-name",
|
name: "a-query-name",
|
||||||
filePath: "a-query-file-path",
|
filePath: "a-query-file-path",
|
||||||
language: QueryLanguage.Javascript,
|
language,
|
||||||
text: "a-query-text",
|
text: "a-query-text",
|
||||||
},
|
},
|
||||||
databases: {
|
databases: {
|
||||||
|
|||||||
@@ -28,9 +28,13 @@ import {
|
|||||||
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
import { QueryHistoryManager } from "../../../../src/query-history/query-history-manager";
|
||||||
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
||||||
import { createMockApp } from "../../../__mocks__/appMock";
|
import { createMockApp } from "../../../__mocks__/appMock";
|
||||||
|
import { LanguageContextStore } from "../../../../src/language-context-store";
|
||||||
|
import { App } from "../../../../src/common/app";
|
||||||
|
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||||
|
|
||||||
describe("HistoryTreeDataProvider", () => {
|
describe("HistoryTreeDataProvider", () => {
|
||||||
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
||||||
|
let app: App;
|
||||||
let configListener: QueryHistoryConfigListener;
|
let configListener: QueryHistoryConfigListener;
|
||||||
const doCompareCallback = jest.fn();
|
const doCompareCallback = jest.fn();
|
||||||
|
|
||||||
@@ -45,10 +49,12 @@ describe("HistoryTreeDataProvider", () => {
|
|||||||
|
|
||||||
let historyTreeDataProvider: HistoryTreeDataProvider;
|
let historyTreeDataProvider: HistoryTreeDataProvider;
|
||||||
let labelProvider: HistoryItemLabelProvider;
|
let labelProvider: HistoryItemLabelProvider;
|
||||||
|
let languageContext: LanguageContextStore;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(extLogger, "log").mockResolvedValue(undefined);
|
jest.spyOn(extLogger, "log").mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
app = createMockApp({});
|
||||||
configListener = new QueryHistoryConfigListener();
|
configListener = new QueryHistoryConfigListener();
|
||||||
localQueriesResultsViewStub = {
|
localQueriesResultsViewStub = {
|
||||||
showResults: jest.fn(),
|
showResults: jest.fn(),
|
||||||
@@ -124,7 +130,11 @@ describe("HistoryTreeDataProvider", () => {
|
|||||||
ttlInMillis: 0,
|
ttlInMillis: 0,
|
||||||
onDidChangeConfiguration: jest.fn(),
|
onDidChangeConfiguration: jest.fn(),
|
||||||
});
|
});
|
||||||
historyTreeDataProvider = new HistoryTreeDataProvider(labelProvider);
|
languageContext = new LanguageContextStore(app);
|
||||||
|
historyTreeDataProvider = new HistoryTreeDataProvider(
|
||||||
|
labelProvider,
|
||||||
|
languageContext,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -418,11 +428,68 @@ describe("HistoryTreeDataProvider", () => {
|
|||||||
expect(children).toEqual(expected);
|
expect(children).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("filtering", () => {
|
||||||
|
const history = [
|
||||||
|
createMockLocalQueryInfo({
|
||||||
|
userSpecifiedLabel: "a",
|
||||||
|
// No language at all => unknown
|
||||||
|
}),
|
||||||
|
createMockVariantAnalysisHistoryItem({
|
||||||
|
userSpecifiedLabel: "b",
|
||||||
|
// No specified language => javascript
|
||||||
|
}),
|
||||||
|
createMockLocalQueryInfo({
|
||||||
|
userSpecifiedLabel: "c",
|
||||||
|
language: QueryLanguage.Python,
|
||||||
|
}),
|
||||||
|
createMockVariantAnalysisHistoryItem({
|
||||||
|
userSpecifiedLabel: "d",
|
||||||
|
language: QueryLanguage.Java,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
let treeDataProvider: HistoryTreeDataProvider;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||||
|
(queryHistoryManager.treeDataProvider as any).history = [...history];
|
||||||
|
treeDataProvider = queryHistoryManager.treeDataProvider;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should get all if no filter is provided", async () => {
|
||||||
|
const expected = [history[0], history[1], history[2], history[3]];
|
||||||
|
treeDataProvider.sortOrder = SortOrder.NameAsc;
|
||||||
|
|
||||||
|
const children = await treeDataProvider.getChildren();
|
||||||
|
expect(children).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should filter local runs by language", async () => {
|
||||||
|
const expected = [history[3]];
|
||||||
|
treeDataProvider.sortOrder = SortOrder.NameAsc;
|
||||||
|
|
||||||
|
await languageContext.setLanguageContext(QueryLanguage.Java);
|
||||||
|
|
||||||
|
const children = await treeDataProvider.getChildren();
|
||||||
|
expect(children).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should filter variant analysis runs by language", async () => {
|
||||||
|
const expected = [history[2]];
|
||||||
|
treeDataProvider.sortOrder = SortOrder.NameAsc;
|
||||||
|
|
||||||
|
await languageContext.setLanguageContext(QueryLanguage.Python);
|
||||||
|
|
||||||
|
const children = await treeDataProvider.getChildren();
|
||||||
|
expect(children).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
|
async function createMockQueryHistory(allHistory: QueryHistoryInfo[]) {
|
||||||
const qhm = new QueryHistoryManager(
|
const qhm = new QueryHistoryManager(
|
||||||
createMockApp({}),
|
app,
|
||||||
{} as QueryRunner,
|
{} as QueryRunner,
|
||||||
{} as DatabaseManager,
|
{} as DatabaseManager,
|
||||||
localQueriesResultsViewStub,
|
localQueriesResultsViewStub,
|
||||||
@@ -439,6 +506,7 @@ describe("HistoryTreeDataProvider", () => {
|
|||||||
ttlInMillis: 0,
|
ttlInMillis: 0,
|
||||||
onDidChangeConfiguration: jest.fn(),
|
onDidChangeConfiguration: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
languageContext,
|
||||||
doCompareCallback,
|
doCompareCallback,
|
||||||
);
|
);
|
||||||
(qhm.treeDataProvider as any).history = [...allHistory];
|
(qhm.treeDataProvider as any).history = [...allHistory];
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { createMockQueryHistoryDirs } from "../../../factories/query-history/que
|
|||||||
import { createMockApp } from "../../../__mocks__/appMock";
|
import { createMockApp } from "../../../__mocks__/appMock";
|
||||||
import { App } from "../../../../src/common/app";
|
import { App } from "../../../../src/common/app";
|
||||||
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
|
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
|
||||||
|
import { LanguageContextStore } from "../../../../src/language-context-store";
|
||||||
|
|
||||||
describe("QueryHistoryManager", () => {
|
describe("QueryHistoryManager", () => {
|
||||||
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
||||||
@@ -937,6 +938,7 @@ describe("QueryHistoryManager", () => {
|
|||||||
ttlInMillis: 0,
|
ttlInMillis: 0,
|
||||||
onDidChangeConfiguration: jest.fn(),
|
onDidChangeConfiguration: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
new LanguageContextStore(mockApp),
|
||||||
doCompareCallback,
|
doCompareCallback,
|
||||||
);
|
);
|
||||||
(qhm.treeDataProvider as any).history = [...allHistory];
|
(qhm.treeDataProvider as any).history = [...allHistory];
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { QueryHistoryManager } from "../../../../src/query-history/query-history
|
|||||||
import { mockedObject } from "../../utils/mocking.helpers";
|
import { mockedObject } from "../../utils/mocking.helpers";
|
||||||
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
import { createMockQueryHistoryDirs } from "../../../factories/query-history/query-history-dirs";
|
||||||
import { createMockApp } from "../../../__mocks__/appMock";
|
import { createMockApp } from "../../../__mocks__/appMock";
|
||||||
|
import { LanguageContextStore } from "../../../../src/language-context-store";
|
||||||
|
|
||||||
// set a higher timeout since recursive delete may take a while, expecially on Windows.
|
// set a higher timeout since recursive delete may take a while, expecially on Windows.
|
||||||
jest.setTimeout(120000);
|
jest.setTimeout(120000);
|
||||||
@@ -74,8 +75,10 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
|||||||
join(STORAGE_DIR, "workspace-query-history.json"),
|
join(STORAGE_DIR, "workspace-query-history.json"),
|
||||||
).queries;
|
).queries;
|
||||||
|
|
||||||
|
const app = createMockApp({});
|
||||||
|
|
||||||
qhm = new QueryHistoryManager(
|
qhm = new QueryHistoryManager(
|
||||||
createMockApp({}),
|
app,
|
||||||
{} as QueryRunner,
|
{} as QueryRunner,
|
||||||
{} as DatabaseManager,
|
{} as DatabaseManager,
|
||||||
localQueriesResultsViewStub,
|
localQueriesResultsViewStub,
|
||||||
@@ -97,6 +100,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
|||||||
ttlInMillis: 0,
|
ttlInMillis: 0,
|
||||||
onDidChangeConfiguration: jest.fn(),
|
onDidChangeConfiguration: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
new LanguageContextStore(app),
|
||||||
asyncNoop,
|
asyncNoop,
|
||||||
);
|
);
|
||||||
disposables.push(qhm);
|
disposables.push(qhm);
|
||||||
|
|||||||
Reference in New Issue
Block a user