mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 17:03:12 +07:00
Add unit test for Switcher (Recent Files popup), cases with tab placement 'TOP' and 'NONE'
GitOrigin-RevId: 37d093752e9544b4437faf8d3725516f71547f30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
992f8bb6f3
commit
08a0ed3d00
@@ -692,13 +692,13 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<VirtualFile> collectFiles(@NotNull Project project, boolean onlyEdited) {
|
||||
static List<VirtualFile> collectFiles(@NotNull Project project, boolean onlyEdited) {
|
||||
return onlyEdited ? Arrays.asList(IdeDocumentHistory.getInstance(project).getChangedFiles())
|
||||
: getRecentFiles(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Pair<List<FileInfo>, Integer> getFilesToShowAndSelectionIndex(@NotNull Project project,
|
||||
static Pair<List<FileInfo>, Integer> getFilesToShowAndSelectionIndex(@NotNull Project project,
|
||||
@NotNull List<VirtualFile> filesForInit,
|
||||
int toolWindowsCount,
|
||||
boolean pinned) {
|
||||
@@ -1360,7 +1360,7 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private static class FileInfo extends Pair<VirtualFile, EditorWindow> {
|
||||
static class FileInfo extends Pair<VirtualFile, EditorWindow> {
|
||||
private final Project myProject;
|
||||
private String myNameForRendering;
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.testFramework.FileEditorManagerTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
public class SwitcherTest extends FileEditorManagerTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getPlatformTestDataPath() + "fileEditorManager";
|
||||
}
|
||||
|
||||
public void testSwitcherPanelWithTabs() {
|
||||
testTabPlacement(SwingConstants.TOP);
|
||||
}
|
||||
|
||||
public void testSwitcherPanelWithoutTabs() {
|
||||
testTabPlacement(UISettings.TABS_NONE);
|
||||
}
|
||||
|
||||
private void testTabPlacement(int tabPlacement) {
|
||||
UISettings.getInstance().getState().setEditorTabPlacement(tabPlacement);
|
||||
myManager.openFile(getFile("/src/1.txt"), true);
|
||||
myManager.openFile(getFile("/src/2.txt"), true);
|
||||
myManager.openFile(getFile("/src/3.txt"), true);
|
||||
Pair<List<Switcher.FileInfo>, Integer> filesToShowAndSelectionIndex =
|
||||
Switcher.SwitcherPanel
|
||||
.getFilesToShowAndSelectionIndex(getProject(), Switcher.SwitcherPanel.collectFiles(getProject(), false), 10, true);
|
||||
|
||||
if (tabPlacement == UISettings.TABS_NONE) {
|
||||
assertEquals(1, filesToShowAndSelectionIndex.second.intValue());
|
||||
assertEquals(3, filesToShowAndSelectionIndex.first.size());
|
||||
assertEquals(getFile("/src/3.txt"), filesToShowAndSelectionIndex.first.get(0).first);
|
||||
assertEquals(getFile("/src/2.txt"), filesToShowAndSelectionIndex.first.get(1).first);
|
||||
assertEquals(getFile("/src/1.txt"), filesToShowAndSelectionIndex.first.get(2).first);
|
||||
} else {
|
||||
assertEquals(0, filesToShowAndSelectionIndex.second.intValue());
|
||||
assertEquals(2, filesToShowAndSelectionIndex.first.size());
|
||||
assertEquals(getFile("/src/2.txt"), filesToShowAndSelectionIndex.first.get(0).first);
|
||||
assertEquals(getFile("/src/1.txt"), filesToShowAndSelectionIndex.first.get(1).first);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user