|
| 1 | +import { env, Uri, window } from "vscode"; |
| 2 | +import type { MessageItem } from "vscode"; |
| 3 | +import { |
| 4 | + codeQlCliReleaseNotesUrl, |
| 5 | + offerCodeQlCliReleaseNotes, |
| 6 | +} from "../../../../src/codeql-cli/distribution/release-notes"; |
| 7 | + |
| 8 | +describe("offerCodeQlCliReleaseNotes", () => { |
| 9 | + const updateMessage = 'CodeQL CLI updated to version "v2.23.0".'; |
| 10 | + let showInformationMessageSpy: jest.SpiedFunction< |
| 11 | + typeof window.showInformationMessage |
| 12 | + >; |
| 13 | + let openExternalSpy: jest.SpiedFunction<typeof env.openExternal>; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + showInformationMessageSpy = jest |
| 17 | + .spyOn(window, "showInformationMessage") |
| 18 | + .mockResolvedValue(undefined); |
| 19 | + openExternalSpy = jest.spyOn(env, "openExternal").mockResolvedValue(true); |
| 20 | + }); |
| 21 | + |
| 22 | + it("opens the CLI changelog when the release-notes action is selected", async () => { |
| 23 | + showInformationMessageSpy.mockImplementationOnce((...args) => |
| 24 | + Promise.resolve(args[1] as MessageItem), |
| 25 | + ); |
| 26 | + |
| 27 | + await offerCodeQlCliReleaseNotes(updateMessage); |
| 28 | + |
| 29 | + expect(showInformationMessageSpy).toHaveBeenCalledWith(updateMessage, { |
| 30 | + title: "Show release notes", |
| 31 | + isCloseAffordance: false, |
| 32 | + }); |
| 33 | + expect(openExternalSpy).toHaveBeenCalledWith( |
| 34 | + Uri.parse(codeQlCliReleaseNotesUrl), |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it("does not open the changelog when the message is dismissed", async () => { |
| 39 | + await offerCodeQlCliReleaseNotes(updateMessage); |
| 40 | + |
| 41 | + expect(openExternalSpy).not.toHaveBeenCalled(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments