Have the skeleton query wizard call promptImportGithubDatabase so we can make more methods private
This commit is contained in:
@@ -108,10 +108,11 @@ export class DatabaseFetcher {
|
|||||||
public async promptImportGithubDatabase(
|
public async promptImportGithubDatabase(
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
language?: string,
|
language?: string,
|
||||||
|
suggestedRepoNwo?: string,
|
||||||
makeSelected = true,
|
makeSelected = true,
|
||||||
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
|
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
|
||||||
): Promise<DatabaseItem | undefined> {
|
): Promise<DatabaseItem | undefined> {
|
||||||
const githubRepo = await this.askForGitHubRepo(progress);
|
const githubRepo = await this.askForGitHubRepo(progress, suggestedRepoNwo);
|
||||||
if (!githubRepo) {
|
if (!githubRepo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ export class DatabaseFetcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async askForGitHubRepo(
|
private async askForGitHubRepo(
|
||||||
progress?: ProgressCallback,
|
progress?: ProgressCallback,
|
||||||
suggestedValue?: string,
|
suggestedValue?: string,
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
@@ -171,7 +172,7 @@ export class DatabaseFetcher {
|
|||||||
* @param makeSelected make the new database selected in the databases panel (default: true)
|
* @param makeSelected make the new database selected in the databases panel (default: true)
|
||||||
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
||||||
**/
|
**/
|
||||||
public async downloadGitHubDatabase(
|
private async downloadGitHubDatabase(
|
||||||
githubRepo: string,
|
githubRepo: string,
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
language?: string,
|
language?: string,
|
||||||
|
|||||||
@@ -371,19 +371,10 @@ export class SkeletonQueryWizard {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
|
||||||
const chosenRepo = await this.databaseFetcher.askForGitHubRepo(
|
await this.databaseFetcher.promptImportGithubDatabase(
|
||||||
undefined,
|
|
||||||
githubRepoNwo,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!chosenRepo) {
|
|
||||||
throw new UserCancellationException("No GitHub repository provided");
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.databaseFetcher.downloadGitHubDatabase(
|
|
||||||
chosenRepo,
|
|
||||||
progress,
|
progress,
|
||||||
this.language,
|
this.language,
|
||||||
|
githubRepoNwo,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -925,6 +925,7 @@ export class ModelEditorView extends AbstractWebview<
|
|||||||
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
|
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
|
||||||
progress,
|
progress,
|
||||||
this.databaseItem.language,
|
this.databaseItem.language,
|
||||||
|
undefined,
|
||||||
makeSelected,
|
makeSelected,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,11 +56,8 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
let createExampleQlFileSpy: jest.SpiedFunction<
|
let createExampleQlFileSpy: jest.SpiedFunction<
|
||||||
typeof QlPackGenerator.prototype.createExampleQlFile
|
typeof QlPackGenerator.prototype.createExampleQlFile
|
||||||
>;
|
>;
|
||||||
let downloadGitHubDatabaseSpy: jest.SpiedFunction<
|
let promptImportGithubDatabaseSpy: jest.SpiedFunction<
|
||||||
DatabaseFetcher["downloadGitHubDatabase"]
|
DatabaseFetcher["promptImportGithubDatabase"]
|
||||||
>;
|
|
||||||
let askForGitHubRepoSpy: jest.SpiedFunction<
|
|
||||||
DatabaseFetcher["askForGitHubRepo"]
|
|
||||||
>;
|
>;
|
||||||
let openTextDocumentSpy: jest.SpiedFunction<
|
let openTextDocumentSpy: jest.SpiedFunction<
|
||||||
typeof workspace.openTextDocument
|
typeof workspace.openTextDocument
|
||||||
@@ -141,8 +138,8 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
createExampleQlFileSpy = jest
|
createExampleQlFileSpy = jest
|
||||||
.spyOn(QlPackGenerator.prototype, "createExampleQlFile")
|
.spyOn(QlPackGenerator.prototype, "createExampleQlFile")
|
||||||
.mockResolvedValue(undefined);
|
.mockResolvedValue(undefined);
|
||||||
downloadGitHubDatabaseSpy = jest
|
promptImportGithubDatabaseSpy = jest
|
||||||
.spyOn(databaseFetcher, "downloadGitHubDatabase")
|
.spyOn(databaseFetcher, "promptImportGithubDatabase")
|
||||||
.mockResolvedValue(undefined);
|
.mockResolvedValue(undefined);
|
||||||
openTextDocumentSpy = jest
|
openTextDocumentSpy = jest
|
||||||
.spyOn(workspace, "openTextDocument")
|
.spyOn(workspace, "openTextDocument")
|
||||||
@@ -156,10 +153,6 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
databaseFetcher,
|
databaseFetcher,
|
||||||
selectedItems,
|
selectedItems,
|
||||||
);
|
);
|
||||||
|
|
||||||
askForGitHubRepoSpy = jest
|
|
||||||
.spyOn(databaseFetcher, "askForGitHubRepo")
|
|
||||||
.mockResolvedValue(QUERY_LANGUAGE_TO_DATABASE_REPO[chosenLanguage]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -210,7 +203,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
title: "Download database",
|
title: "Download database",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should download database for selected language when selecting download in prompt", async () => {
|
it("should download database for selected language when selecting download in prompt", async () => {
|
||||||
@@ -227,7 +220,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
await wizard.execute();
|
await wizard.execute();
|
||||||
await wizard.waitForDownload();
|
await wizard.waitForDownload();
|
||||||
|
|
||||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should open the query file", async () => {
|
it("should open the query file", async () => {
|
||||||
@@ -336,7 +329,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
it("should not download a new database for language", async () => {
|
it("should not download a new database for language", async () => {
|
||||||
await wizard.execute();
|
await wizard.execute();
|
||||||
|
|
||||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not select the database", async () => {
|
it("should not select the database", async () => {
|
||||||
@@ -385,7 +378,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
it("should not download a new database for language", async () => {
|
it("should not download a new database for language", async () => {
|
||||||
await wizard.execute();
|
await wizard.execute();
|
||||||
|
|
||||||
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
|
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should select an existing database", async () => {
|
it("should select an existing database", async () => {
|
||||||
@@ -417,54 +410,23 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("if database is missing", () => {
|
describe("if database is missing", () => {
|
||||||
describe("if the user chooses to downloaded the suggested database from GitHub", () => {
|
beforeEach(() => {
|
||||||
beforeEach(() => {
|
showInformationMessageSpy.mockImplementation(
|
||||||
showInformationMessageSpy.mockImplementation(
|
async (_message, options, item) => {
|
||||||
async (_message, options, item) => {
|
if (item === undefined) {
|
||||||
if (item === undefined) {
|
return options as MessageItem;
|
||||||
return options as MessageItem;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
it("should download a new database for language", async () => {
|
|
||||||
await wizard.execute();
|
|
||||||
await wizard.waitForDownload();
|
|
||||||
|
|
||||||
expect(askForGitHubRepoSpy).toHaveBeenCalled();
|
|
||||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("if the user choses to download a different database from GitHub than the one suggested", () => {
|
it("should download a new database for language", async () => {
|
||||||
beforeEach(() => {
|
await wizard.execute();
|
||||||
showInformationMessageSpy.mockImplementation(
|
await wizard.waitForDownload();
|
||||||
async (_message, options, item) => {
|
|
||||||
if (item === undefined) {
|
|
||||||
return options as MessageItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const chosenGitHubRepo = "pickles-owner/pickles-repo";
|
|
||||||
|
|
||||||
askForGitHubRepoSpy = jest
|
|
||||||
.spyOn(databaseFetcher, "askForGitHubRepo")
|
|
||||||
.mockResolvedValue(chosenGitHubRepo);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should download the newly chosen database", async () => {
|
|
||||||
await wizard.execute();
|
|
||||||
await wizard.waitForDownload();
|
|
||||||
|
|
||||||
expect(askForGitHubRepoSpy).toHaveBeenCalled();
|
|
||||||
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user