Skip to content

Commit e2bac9b

Browse files
authored
Hide notifications is plugin mentioned in the conditions is not installed (#5225)
1 parent 5abfb19 commit e2bac9b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/RulesEngine.kt

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ object RulesEngine {
5656
if (notificationExtension.isNullOrEmpty()) return true
5757
val extensionsToBeChecked = notificationExtension.map { it.id }
5858
val pluginVersions = actualPluginVersions.filterKeys { extensionsToBeChecked.contains(it) }
59+
if (pluginVersions.isEmpty()) return false
5960
return notificationExtension.all { extension ->
6061
val actualVersion = pluginVersions[extension.id]
6162
if (actualVersion == null) {

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/notifications/NotificationFormatUtilsTest.kt

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class NotificationFormatUtilsTest {
3636
val projectRule = ProjectRule()
3737

3838
private lateinit var mockSystemDetails: SystemDetails
39+
private lateinit var mockSystemDetailsWithNoPlugin: SystemDetails
3940
private lateinit var exampleNotification: InputStream
4041

4142
@BeforeEach
@@ -53,6 +54,18 @@ class NotificationFormatUtilsTest {
5354
)
5455
)
5556

57+
mockSystemDetailsWithNoPlugin = SystemDetails(
58+
computeType = "Local",
59+
computeArchitecture = "x86_64",
60+
osType = "Linux",
61+
osVersion = "5.4.0",
62+
ideType = "IC",
63+
ideVersion = "2023.1",
64+
pluginVersions = mapOf(
65+
"aws.toolkit" to "1.0",
66+
)
67+
)
68+
5669
exampleNotification = javaClass.getResource("/exampleNotification2.json")?.let {
5770
Paths.get(it.toURI()).takeIf { f -> f.exists() }
5871
}?.inputStream() ?: throw RuntimeException("Test not found")
@@ -98,6 +111,13 @@ class NotificationFormatUtilsTest {
98111
}
99112
}
100113

114+
@Test
115+
fun `If plugin is not present, notification is not shown`() {
116+
every { getCurrentSystemAndConnectionDetails() } returns mockSystemDetailsWithNoPlugin
117+
val shouldShow = RulesEngine.displayNotification(projectRule.project, pluginNotPresentData)
118+
assertThat(shouldShow).isFalse
119+
}
120+
101121
@ParameterizedTest
102122
@MethodSource("validNotifications")
103123
fun `The notification is shown`(notification: String, expectedData: NotificationData) {

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/notifications/NotificationFormatUtilsTestCases.kt

+26
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,29 @@ val invalidIdeTypeAndVersionData = NotificationData(
360360
)
361361
)
362362
)
363+
364+
val pluginNotPresentData = NotificationData(
365+
id = "example_id_12344",
366+
schedule = NotificationSchedule(type = "StartUp"),
367+
severity = "Critical",
368+
condition = NotificationDisplayCondition(
369+
compute = null,
370+
os = null,
371+
ide = null,
372+
extension = mutableListOf(
373+
ExtensionType(
374+
"amazon.q",
375+
version = NotificationExpression.NotEqualsCondition("1.3334")
376+
)
377+
),
378+
authx = null
379+
380+
),
381+
actions = emptyList(),
382+
content = NotificationContentDescriptionLocale(
383+
NotificationContentDescription(
384+
title = "Look at this!",
385+
description = "Some bug is there"
386+
)
387+
)
388+
)

0 commit comments

Comments
 (0)