use of org.eclipse.n4js.ui.navigator.internal.ShowHiddenWorkingSetsDropDownAction in project n4js by eclipse.
the class GHOLD_101_WorkingSetsTest_PluginUITest method testHideShowWorkingSets.
/**
*/
@Test
public void testHideShowWorkingSets() {
activateWorkingSetManager(ProjectTypeAwareWorkingSetManager.class);
TreeItem[] treeItems = commonViewer.getTree().getItems();
final int expectedItemCount = ProjectType.values().length + 1;
assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
List<ProjectTypeWorkingSet> workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
assertEquals("Mismatching number of working sets.", expectedItemCount, workingSets.size());
List<ProjectTypeWorkingSet> workingSetsToHide = workingSets;
final HideWorkingSetAction hideAction = new HideWorkingSetAction();
commonViewer.setSelection(new StructuredSelection(workingSets.toArray()));
waitForIdleState();
treeItems = commonViewer.getTree().getItems();
final List<ProjectTypeWorkingSet> selectedWorkingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
assertEquals(workingSetsToHide, selectedWorkingSets);
hideAction.selectionChanged(commonViewer.getStructuredSelection());
waitForIdleState();
assertFalse("Expected disabled action.", hideAction.isEnabled());
workingSetsToHide = newArrayList(workingSets.subList(0, 3));
commonViewer.setSelection(new StructuredSelection(workingSetsToHide.toArray()));
hideAction.selectionChanged(commonViewer.getStructuredSelection());
waitForIdleState();
assertTrue("Expected enabled action.", hideAction.isEnabled());
hideAction.run();
waitForIdleState();
treeItems = commonViewer.getTree().getItems();
workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
assertEquals("Mismatching number of working sets.", expectedItemCount - workingSetsToHide.size(), workingSets.size());
for (final WorkingSet workingSet : workingSetsToHide) {
assertTrue("Working set must not be visible in the navigator: " + workingSet, !workingSets.contains(workingSet));
}
IContributionItem showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
assertNotNull("Expected visible toolbar item, since there are hidden working sets.", showHiddenWorkingSetsItem);
assertTrue("Expected a type of " + ActionContributionItem.class, showHiddenWorkingSetsItem instanceof ActionContributionItem);
final IAction action = ((ActionContributionItem) showHiddenWorkingSetsItem).getAction();
assertTrue("Expected a type of " + ShowHiddenWorkingSetsDropDownAction.class, action instanceof ShowHiddenWorkingSetsDropDownAction);
final ShowHiddenWorkingSetsDropDownAction showHiddenWorkingSetsAction = (ShowHiddenWorkingSetsDropDownAction) action;
Menu menu = showHiddenWorkingSetsAction.getMenu(commonViewer.getControl());
assertTrue("Expected " + workingSetsToHide.size() + " menu item plus a separator plus an item for showing all hidden elements.", workingSetsToHide.size() + 2 == menu.getItemCount());
menu.getItem(0).notifyListeners(SWT.Selection, null);
waitForIdleState();
workingSetsToHide.remove(0);
treeItems = commonViewer.getTree().getItems();
workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
assertEquals("Mismatching number of working sets.", expectedItemCount - workingSetsToHide.size(), workingSets.size());
menu = showHiddenWorkingSetsAction.getMenu(commonViewer.getControl());
assertTrue("Expected " + workingSetsToHide.size() + " menu item plus a separator plus an item for showing all hidden elements.", workingSetsToHide.size() + 2 == menu.getItemCount());
menu.getItem(menu.getItemCount() - 1).notifyListeners(SWT.Selection, null);
waitForIdleState();
treeItems = commonViewer.getTree().getItems();
assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
assertNull("Expected not visible toolbar item, since all working sets are visible.", showHiddenWorkingSetsItem);
treeItems = commonViewer.getTree().getItems();
assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
workingSetsToHide = newArrayList(workingSets.subList(0, 3));
commonViewer.setSelection(new StructuredSelection(workingSetsToHide.toArray()));
hideAction.selectionChanged(commonViewer.getStructuredSelection());
waitForIdleState();
assertTrue("Expected enabled action.", hideAction.isEnabled());
hideAction.run();
waitForIdleState();
showHiddenWorkingSetsItem = from(Arrays.asList(projectExplorer.getViewSite().getActionBars().getToolBarManager().getItems())).firstMatch(i -> ShowHiddenWorkingSetsDropDownAction.class.getName().equals(i.getId())).orNull();
// This state will be reseted in tear down phase.
assertNotNull("Expected visible toolbar item, since there are hidden working sets.", showHiddenWorkingSetsItem);
}
Aggregations