-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a notification after auto-installing a new version of Lexic…
…al (#81)
- Loading branch information
1 parent
bfb2071
commit 9d401b9
Showing
10 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { window } from "vscode"; | ||
import ReleaseVersion from "./release/version"; | ||
import Configuration from "./configuration"; | ||
|
||
namespace Notifications { | ||
export function notifyAutoInstallSuccess(version: ReleaseVersion.T): void { | ||
const disableNotificationMessage = "Disable this notification"; | ||
const serializedVersion = ReleaseVersion.serialize(version); | ||
const releaseUrl = `https://github.com/lexical-lsp/lexical/releases/tag/v${serializedVersion}`; | ||
const message = `Lexical was automatically updated to version ${serializedVersion}. See [what's new](${releaseUrl}).`; | ||
|
||
window | ||
.showInformationMessage(message, disableNotificationMessage) | ||
.then((fulfilledValue) => { | ||
if (fulfilledValue === disableNotificationMessage) { | ||
Configuration.disableAutoInstallUpdateNotification(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default Notifications; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { mockReturnValue } from "./utils/strict-mocks"; | ||
import { MessageItem, window } from "vscode"; | ||
import { SynchronousPromise } from "synchronous-promise"; | ||
import Notifications from "../notifications"; | ||
import ReleaseVersion from "../release/version"; | ||
import Configuration from "../configuration"; | ||
|
||
describe("notifyAutoInstallSuccess", () => { | ||
test("sends an information message with the installed version", () => { | ||
mockReturnValue( | ||
window, | ||
"showInformationMessage", | ||
Promise.resolve(undefined), | ||
); | ||
|
||
Notifications.notifyAutoInstallSuccess(ReleaseVersion.deserialize("1.2.3")); | ||
|
||
expect(window.showInformationMessage).toHaveBeenCalledWith( | ||
expect.stringContaining("version 1.2.3"), | ||
"Disable this notification", | ||
); | ||
}); | ||
|
||
test("when user requests to disable the notification, it updates the configuration", () => { | ||
mockReturnValue(Configuration, "disableAutoInstallUpdateNotification"); | ||
mockReturnValue( | ||
window, | ||
"showInformationMessage", | ||
SynchronousPromise.resolve( | ||
"Disable this notification" as unknown as MessageItem, | ||
), | ||
); | ||
|
||
Notifications.notifyAutoInstallSuccess(ReleaseVersion.deserialize("1.2.3")); | ||
|
||
expect( | ||
Configuration.disableAutoInstallUpdateNotification, | ||
).toHaveBeenCalled(); | ||
}); | ||
|
||
test("notification should include a link to the release notes", () => { | ||
mockReturnValue( | ||
window, | ||
"showInformationMessage", | ||
Promise.resolve(undefined), | ||
); | ||
|
||
Notifications.notifyAutoInstallSuccess(ReleaseVersion.deserialize("1.2.3")); | ||
|
||
expect(window.showInformationMessage).toHaveBeenCalledWith( | ||
expect.stringContaining( | ||
"https://github.com/lexical-lsp/lexical/releases/tag/v1.2.3", | ||
), | ||
"Disable this notification", | ||
); | ||
}); | ||
}); |