diff --git a/src/prompt.spec.ts b/src/prompt.spec.ts index f88ba7f6dd7..3f662324a8c 100644 --- a/src/prompt.spec.ts +++ b/src/prompt.spec.ts @@ -50,6 +50,167 @@ describe("prompt", () => { }); expect(result).to.be.true; }); + + it("handles non-interactive with default", async () => { + const result = await prompt.confirm({ + message: "Continue?", + nonInteractive: true, + default: false, + }); + expect(result).to.be.false; + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.confirm({ + message: "Continue?", + nonInteractive: true, + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Continue?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("input", () => { + it("handles non-interactive with default", async () => { + const result = await prompt.input({ + message: "Name?", + nonInteractive: true, + default: "Inigo Montoya", + }); + expect(result).to.equal("Inigo Montoya"); + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.input({ + message: "Name?", + nonInteractive: true, + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Name?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("checkbox", () => { + it("handles non-interactive with default", async () => { + const result = await prompt.checkbox({ + message: "Tools?", + nonInteractive: true, + choices: ["hammer", "wrench", "saw"], + default: ["hammer", "wrench"], + }); + expect(result).to.deep.equal(["hammer", "wrench"]); + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.checkbox({ + message: "Tools?", + nonInteractive: true, + choices: ["hammer", "wrench", "saw"], + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Tools?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("select", () => { + it("handles non-interactive with default", async () => { + const result = await prompt.select({ + message: "Tool?", + nonInteractive: true, + choices: ["hammer", "wrench", "saw"], + default: "wrench", + }); + expect(result).to.equal("wrench"); + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.select({ + message: "Tool?", + nonInteractive: true, + choices: ["hammer", "wrench", "saw"], + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Tool?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("number", () => { + it("handles non-interactive with default", async () => { + const result = await prompt.number({ + message: "Count?", + nonInteractive: true, + default: 42, + }); + expect(result).to.equal(42); + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.number({ + message: "Count?", + nonInteractive: true, + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Count?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("password", () => { + it("throws in non-interactive", async () => { + await expect( + prompt.password({ + message: "Password?", + nonInteractive: true, + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Password?" does not have a default and cannot be answered in non-interactive mode', + ); + }); + }); + + describe("search", () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const source = (term: string | undefined) => { + return ["a", "b", "c"]; + }; + + it("handles non-interactive with default", async () => { + const result = await prompt.search({ + message: "Letter?", + nonInteractive: true, + source, + default: "b", + }); + expect(result).to.equal("b"); + }); + + it("throws in non-interactive without default", async () => { + await expect( + prompt.search({ + message: "Letter?", + nonInteractive: true, + source, + }), + ).to.be.rejectedWith( + FirebaseError, + 'Question "Letter?" does not have a default and cannot be answered in non-interactive mode', + ); + }); }); }); });