Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0dc672a
chore: allow running GHA on this branch
himanshusinghs Oct 17, 2024
375f715
chore: comment out the flaking assertion
himanshusinghs Oct 17, 2024
17daadf
chore: use invokeLater for better concurrency control
himanshusinghs Oct 17, 2024
61fc8b9
chore: re-enable other test for testing
himanshusinghs Oct 17, 2024
3879ff1
chore: make dependent actions recoverable
himanshusinghs Oct 17, 2024
7d2ddd1
chore: decrease the recovery timeout for actions
himanshusinghs Oct 17, 2024
89663e2
chore: decrease the recovery timeout for actions, enable other UI tests
himanshusinghs Oct 17, 2024
f767818
chore: enable more UI tests
himanshusinghs Oct 17, 2024
fe49142
chore: enable more UI tests
himanshusinghs Oct 17, 2024
1f440aa
chore: fixing assertion
himanshusinghs Oct 17, 2024
503884e
chore: enable rest of the UI tests
himanshusinghs Oct 17, 2024
ff4d1a2
chore: use invokeLater for better concurrency control on DatabaseComb…
himanshusinghs Oct 18, 2024
d57b5be
chore: add step logging for more debug info
himanshusinghs Oct 18, 2024
1b3fe21
chore: revert quality-check.yaml changes
himanshusinghs Oct 18, 2024
3e46a70
chore: remove test deps from fixture project
himanshusinghs Oct 18, 2024
7b62fb4
chore: version ref via versions toml
himanshusinghs Oct 18, 2024
d3db96b
chore: added custom step logger to log exceptions as well
himanshusinghs Oct 18, 2024
b4e9e5c
chore: ignore gradle sync exception logging
himanshusinghs Oct 18, 2024
5ec05e4
chore: also ignore Search 'Idea frame'
himanshusinghs Oct 18, 2024
12d1625
chore: also ignore Search 'AI' related exception
himanshusinghs Oct 18, 2024
c14e452
chore: better ignore
himanshusinghs Oct 18, 2024
1d2f60d
chore: a few more ignores
himanshusinghs Oct 18, 2024
fd54190
chore: adds way for manual gradle reload
himanshusinghs Oct 22, 2024
b249764
chore: wait a little more for gradle projects to show up
himanshusinghs Oct 22, 2024
d1b0893
chore: minor adjustments
himanshusinghs Oct 22, 2024
2c413a5
chore: use invokeAction for gradle sync
himanshusinghs Oct 22, 2024
a80096a
chore: wait for smartmode:
himanshusinghs Oct 22, 2024
8f5e22b
chore: ensure screenshots are attached in reports
himanshusinghs Oct 22, 2024
e0e1369
chore: include smartmode check
himanshusinghs Oct 22, 2024
f79581b
chore: perform pre and post smart mode check
himanshusinghs Oct 22, 2024
32d0b8c
chore: move selector matching on RemoteRobot
himanshusinghs Oct 22, 2024
0345316
chore: catch clean data sources error
himanshusinghs Oct 22, 2024
207180f
chore: remove data sources from UI instead of write unsafe context call
himanshusinghs Oct 22, 2024
9fe8b08
chore: address PR feedback and remove debug steps
himanshusinghs Oct 23, 2024
29a7f9c
chore: use invokeLater with correct modality state
himanshusinghs Oct 23, 2024
9f3c7b6
chore: address PR feedback and add safety net for left over data sources
himanshusinghs Oct 23, 2024
df5c222
chore: remove dead code
himanshusinghs Oct 23, 2024
faec2d5
chore: specify the current modality state
himanshusinghs Oct 23, 2024
46bcc56
chore: catch Write unsafe errors and ignore
himanshusinghs Oct 23, 2024
a0df2e2
chore: bring back old clean data source with catch for write-unsafe-e…
himanshusinghs Oct 23, 2024
25220c5
chore: bring back maybeTerminateButton call
himanshusinghs Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/quality-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
path: |
**/build/reports/**/*.html
**/build/reports/**/*.log
**/build/reports/*/*.png
**/build/reports/**/*.png
**/build/idea-sandbox/system/**/*.log
**/build/idea-sandbox/system-test/**/*.log
**/video/**/*.avi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.mongodb.jbplugin.editor.inputs

import com.intellij.database.dataSource.LocalDataSource
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.asSequence
import com.intellij.sql.indexOf
import com.intellij.ui.AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED
import com.intellij.ui.components.JBLabel
import com.mongodb.jbplugin.accessadapter.datagrip.adapter.isConnected
import com.mongodb.jbplugin.editor.models.ToolbarState
import com.mongodb.jbplugin.editor.models.getToolbarModel
import com.mongodb.jbplugin.i18n.Icons
import com.mongodb.jbplugin.i18n.Icons.scaledToText
Expand Down Expand Up @@ -98,15 +101,10 @@ class DataSourceComboBox(
var isFirstInit = true
coroutineScope.launch {
project.getToolbarModel().toolbarState.collect { state ->
withoutSelectionChangedListener {
selectedDataSourceConnecting = state.selectedDataSourceConnecting
selectedDataSourceFailedConnecting = state.selectedDataSourceConnectionFailed
if (isFirstInit || state.dataSources != dataSources) {
isFirstInit = false
populateComboBoxWithDataSources(state.dataSources)
}
selectDataSourceByUniqueId(state.selectedDataSource?.uniqueId)
}
ApplicationManager.getApplication().invokeLater({
updateComboBoxState(state, isFirstInit)
isFirstInit = false
}, ModalityState.stateForComponent(comboBoxComponent))
}
}
}
Expand All @@ -120,11 +118,28 @@ class DataSourceComboBox(
}
}

private fun populateComboBoxWithDataSources(dataSources: List<LocalDataSource>) {
comboBoxModel.removeAllElements()
// First item is purposely a null to render "Detach data source label"
comboBoxModel.addElement(null)
comboBoxModel.addAll(dataSources)
private fun updateComboBoxState(state: ToolbarState, isFirstInit: Boolean) = withoutSelectionChangedListener {
selectedDataSourceConnecting = state.selectedDataSourceConnecting
selectedDataSourceFailedConnecting = state.selectedDataSourceConnectionFailed
if (isFirstInit || state.dataSources != dataSources) {
populateComboBoxWithDataSources(state.dataSources.toSet())
}
selectDataSourceByUniqueId(state.selectedDataSource?.uniqueId)
}

private fun populateComboBoxWithDataSources(newDataSources: Set<LocalDataSource>) {
val oldDataSources = dataSources.toSet()

val dataSourcesToAdd = newDataSources - oldDataSources
val dataSourcesToRemove = oldDataSources - newDataSources

dataSourcesToAdd.forEach { comboBoxModel.addElement(it) }
dataSourcesToRemove.forEach { comboBoxModel.removeElement(it) }

if (comboBoxModel.getIndexOf(null) != 0) {
comboBoxModel.removeElement(null)
comboBoxModel.insertElementAt(null, 0)
}
}

private fun selectDataSourceByUniqueId(uniqueId: String?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.mongodb.jbplugin.editor.inputs

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.asSequence
import com.intellij.ui.AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED
import com.intellij.ui.components.JBLabel
import com.mongodb.jbplugin.editor.models.ToolbarState
import com.mongodb.jbplugin.editor.models.getToolbarModel
import com.mongodb.jbplugin.i18n.Icons
import com.mongodb.jbplugin.i18n.Icons.scaledToText
Expand Down Expand Up @@ -78,14 +81,10 @@ class DatabaseComboBox(
var isFirstInit = true
coroutineScope.launch {
project.getToolbarModel().toolbarState.collect { state ->
withoutSelectionChangedListener {
loadingDatabases = state.databasesLoadingForSelectedDataSource
if (isFirstInit || state.databases != databases) {
isFirstInit = false
populateComboBoxWithDatabases(state.databases)
}
selectDatabaseAndNotify(state.selectedDatabase)
}
ApplicationManager.getApplication().invokeLater({
updateComboBoxState(state, isFirstInit)
isFirstInit = false
}, ModalityState.stateForComponent(comboBoxComponent))
}
}
}
Expand All @@ -99,11 +98,27 @@ class DatabaseComboBox(
}
}

private fun populateComboBoxWithDatabases(databases: List<String>) {
comboBoxModel.removeAllElements()
// First item is purposely a null to render "Detach data source label"
comboBoxModel.addElement(null)
comboBoxModel.addAll(databases)
private fun updateComboBoxState(state: ToolbarState, isFirstInit: Boolean) = withoutSelectionChangedListener {
loadingDatabases = state.databasesLoadingForSelectedDataSource
if (isFirstInit || state.databases != databases) {
populateComboBoxWithDatabases(state.databases.toSet())
}
selectDatabaseAndNotify(state.selectedDatabase)
}

private fun populateComboBoxWithDatabases(newDatabases: Set<String>) {
val oldDatabases = databases.toSet()

val databasesToAdd = newDatabases - oldDatabases
val databasesToRemove = oldDatabases - newDatabases

databasesToAdd.forEach { comboBoxModel.addElement(it) }
databasesToRemove.forEach { comboBoxModel.removeElement(it) }

if (comboBoxModel.getIndexOf(null) != 0) {
comboBoxModel.removeElement(null)
comboBoxModel.insertElementAt(null, 0)
}
}

private fun selectDatabaseAndNotify(database: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.mongodb.jbplugin.codeActions.impl

import com.intellij.remoterobot.RemoteRobot
import com.mongodb.jbplugin.fixtures.*
import com.mongodb.jbplugin.fixtures.components.findJavaEditorToolbar
import com.mongodb.jbplugin.fixtures.components.findJavaEditorToolbarPopup
import com.mongodb.jbplugin.fixtures.components.findRunQueryGutter
import com.mongodb.jbplugin.fixtures.components.idea.ideaFrame
import com.mongodb.jbplugin.fixtures.components.openRunQueryPopup
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration

@UiTest
@RequiresMongoDbCluster
Expand All @@ -20,6 +20,7 @@ class MongoDbRunQueryActionUiTest {
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
) {
remoteRobot.ideaFrame().cleanDataSources()
remoteRobot.ideaFrame().addDataSourceWithUrl(javaClass.simpleName, url)
}

Expand All @@ -34,8 +35,7 @@ class MongoDbRunQueryActionUiTest {
remoteRobot.ideaFrame().openFile(
"/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java"
)
remoteRobot.findRunQueryGutter(atLine = 24)!!.click()
val popup = remoteRobot.findJavaEditorToolbarPopup()
val popup = remoteRobot.openRunQueryPopup(atLine = 24)
popup.cancel()
}

Expand All @@ -45,16 +45,11 @@ class MongoDbRunQueryActionUiTest {
remoteRobot.ideaFrame().openFile(
"/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java"
)
remoteRobot.findJavaEditorToolbar().detachDataSource()
remoteRobot.findRunQueryGutter(atLine = 24)!!.click()
// because we are disconnected, we should now try to connect
val popup = remoteRobot.findJavaEditorToolbarPopup()
popup.dataSources.selectItem(
javaClass.simpleName
)
val popup = remoteRobot.openRunQueryPopup(atLine = 24)
popup.selectDataSource(javaClass.simpleName)
popup.ok("Run Query", timeout = 1.minutes)
// check that we open a console
eventually {
eventually(30.seconds.toJavaDuration()) {
val currentEditor = remoteRobot.ideaFrame().currentTab()
assertTrue(currentEditor.editor.fileName.startsWith("console"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import com.mongodb.jbplugin.fixtures.components.findJavaEditorToolbar
import com.mongodb.jbplugin.fixtures.components.idea.ideaFrame
import com.mongodb.jbplugin.fixtures.components.isJavaEditorToolbarHidden
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.minutes
Expand All @@ -21,6 +20,7 @@ class JavaDriverToolbarVisibilityUiTest {
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
) {
remoteRobot.ideaFrame().cleanDataSources()
remoteRobot.ideaFrame().addDataSourceWithUrl(javaClass.simpleName, url)
}

Expand All @@ -30,7 +30,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `shows the toolbar in a java file with references to the driver`(remoteRobot: RemoteRobot) {
remoteRobot.ideaFrame().openFile(
"/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java"
Expand All @@ -40,7 +40,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `shows the toolbar in all the java files with references to the driver`(
remoteRobot: RemoteRobot
) {
Expand All @@ -63,7 +63,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `does not show the toolbar in a java file without references to the driver`(
remoteRobot: RemoteRobot
) {
Expand All @@ -74,7 +74,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `does show existing data sources in the combo box`(
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
Expand All @@ -88,7 +88,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `does not show the database select on a java driver file`(
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
Expand All @@ -102,7 +102,7 @@ class JavaDriverToolbarVisibilityUiTest {
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `does show the database select on a spring criteria file`(
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
Expand All @@ -114,34 +114,31 @@ class JavaDriverToolbarVisibilityUiTest {
val toolbar = remoteRobot.findJavaEditorToolbar()
assertTrue(toolbar.hasDatabasesComboBox)

eventually(1.minutes.toJavaDuration()) {
// when we select a cluster, it will connect asynchronously
toolbar.dataSources.selectItem(javaClass.simpleName)
}
toolbar.selectDataSource(javaClass.simpleName)

eventually(1.minutes.toJavaDuration()) {
// it can take a few seconds, we will retry every few milliseconds
// but wait at least for a minute if we can't select a database
toolbar.databases.selectItem("admin")
toolbar.selectDatabase("admin")
}
}

@Test
@RequiresProject("basic-java-project-with-mongodb")
@RequiresProject("basic-java-project-with-mongodb", smartMode = true)
fun `shows the toolbar when a reference to the driver is added`(
remoteRobot: RemoteRobot,
url: MongoDbServerUrl,
) {
assertTrue(remoteRobot.isJavaEditorToolbarHidden())

remoteRobot.ideaFrame().openFile(
"/src/main/java/alt/mongodb/javadriver/NoDriverReference.java"
)
assertTrue(remoteRobot.isJavaEditorToolbarHidden())
val editor = remoteRobot.ideaFrame().currentTab().editor
val textBeforeChanges = editor.text

editor.insertTextAtLine(1, 0, "import com.mongodb.client.MongoClient;")

remoteRobot.findJavaEditorToolbar()
editor.text = textBeforeChanges.replace("\n", "\\\n")
assertTrue(remoteRobot.findJavaEditorToolbar().isShowing)
editor.replaceText("import com.mongodb.client.MongoClient;", "")
assertTrue(remoteRobot.isJavaEditorToolbarHidden())
}
}
Loading
Loading