From 819e742a09eb22623fe6eea97ccc5383a6d78dcc Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:52:30 -0400 Subject: [PATCH] chore: more unit tests Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- .../commands/UnixCommandHandler.unit.test.ts | 8 ++++---- .../commands/ZoweCommandProvider.unit.test.ts | 5 ++--- .../__unit__/tools/ZoweTerminal.unit.test.ts | 13 +++++++++++-- packages/zowe-explorer/src/tools/ZoweTerminal.ts | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/commands/UnixCommandHandler.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/commands/UnixCommandHandler.unit.test.ts index 87d73f640..fe3f4d845 100644 --- a/packages/zowe-explorer/__tests__/__unit__/commands/UnixCommandHandler.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/commands/UnixCommandHandler.unit.test.ts @@ -265,7 +265,7 @@ describe("UnixCommand Actions Unit Testing", () => { expect(showInputBox.mock.calls.length).toBe(2); expect(appendLine.mock.calls.length).toBe(2); - expect(appendLine.mock.calls[0][0]).toBe("> testUser@firstProfile:/u/directorypath$ /d iplinfo1"); + expect(appendLine.mock.calls[0][0]).toBe("> testUser@firstProfile:/u/directorypath $ /d iplinfo1"); expect(appendLine.mock.calls[1][0]["commandResponse"]).toBe("iplinfo1"); expect(showInformationMessage.mock.calls.length).toBe(0); }); @@ -286,7 +286,7 @@ describe("UnixCommand Actions Unit Testing", () => { }); }); - fit("tests the issueUnixCommand function user selects a history item", async () => { + it("tests the issueUnixCommand function user selects a history item", async () => { const mockUssApi = await apiRegisterInstance.getUssApi(profileOne); const getUssApiMock = jest.fn(); getUssApiMock.mockReturnValue(mockUssApi); @@ -452,10 +452,10 @@ describe("UnixCommand Actions Unit Testing", () => { await getUnixActions().issueUnixCommand(); - expect(showInformationMessage.mock.calls[0][0]).toEqual("Operation Cancelled"); + expect(showInformationMessage.mock.calls[0][0]).toEqual("Operation cancelled"); }); - fit("tests the issueUnixCommand function user starts typing a value in quick pick", async () => { + it("tests the issueUnixCommand function user starts typing a value in quick pick", async () => { createQuickPick.mockReturnValueOnce({ placeholder: 'Choose "Create new..." to define a new profile or select an existing profile to add to the Data Set Explorer', activeItems: [qpItem2], diff --git a/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts index 1db3523df..fb3063e1d 100644 --- a/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts @@ -10,15 +10,14 @@ */ import * as vscode from "vscode"; -import { Gui, imperative, ProfilesCache, ZoweTreeNode } from "@zowe/zowe-explorer-api"; +import { Gui, ProfilesCache, ZoweTreeNode } from "@zowe/zowe-explorer-api"; import { createIProfile, createISession } from "../../__mocks__/mockCreators/shared"; -import { ICommandProviderDialogs, ZoweCommandProvider } from "../../../src/commands/ZoweCommandProvider"; +import { ZoweCommandProvider } from "../../../src/commands/ZoweCommandProvider"; import { Profiles } from "../../../src/configuration/Profiles"; import { ZoweDatasetNode } from "../../../src/trees/dataset/ZoweDatasetNode"; import { SharedContext } from "../../../src/trees/shared/SharedContext"; import { createIJobFile } from "../../__mocks__/mockCreators/jobs"; import { AuthUtils } from "../../../src/utils/AuthUtils"; -import { SettingsConfig } from "../../../src/configuration/SettingsConfig"; const globalMocks = { testSession: createISession(), diff --git a/packages/zowe-explorer/__tests__/__unit__/tools/ZoweTerminal.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/tools/ZoweTerminal.unit.test.ts index f853b37df..67d5fc6a3 100644 --- a/packages/zowe-explorer/__tests__/__unit__/tools/ZoweTerminal.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/tools/ZoweTerminal.unit.test.ts @@ -32,9 +32,10 @@ describe("ZoweTerminal Unit Tests", () => { iTerm.handleInput("002"); iTerm.handleInput(ZoweTerminal.Keys.ENTER); expect(spyCb).toHaveBeenCalledWith("old002"); - // expect((iTerm as any).mHistory as string[]).toContain("old002"); + // expect((iTerm as any).mHistory as string[]).toContain("test002"); spyCb.mockClear(); + iTerm.handleInput(ZoweTerminal.Keys.UP); iTerm.handleInput(ZoweTerminal.Keys.UP); iTerm.handleInput(ZoweTerminal.Keys.DOWN); iTerm.handleInput(ZoweTerminal.Keys.LEFT); @@ -43,10 +44,18 @@ describe("ZoweTerminal Unit Tests", () => { iTerm.handleInput(ZoweTerminal.Keys.RIGHT); iTerm.handleInput(ZoweTerminal.Keys.BACKSPACE); iTerm.handleInput("11"); + iTerm.handleInput(ZoweTerminal.Keys.BACKSPACE); iTerm.handleInput(ZoweTerminal.Keys.ENTER); - expect(spyCb).toHaveBeenCalledWith("11"); + expect(spyCb).toHaveBeenCalledWith("1"); + // expect(spyCb).toHaveBeenCalledWith("test12"); spyCb.mockClear(); + (iTerm as any).command = ""; + iTerm.handleInput(ZoweTerminal.Keys.ENTER); iTerm.handleInput(ZoweTerminal.Keys.CTRL_C); + iTerm.handleInput(":clear"); + iTerm.handleInput(ZoweTerminal.Keys.ENTER); + iTerm.handleInput(":exit"); + iTerm.handleInput(ZoweTerminal.Keys.ENTER); }); }); diff --git a/packages/zowe-explorer/src/tools/ZoweTerminal.ts b/packages/zowe-explorer/src/tools/ZoweTerminal.ts index 4703ea2d1..8f7921782 100644 --- a/packages/zowe-explorer/src/tools/ZoweTerminal.ts +++ b/packages/zowe-explorer/src/tools/ZoweTerminal.ts @@ -153,7 +153,7 @@ export class ZoweTerminal implements vscode.Pseudoterminal { if (cmd === ":clear") { this.clear(); } else if (cmd === ":exit") { - this.closeEmitter.fire(); + this.close(); } } else { const output = await this.processCmd(cmd);