Search in sources :

Example 26 with MenuItem

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);
}
Also used : PlaceRequest(org.uberfire.mvp.PlaceRequest) ShowAssetUsagesDisplayer(org.kie.workbench.common.services.refactoring.client.usages.ShowAssetUsagesDisplayer) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) MenuItem(org.uberfire.workbench.model.menu.MenuItem) DeletePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.DeletePopUpPresenter) Menus(org.uberfire.workbench.model.menu.Menus) TestFormEditorHelper(org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper)

Example 27 with MenuItem

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());
}
Also used : Answer(org.mockito.stubbing.Answer) Callback(com.google.gwt.core.client.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 28 with MenuItem

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();
}
Also used : MenuItemCommand(org.uberfire.workbench.model.menu.MenuItemCommand) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 29 with MenuItem

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());
}
Also used : Answer(org.mockito.stubbing.Answer) Callback(com.google.gwt.core.client.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 30 with MenuItem

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());
}
Also used : BaseMenuCustom(org.uberfire.workbench.model.menu.impl.BaseMenuCustom) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Aggregations

MenuItem (org.uberfire.workbench.model.menu.MenuItem)34 Test (org.junit.Test)18 Button (org.gwtbootstrap3.client.ui.Button)6 IsWidget (com.google.gwt.user.client.ui.IsWidget)5 ButtonGroup (org.gwtbootstrap3.client.ui.ButtonGroup)5 DropDownMenu (org.gwtbootstrap3.client.ui.DropDownMenu)5 Command (org.uberfire.mvp.Command)5 AnchorListItem (org.gwtbootstrap3.client.ui.AnchorListItem)4 ButtonSize (org.gwtbootstrap3.client.ui.constants.ButtonSize)4 IconType (org.gwtbootstrap3.client.ui.constants.IconType)4 Toggle (org.gwtbootstrap3.client.ui.constants.Toggle)4 MenuUtils (org.kie.workbench.common.stunner.client.widgets.menu.MenuUtils)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Inject (javax.inject.Inject)3 IconPosition (org.gwtbootstrap3.client.ui.constants.IconPosition)3 Pull (org.gwtbootstrap3.client.ui.constants.Pull)3 PlaceRequest (org.uberfire.mvp.PlaceRequest)3 Menus (org.uberfire.workbench.model.menu.Menus)3 BaseMenuCustom (org.uberfire.workbench.model.menu.impl.BaseMenuCustom)3