-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add UI test to toggle telemetry
- Loading branch information
Showing
6 changed files
with
207 additions
and
44 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
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
72 changes: 72 additions & 0 deletions
72
...plugin/src/test/kotlin/com/mongodb/jbplugin/fixtures/components/MongoDbSettingsFixture.kt
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,72 @@ | ||
/** | ||
* Fixture that represents the plugin settings page. If you add new settings, | ||
* you should add new properties here. | ||
* | ||
* For usage in tests that work with settings, you can use openSettings, that will open the UI, or | ||
* remoteRobot.useSetting(name), that will give you the value for that specific setting. | ||
*/ | ||
|
||
package com.mongodb.jbplugin.fixtures.components | ||
|
||
import com.intellij.remoterobot.RemoteRobot | ||
import com.intellij.remoterobot.data.RemoteComponent | ||
import com.intellij.remoterobot.fixtures.* | ||
import com.mongodb.jbplugin.fixtures.findVisible | ||
|
||
/** | ||
* Component that represents the settings page. | ||
* | ||
* @param remoteRobot | ||
* @param remoteComponent | ||
*/ | ||
@DefaultXpath(by = "accessible name", xpath = "//div[@accessiblename='MongoDB Settings']") | ||
@FixtureName("MongoDBSettings") | ||
class MongoDbSettingsFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ContainerFixture(remoteRobot, | ||
remoteComponent) { | ||
val enableTelemetry by lazy { | ||
findAll<JCheckboxFixture>().find { it.text == "Enable telemetry" } ?: throw NoSuchElementException() | ||
} | ||
val ok by lazy { | ||
remoteRobot.findAll<JButtonFixture>().find { it.text == "OK" } ?: throw NoSuchElementException() | ||
} | ||
} | ||
|
||
/** | ||
* Opens the settings dialog and returns a fixture, so it can be interacted. | ||
* | ||
* @return | ||
*/ | ||
fun RemoteRobot.openSettings(): MongoDbSettingsFixture { | ||
this.runJs( | ||
""" | ||
importClass(com.intellij.openapi.application.ApplicationManager) | ||
const runAction = new Runnable({ | ||
run: function() { | ||
com.intellij.openapi.options.ShowSettingsUtil.getInstance().showSettingsDialog( | ||
null, | ||
"MongoDB", | ||
) | ||
} | ||
}) | ||
ApplicationManager.getApplication().invokeLater(runAction) | ||
""".trimIndent(), | ||
) | ||
|
||
return findVisible() | ||
} | ||
|
||
/** | ||
* Returns a specific setting value from the plugin settings. | ||
* | ||
* @see com.mongodb.jbplugin.settings.PluginSettings for the possible values. | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
inline fun <reified T> RemoteRobot.useSetting(name: String): T = callJs( | ||
""" | ||
global.get('loadPluginService')( | ||
'com.mongodb.jbplugin.settings.PluginSettingsStateComponent' | ||
).getState().$name() | ||
""".trimIndent(), | ||
) |
25 changes: 25 additions & 0 deletions
25
packages/jetbrains-plugin/src/test/kotlin/com/mongodb/jbplugin/settings/SettingsUiTest.kt
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,25 @@ | ||
package com.mongodb.jbplugin.settings | ||
|
||
import com.intellij.remoterobot.RemoteRobot | ||
import com.mongodb.jbplugin.fixtures.RequiresProject | ||
import com.mongodb.jbplugin.fixtures.UiTest | ||
import com.mongodb.jbplugin.fixtures.components.openSettings | ||
import com.mongodb.jbplugin.fixtures.components.useSetting | ||
import org.junit.jupiter.api.Assertions.assertNotEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
@UiTest | ||
class SettingsUiTest { | ||
@Test | ||
@RequiresProject("basic-java-project-with-mongodb") | ||
fun `allows toggling the telemetry`(remoteRobot: RemoteRobot) { | ||
val telemetryBeforeTest = remoteRobot.useSetting<Boolean>("isTelemetryEnabled") | ||
|
||
val settings = remoteRobot.openSettings() | ||
settings.enableTelemetry.click() | ||
settings.ok.click() | ||
|
||
val telemetryAfterTest = remoteRobot.useSetting<Boolean>("isTelemetryEnabled") | ||
assertNotEquals(telemetryBeforeTest, telemetryAfterTest) | ||
} | ||
} |