-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPythonRequiredStartupActivityTest.kt
More file actions
163 lines (132 loc) · 6.32 KB
/
Copy pathPythonRequiredStartupActivityTest.kt
File metadata and controls
163 lines (132 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.github.pyvenvmanage
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.unmockkObject
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.github.pyvenvmanage.settings.PyVenvManageSettings
class PythonRequiredStartupActivityTest {
private lateinit var project: Project
private lateinit var notificationGroupManager: NotificationGroupManager
private lateinit var notificationGroup: NotificationGroup
private lateinit var notification: Notification
private lateinit var settings: PyVenvManageSettings
private lateinit var pythonModuleId: PluginId
private lateinit var pythonCoreId: PluginId
@BeforeEach
fun setUp() {
project = mockk(relaxed = true)
notificationGroupManager = mockk(relaxed = true)
notificationGroup = mockk(relaxed = true)
notification = mockk(relaxed = true)
settings = mockk(relaxed = true)
pythonModuleId = PluginId.getId("com.intellij.modules.python")
pythonCoreId = PluginId.getId("PythonCore")
mockkStatic(NotificationGroupManager::class)
mockkStatic(PluginManager::class)
mockkStatic(PluginManagerCore::class)
mockkObject(PyVenvManageSettings)
every { NotificationGroupManager.getInstance() } returns notificationGroupManager
every { notificationGroupManager.getNotificationGroup("PyVenv Manage") } returns notificationGroup
every {
notificationGroup.createNotification(any<String>(), any<String>(), any<NotificationType>())
} returns notification
every { notification.addAction(any<NotificationAction>()) } returns notification
every { PyVenvManageSettings.getInstance() } returns settings
every { settings.dismissedPythonWarning } returns false
}
@AfterEach
fun tearDown() {
unmockkStatic(NotificationGroupManager::class)
unmockkStatic(PluginManager::class)
unmockkStatic(PluginManagerCore::class)
unmockkObject(PyVenvManageSettings)
}
@Test
fun `does not show notification when python module is available`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns true
every { PluginManagerCore.isDisabled(pythonModuleId) } returns false
PythonRequiredStartupActivity().execute(project)
verify(exactly = 0) { notification.notify(any()) }
}
@Test
fun `does not show notification when PythonCore plugin is available`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns true
every { PluginManagerCore.isDisabled(pythonCoreId) } returns false
PythonRequiredStartupActivity().execute(project)
verify(exactly = 0) { notification.notify(any()) }
}
@Test
fun `shows warning notification when python is not available`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
PythonRequiredStartupActivity().execute(project)
verify {
notificationGroup.createNotification(
"PyVenv Manage requires Python support",
"Please install the Python plugin or use PyCharm for full functionality.",
NotificationType.WARNING,
)
}
verify { notification.notify(project) }
}
@Test
fun `shows warning when python plugin exists but is disabled`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns true
every { PluginManagerCore.isDisabled(pythonModuleId) } returns true
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
PythonRequiredStartupActivity().execute(project)
verify { notification.notify(project) }
}
@Test
fun `does not show notification when warning was dismissed`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
every { settings.dismissedPythonWarning } returns true
PythonRequiredStartupActivity().execute(project)
verify(exactly = 0) { notification.notify(any()) }
}
@Test
fun `notification includes dont show again action`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
PythonRequiredStartupActivity().execute(project)
verify { notification.addAction(any<NotificationAction>()) }
}
@Test
fun `dont show again action sets dismissed flag and expires notification`(): Unit =
runBlocking {
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
val actionSlot = slot<NotificationAction>()
every { notification.addAction(capture(actionSlot)) } returns notification
PythonRequiredStartupActivity().execute(project)
val event: com.intellij.openapi.actionSystem.AnActionEvent = mockk(relaxed = true)
actionSlot.captured.actionPerformed(event, notification)
verify { settings.dismissedPythonWarning = true }
verify { notification.expire() }
}
}