-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for the pinned files feature
- Loading branch information
Showing
8 changed files
with
251 additions
and
55 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
114 changes: 114 additions & 0 deletions
114
plugin-core/src/test/java/appland/actions/AddNavieContextFilesActionTest.java
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,114 @@ | ||
package appland.actions; | ||
|
||
import appland.AppMapBaseTest; | ||
import appland.cli.TestAppLandDownloadService; | ||
import appland.utils.DataContexts; | ||
import appland.webviews.navie.NavieEditor; | ||
import appland.webviews.navie.NavieEditorProvider; | ||
import com.intellij.openapi.actionSystem.*; | ||
import com.intellij.openapi.actionSystem.ex.ActionUtil; | ||
import com.intellij.openapi.fileEditor.FileEditorManager; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.testFramework.EdtTestUtil; | ||
import com.intellij.testFramework.TestActionEvent; | ||
import com.intellij.testFramework.fixtures.TempDirTestFixture; | ||
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class AddNavieContextFilesActionTest extends AppMapBaseTest { | ||
@Override | ||
protected TempDirTestFixture createTempDirTestFixture() { | ||
return new TempDirTestFixtureImpl(); | ||
} | ||
|
||
@Before | ||
public void ensureToolsDownloaded() { | ||
TestAppLandDownloadService.ensureDownloaded(); | ||
} | ||
|
||
@Test | ||
public void enabledForNavieEditorAndContextFile() throws Exception { | ||
// must be created first because the Navie editor must be the selected editor | ||
var contextFile = myFixture.configureByText("test.txt", ""); | ||
|
||
var tempDir = myFixture.createFile("test.txt", "").getParent(); | ||
withContentRoot(tempDir, () -> { | ||
openNavieEditor(tempDir); | ||
|
||
var presentation = updateAction(createActionContext(contextFile.getVirtualFile())); | ||
Assert.assertTrue("Action must be enabled for a file", presentation.isEnabledAndVisible()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void disabledWithoutNavieEditor() throws Exception { | ||
var contextFile = myFixture.configureByText("test.txt", ""); | ||
|
||
var tempDir = myFixture.createFile("test.txt", "").getParent(); | ||
withContentRoot(tempDir, () -> { | ||
var presentation = updateAction(createActionContext(contextFile.getVirtualFile())); | ||
Assert.assertFalse("Action must be unavailable without selected Navie editor", presentation.isEnabledAndVisible()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void disabledWithoutContextFile() throws Exception { | ||
var contextDir = myFixture.configureByText("test.txt", "").getVirtualFile().getParent(); | ||
|
||
var tempDir = myFixture.createFile("test.txt", "").getParent(); | ||
withContentRoot(tempDir, () -> { | ||
openNavieEditor(tempDir); | ||
|
||
var presentation = updateAction(createActionContext(contextDir)); | ||
Assert.assertFalse("Action must be unavailable for a selected directory", presentation.isEnabledAndVisible()); | ||
}); | ||
} | ||
|
||
private void openNavieEditor(@NotNull VirtualFile tempDir) throws Exception { | ||
createAppMapConfig(tempDir, Path.of("tmp", "appmap")); | ||
waitForJsonRpcServerPort(); | ||
|
||
edt(() -> NavieEditorProvider.openEditor(getProject(), DataContext.EMPTY_CONTEXT)); | ||
|
||
// wait until the Navie editor is the selected editor | ||
var deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30); | ||
while (System.currentTimeMillis() <= deadline) { | ||
var editor = EdtTestUtil.runInEdtAndGet(() -> FileEditorManager.getInstance(getProject()).getSelectedEditor()); | ||
if (editor instanceof NavieEditor) { | ||
break; | ||
} | ||
Thread.sleep(500); | ||
} | ||
|
||
var editor = EdtTestUtil.runInEdtAndGet(() -> FileEditorManager.getInstance(getProject()).getSelectedEditor()); | ||
assertTrue("Navie editor must be open", editor instanceof NavieEditor); | ||
} | ||
|
||
private @NotNull DataContext createActionContext(@Nullable VirtualFile contextFile) { | ||
return DataContexts.createCustomContext(dataId -> { | ||
if (contextFile != null && PlatformDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) { | ||
return new VirtualFile[]{contextFile}; | ||
} | ||
if (PlatformDataKeys.PROJECT.is(dataId)) { | ||
return myFixture.getProject(); | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
private static @NotNull Presentation updateAction(@NotNull DataContext context) { | ||
var action = ActionManager.getInstance().getAction("appmap.navie.pinContextFile"); | ||
assertNotNull(action); | ||
|
||
var e = TestActionEvent.createFromAnAction(action, null, ActionPlaces.MAIN_MENU, context); | ||
ActionUtil.performDumbAwareUpdate(action, e, false); | ||
return e.getPresentation(); | ||
} | ||
} |
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
Oops, something went wrong.