use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.
the class FormEditorPresenterAbstractTest method loadContent.
protected void loadContent() {
when(formDefinitionResourceType.getSuffix()).thenReturn("form.frm");
when(formDefinitionResourceType.accept(path)).thenReturn(true);
when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> mock(EditorFieldLayoutComponent.class));
when(formEditorService.loadContent(any())).then(invocation -> serviceLoad());
editorServiceCallerMock = new CallerMock<>(formEditorService);
editorHelper = spy(new TestFormEditorHelper(fieldManager, editorFieldLayoutComponents, beanManager));
when(layoutEditorMock.getLayout()).thenReturn(new LayoutTemplate());
when(menuBuilderMock.addSave(Mockito.<MenuItem>any())).thenReturn(menuBuilderMock);
when(menuBuilderMock.addCopy(Mockito.<Command>any())).thenReturn(menuBuilderMock);
when(menuBuilderMock.addRename(Mockito.<Command>any())).thenReturn(menuBuilderMock);
when(menuBuilderMock.addDelete(Mockito.<ObservablePath>any())).thenReturn(menuBuilderMock);
when(menuBuilderMock.addNewTopLevelMenu(Mockito.<MenuItem>any())).thenReturn(menuBuilderMock);
when(menuBuilderMock.build()).thenReturn(mock(Menus.class));
when(versionRecordManager.getCurrentPath()).thenReturn(path);
when(translationService.format(Mockito.<String>any(), Mockito.<String>any())).thenReturn("");
showAssetUsagesDisplayer = spy(new ShowAssetUsagesDisplayer(assetUsagesDisplayerView, translationService, new CallerMock<>(assetsUsagService)));
when(assetUsagesDisplayerView.getDefaultMessageContainer()).thenReturn(mock(HTMLElement.class));
when(assetsUsagService.getAssetUsages(Mockito.<String>any(), any(), any())).thenReturn(assetUsages);
deletePopUpPresenter = spy(new DeletePopUpPresenter(deletePopUpView, toggleCommentPresenter));
presenter = new FormEditorPresenter(view, modelChangesDisplayer, formDefinitionResourceType, editorServiceCallerMock, translationService, editorFieldLayoutComponents, showAssetUsagesDisplayer, errorMessageDisplayer, layoutEditorPropertiesPresenter) {
{
kieView = mock(KieEditorWrapperView.class);
versionRecordManager = FormEditorPresenterAbstractTest.this.versionRecordManager;
editorHelper = FormEditorPresenterAbstractTest.this.editorHelper;
busyIndicatorView = mock(BusyIndicatorView.class);
overviewWidget = mock(OverviewWidgetPresenter.class);
layoutEditor = layoutEditorMock;
layoutDragComponentPalette = layoutDragComponentPaletteMock;
layoutFocusEvent = layoutFocusEventMock;
htmlLayoutDragComponent = FormEditorPresenterAbstractTest.this.htmlLayoutDragComponent;
notification = notificationEvent;
fileMenuBuilder = menuBuilderMock;
workbenchContext = FormEditorPresenterAbstractTest.this.workbenchContext;
projectController = FormEditorPresenterAbstractTest.this.projectController;
deletePopUpPresenter = FormEditorPresenterAbstractTest.this.deletePopUpPresenter;
renamePopUpPresenter = FormEditorPresenterAbstractTest.this.renamePopUpPresenter;
alertsButtonMenuItemBuilder = FormEditorPresenterAbstractTest.this.alertsButtonMenuItemBuilder;
copyPopUpPresenter = FormEditorPresenterAbstractTest.this.copyPopUpPresenter;
promises = FormEditorPresenterAbstractTest.this.promises;
}
@Override
protected MenuItem downloadMenuItem() {
return downloadMenuItem;
}
@Override
public void doLoadContent(FormModelerContent content) {
super.doLoadContent(content);
employeeFields.addAll(editorHelper.getAvailableFields().values());
}
@Override
protected void addSourcePage() {
}
};
presenter.onStartup(path, mock(PlaceRequest.class));
assertTrue("There should exist base field draggables", editorHelper.getBaseFieldsDraggables().size() > 0);
}
use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.
the class NewResourcesMenuTest method testOnWorkspaceProjectContextChangedDisabled.
@Test
@SuppressWarnings("unchecked")
public void testOnWorkspaceProjectContextChangedDisabled() {
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) {
final Object[] args = invocation.getArguments();
final Callback callback = (Callback) args[0];
callback.onSuccess(false);
return null;
}
}).when(handler).acceptContext(any(Callback.class));
// Arguments aren't actually used
menu.onChange(null, null);
verify(handler, times(1)).acceptContext(any(Callback.class));
final List<MenuItem> menus = menu.getMenuItems();
verify(handler, times(2)).acceptContext(any(Callback.class));
final MenuItem mi = menus.get(0);
assertFalse(mi.isEnabled());
}
use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.
the class NewResourcesMenuTest method testMenuItemCommand.
@Test
public void testMenuItemCommand() {
final List<MenuItem> menus = menu.getMenuItems();
assertNotNull(menus);
assertEquals(1, menus.size());
final MenuItem mi = menus.get(0);
assertTrue(mi.isEnabled());
assertTrue(mi instanceof MenuItemCommand);
final MenuItemCommand miu = (MenuItemCommand) mi;
assertNotNull(miu.getCommand());
miu.getCommand().execute();
verify(command, times(1)).execute();
}
use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.
the class NewResourcesMenuTest method testOnWorkspaceProjectContextChangedEnabled.
@Test
@SuppressWarnings("unchecked")
public void testOnWorkspaceProjectContextChangedEnabled() {
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) {
final Object[] args = invocation.getArguments();
final Callback callback = (Callback) args[0];
callback.onSuccess(true);
return null;
}
}).when(handler).acceptContext(any(Callback.class));
// Arguments aren't actually used
menu.onChange(null, null);
verify(handler, times(1)).acceptContext(any(Callback.class));
final List<MenuItem> menus = menu.getMenuItems();
verify(handler, times(2)).acceptContext(any(Callback.class));
final MenuItem mi = menus.get(0);
assertTrue(mi.isEnabled());
}
use of org.uberfire.workbench.model.menu.MenuItem in project kie-wb-common by kiegroup.
the class ProjectEditorMenuSessionItemsTest method testIsEnabledWithRegisteredMenuItem.
@Test
public void testIsEnabledWithRegisteredMenuItem() {
final MenuItem menuItem = new BaseMenuCustom<String>() {
@Override
public String build() {
return "";
}
};
when(itemsBuilder.newClearItem(Mockito.<Command>any())).thenReturn(menuItem);
editorMenuSessionItems.populateMenu(fileMenuBuilder);
editorMenuSessionItems.setItemEnabled(ClearSessionCommand.class, true);
assertTrue(menuItem.isEnabled());
editorMenuSessionItems.setItemEnabled(ClearSessionCommand.class, false);
assertFalse(menuItem.isEnabled());
}
Aggregations