Search in sources :

Example 1 with TestFormEditorHelper

use of org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method loadContent.

private void loadContent() {
    testFieldManager = spy(new TestFieldManager());
    when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> {
        final EditorFieldLayoutComponent mocked = mock(EditorFieldLayoutComponent.class);
        return mocked;
    });
    when(formEditorService.loadContent(any())).then(invocation -> {
        FormDefinition form = new FormDefinition();
        form.setName("EmployeeTestForm");
        form.setId("_random_id");
        content = new FormModelerContent();
        PortableJavaModel model = new PortableJavaModel("com.test.Employee");
        model.getProperties().addAll(modelProperties);
        form.setModel(model);
        content.setDefinition(form);
        content.setOverview(new Overview());
        return content;
    });
    when(testFieldManager.getBaseFieldTypes()).thenAnswer(invocationOnMock -> {
        List<String> baseFields = new ArrayList<>();
        baseFields.add("TextBox");
        baseFields.add("CheckBox");
        return baseFields;
    });
    editorServiceCallerMock = new CallerMock<>(formEditorService);
    formEditorHelper = new TestFormEditorHelper(testFieldManager, editorFieldLayoutComponents);
    formEditorService.loadContent(null);
    formEditorHelper.initHelper(content);
    assertEquals(formEditorHelper.getEditorFieldTypes().size(), formEditorHelper.getBaseFieldsDraggables().size());
}
Also used : FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) ArrayList(java.util.ArrayList) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) TestFormEditorHelper(org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) Overview(org.guvnor.common.services.shared.metadata.model.Overview) TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with TestFormEditorHelper

use of org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper 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));
    when(layoutEditorMock.getLayout()).thenReturn(new LayoutTemplate());
    when(menuBuilderMock.addSave(any(MenuItem.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addCopy(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addRename(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addRename(any(Command.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addDelete(any(ObservablePath.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.addNewTopLevelMenu(any(MenuItem.class))).thenReturn(menuBuilderMock);
    when(menuBuilderMock.build()).thenReturn(mock(Menus.class));
    when(versionRecordManager.getCurrentPath()).thenReturn(path);
    when(translationService.format(anyString(), anyString())).thenReturn("");
    showAssetUsagesDisplayer = spy(new ShowAssetUsagesDisplayer(assetUsagesDisplayerView, translationService, new CallerMock<>(assetsUsagService)));
    when(assetUsagesDisplayerView.getDefaultMessageContainer()).thenReturn(mock(HTMLElement.class));
    when(assetsUsagService.getAssetUsages(anyString(), any(), any())).thenReturn(assetUsages);
    deletePopUpPresenter = spy(new DeletePopUpPresenter(deletePopUpView, toggleCommentPresenter));
    presenter = new FormEditorPresenter(view, modelChangesDisplayer, formDefinitionResourceType, editorServiceCallerMock, translationService, editorFieldLayoutComponents, showAssetUsagesDisplayer) {

        {
            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;
            formEditorContext = mock(FormEditorContext.class);
        }

        @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) DefaultFileNameValidator(org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator) DeletePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.DeletePopUpPresenter) Command(org.uberfire.mvp.Command) Menus(org.uberfire.workbench.model.menu.Menus) TestFormEditorHelper(org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper) ObservablePath(org.uberfire.backend.vfs.ObservablePath)

Aggregations

EditorFieldLayoutComponent (org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)2 TestFormEditorHelper (org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper)2 FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)2 ArrayList (java.util.ArrayList)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 HTMLElement (org.jboss.errai.common.client.dom.HTMLElement)1 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)1 ShowAssetUsagesDisplayer (org.kie.workbench.common.services.refactoring.client.usages.ShowAssetUsagesDisplayer)1 Mockito.anyString (org.mockito.Mockito.anyString)1 ObservablePath (org.uberfire.backend.vfs.ObservablePath)1 DeletePopUpPresenter (org.uberfire.ext.editor.commons.client.file.popups.DeletePopUpPresenter)1 DefaultFileNameValidator (org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator)1 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)1 Command (org.uberfire.mvp.Command)1 PlaceRequest (org.uberfire.mvp.PlaceRequest)1 MenuItem (org.uberfire.workbench.model.menu.MenuItem)1 Menus (org.uberfire.workbench.model.menu.Menus)1