Skip to content

Commit d1dd93e

Browse files
committed
Refactor project setup and add project view visibility check
Updated project setup to use user home directory for temporary files. Introduced a utility method to verify if the project view is visible, improving reliability. Adjusted error handling to ensure tests proceed even when some UI elements are missing.
1 parent 5f241a4 commit d1dd93e

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

src/test/kotlin/com/magento/idea/magento2plugin/actions/content/MarkDirectoryAsMagentoRootTest.kt

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
package com.magento.idea.magento2plugin.actions.content
77

88
import com.automation.remarks.junit5.Video
9+
import com.intellij.openapi.util.io.NioFiles.createDirectories
910
import org.assertj.swing.core.MouseButton
1011
import com.intellij.remoterobot.RemoteRobot
11-
import com.intellij.remoterobot.fixtures.ComponentFixture
1212
import com.intellij.remoterobot.fixtures.ContainerFixture
13-
import com.intellij.remoterobot.fixtures.Fixture
14-
import com.intellij.remoterobot.fixtures.JButtonFixture
1513
import com.intellij.remoterobot.search.locators.byXpath
1614
import com.intellij.remoterobot.steps.CommonSteps
1715
import com.intellij.remoterobot.stepsProcessing.step
18-
import com.intellij.remoterobot.utils.Keyboard
1916
import com.intellij.remoterobot.utils.keyboard
2017
import com.intellij.remoterobot.utils.waitFor
2118
import com.intellij.remoterobot.utils.waitForIgnoringError
22-
import com.intellij.ui.components.dialog
2319
import com.magento.idea.magento2plugin.pages.*
2420
import com.magento.idea.magento2plugin.utils.RemoteRobotExtension
2521
import com.magento.idea.magento2plugin.utils.StepsLogger
@@ -30,8 +26,8 @@ import org.junit.jupiter.api.extension.ExtendWith
3026
import java.awt.event.KeyEvent.*
3127
import java.io.File
3228
import java.io.IOException
29+
import java.nio.file.Paths
3330
import java.time.Duration.ofMinutes
34-
import kotlin.io.path.createTempDirectory
3531

3632
@ExtendWith(RemoteRobotExtension::class)
3733
class MarkDirectoryAsMagentoRootTest {
@@ -43,9 +39,21 @@ class MarkDirectoryAsMagentoRootTest {
4339

4440
@BeforeEach
4541
fun setup() {
46-
// Create a temporary directory
42+
// Get the user's home directory in a platform-independent way
43+
val userHomeDir = System.getProperty("user.home")
44+
45+
// Create a temporary directory inside the user's home directory
46+
val tempDirPath = Paths.get(userHomeDir, "intellij-test-project")
47+
tempProjectDir = createDirectories(tempDirPath).toFile().apply {
48+
// Ensure the temporary directory is deleted and recreated
49+
if (exists()) {
50+
deleteRecursively()
51+
}
52+
mkdirs()
53+
}
54+
55+
// Define the source directory for the test data
4756
val sourceDir = File("testData/project/magento2")
48-
tempProjectDir = createTempDirectory("intellij-test-project").toFile()
4957

5058
// Copy the test data to the temporary directory
5159
sourceDir.copyRecursively(
@@ -86,8 +94,12 @@ class MarkDirectoryAsMagentoRootTest {
8694
// end temporary workaround
8795

8896
welcomeFrame {
89-
val launchedFromScript = find<ContainerFixture>(byXpath("//div[@class='LinkLabel']"))
90-
launchedFromScript.click()
97+
try {
98+
val launchedFromScript = find<ContainerFixture>(byXpath("//div[@class='LinkLabel']"))
99+
launchedFromScript.click()
100+
} catch (e: Exception) {
101+
// Element does not exist, continue without failing the test
102+
}
91103

92104
createNewProjectFromExistingFilesLink.click()
93105
dialog("Open File or Project") {
@@ -111,8 +123,10 @@ class MarkDirectoryAsMagentoRootTest {
111123
enableSupportLink.click(java.awt.Point(1, 1))
112124
waitFor(ofMinutes(1)) { isDumbMode().not() }
113125

114-
keyboard {
115-
hotKey(VK_ALT, VK_1)
126+
if (!isProjectViewVisible()) {
127+
keyboard {
128+
hotKey(VK_ALT, VK_1)
129+
}
116130
}
117131

118132
with(projectViewTree) {

src/test/kotlin/com/magento/idea/magento2plugin/pages/IdeaFrame.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) :
2323
get() = actionLink(byXpath("//div[@accessiblename='Enable Magento support for this project?' and @class='JEditorPane']"))
2424

2525
val projectViewTree
26-
get() = find<ContainerFixture>(byXpath("ProjectViewTree", "//div[@class='ProjectViewTree']"))
26+
get() = find<ContainerFixture>(byXpath("//div[@class='ProjectViewTree']"))
2727

2828
@JvmOverloads
2929
fun dumbAware(timeout: Duration = Duration.ofMinutes(5), function: () -> Unit) {
@@ -40,6 +40,18 @@ class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) :
4040
}
4141
}
4242

43+
fun isProjectViewVisible(): Boolean {
44+
return try {
45+
with(projectViewTree) {
46+
findText("vendor")
47+
true
48+
}
49+
} catch (e: Exception) {
50+
false
51+
}
52+
}
53+
54+
4355
fun isDumbMode(): Boolean {
4456
return callJs(
4557
"""

0 commit comments

Comments
 (0)