Have the skeleton query wizard call promptImportGithubDatabase so we can make more methods private

This commit is contained in:
Robert
2024-03-07 12:58:21 +00:00
parent f29aff6303
commit 9fa6d99f09
4 changed files with 28 additions and 73 deletions

View File

@@ -108,10 +108,11 @@ export class DatabaseFetcher {
public async promptImportGithubDatabase(
progress: ProgressCallback,
language?: string,
suggestedRepoNwo?: string,
makeSelected = true,
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
): Promise<DatabaseItem | undefined> {
const githubRepo = await this.askForGitHubRepo(progress);
const githubRepo = await this.askForGitHubRepo(progress, suggestedRepoNwo);
if (!githubRepo) {
return;
}
@@ -138,7 +139,7 @@ export class DatabaseFetcher {
return;
}
public async askForGitHubRepo(
private async askForGitHubRepo(
progress?: ProgressCallback,
suggestedValue?: string,
): Promise<string | undefined> {
@@ -171,7 +172,7 @@ export class DatabaseFetcher {
* @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
**/
public async downloadGitHubDatabase(
private async downloadGitHubDatabase(
githubRepo: string,
progress: ProgressCallback,
language?: string,

View File

@@ -371,19 +371,10 @@ export class SkeletonQueryWizard {
});
const githubRepoNwo = QUERY_LANGUAGE_TO_DATABASE_REPO[this.language];
const chosenRepo = await this.databaseFetcher.askForGitHubRepo(
undefined,
githubRepoNwo,
);
if (!chosenRepo) {
throw new UserCancellationException("No GitHub repository provided");
}
await this.databaseFetcher.downloadGitHubDatabase(
chosenRepo,
await this.databaseFetcher.promptImportGithubDatabase(
progress,
this.language,
githubRepoNwo,
);
}

View File

@@ -925,6 +925,7 @@ export class ModelEditorView extends AbstractWebview<
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
progress,
this.databaseItem.language,
undefined,
makeSelected,
false,
);

View File

@@ -56,11 +56,8 @@ describe("SkeletonQueryWizard", () => {
let createExampleQlFileSpy: jest.SpiedFunction<
typeof QlPackGenerator.prototype.createExampleQlFile
>;
let downloadGitHubDatabaseSpy: jest.SpiedFunction<
DatabaseFetcher["downloadGitHubDatabase"]
>;
let askForGitHubRepoSpy: jest.SpiedFunction<
DatabaseFetcher["askForGitHubRepo"]
let promptImportGithubDatabaseSpy: jest.SpiedFunction<
DatabaseFetcher["promptImportGithubDatabase"]
>;
let openTextDocumentSpy: jest.SpiedFunction<
typeof workspace.openTextDocument
@@ -141,8 +138,8 @@ describe("SkeletonQueryWizard", () => {
createExampleQlFileSpy = jest
.spyOn(QlPackGenerator.prototype, "createExampleQlFile")
.mockResolvedValue(undefined);
downloadGitHubDatabaseSpy = jest
.spyOn(databaseFetcher, "downloadGitHubDatabase")
promptImportGithubDatabaseSpy = jest
.spyOn(databaseFetcher, "promptImportGithubDatabase")
.mockResolvedValue(undefined);
openTextDocumentSpy = jest
.spyOn(workspace, "openTextDocument")
@@ -156,10 +153,6 @@ describe("SkeletonQueryWizard", () => {
databaseFetcher,
selectedItems,
);
askForGitHubRepoSpy = jest
.spyOn(databaseFetcher, "askForGitHubRepo")
.mockResolvedValue(QUERY_LANGUAGE_TO_DATABASE_REPO[chosenLanguage]);
});
afterEach(async () => {
@@ -210,7 +203,7 @@ describe("SkeletonQueryWizard", () => {
title: "Download database",
}),
);
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
});
it("should download database for selected language when selecting download in prompt", async () => {
@@ -227,7 +220,7 @@ describe("SkeletonQueryWizard", () => {
await wizard.execute();
await wizard.waitForDownload();
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
});
it("should open the query file", async () => {
@@ -336,7 +329,7 @@ describe("SkeletonQueryWizard", () => {
it("should not download a new database for language", async () => {
await wizard.execute();
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
});
it("should not select the database", async () => {
@@ -385,7 +378,7 @@ describe("SkeletonQueryWizard", () => {
it("should not download a new database for language", async () => {
await wizard.execute();
expect(downloadGitHubDatabaseSpy).not.toHaveBeenCalled();
expect(promptImportGithubDatabaseSpy).not.toHaveBeenCalled();
});
it("should select an existing database", async () => {
@@ -417,54 +410,23 @@ describe("SkeletonQueryWizard", () => {
});
describe("if database is missing", () => {
describe("if the user chooses to downloaded the suggested database from GitHub", () => {
beforeEach(() => {
showInformationMessageSpy.mockImplementation(
async (_message, options, item) => {
if (item === undefined) {
return options as MessageItem;
}
beforeEach(() => {
showInformationMessageSpy.mockImplementation(
async (_message, options, item) => {
if (item === undefined) {
return options as MessageItem;
}
return item;
},
);
});
it("should download a new database for language", async () => {
await wizard.execute();
await wizard.waitForDownload();
expect(askForGitHubRepoSpy).toHaveBeenCalled();
expect(downloadGitHubDatabaseSpy).toHaveBeenCalled();
});
return item;
},
);
});
describe("if the user choses to download a different database from GitHub than the one suggested", () => {
beforeEach(() => {
showInformationMessageSpy.mockImplementation(
async (_message, options, item) => {
if (item === undefined) {
return options as MessageItem;
}
it("should download a new database for language", async () => {
await wizard.execute();
await wizard.waitForDownload();
return item;
},
);
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();
});
expect(promptImportGithubDatabaseSpy).toHaveBeenCalled();
});
});
});