Skip to content

Commit

Permalink
KOGITO-9756: SWF Editor - Re-enable tests (#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
handreyrc authored Sep 29, 2023
1 parent ff4bdb1 commit 3d0c58c
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import elemental2.dom.HTMLDivElement;
import elemental2.dom.HTMLElement;
import elemental2.dom.MouseEvent;
import jsinterop.base.Js;
import org.gwtproject.timer.client.Timer;
import org.kie.workbench.common.stunner.client.lienzo.components.views.LienzoPanelWidget;
import org.kie.workbench.common.stunner.core.client.shape.view.event.NativeHandler;
Expand Down Expand Up @@ -152,7 +151,6 @@ private void moveProxyTo(final double x,
}

void attachHandlers(final ShapeGlyphDragHandler.Callback callback) {
//TODO: Remove Js.uncheckedCast() when j2cl migration is complete
HTMLElement panelElement = rootPanelSupplier.get();

mouseMoveHandler = new NativeHandler(MOUSE_MOVE,
Expand Down Expand Up @@ -217,7 +215,7 @@ private void clearHandlers() {
private void clearState(final Command proxyDestroyCommand) {
clearHandlers();
if (Objects.nonNull(dragProxyPanel)) {
rootPanelSupplier.get().removeChild(Js.cast(dragProxyPanel.getElement()));
rootPanelSupplier.get().removeChild(dragProxyPanel.getElement());
if (null != proxyDestroyCommand) {
proxyDestroyCommand.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
import com.ait.lienzo.client.core.shape.IPrimitive;
import com.ait.lienzo.client.core.shape.Layer;
import com.ait.lienzo.test.LienzoMockitoTestRunner;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import elemental2.dom.CSSStyleDeclaration;
import elemental2.dom.HTMLElement;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas;
Expand All @@ -49,8 +47,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

// TODO: J2CL migration - Drop the Ignore once 2 TODOs fixed
@Ignore
@RunWith(LienzoMockitoTestRunner.class)
public class LienzoCanvasViewTest {

Expand All @@ -65,63 +61,55 @@ public class LienzoCanvasViewTest {
@Mock
private LienzoPanel panel;
@Mock
private Style panelStyle;
@Mock
private CanvasSettings settings;

private HTMLElement element;

private LienzoCanvasView tested;

private BiFunction<Integer, Integer, IPrimitive<?>> decoratorFactory;

@Before
public void setUp() throws Exception {
decoratorFactory = (integer, integer2) -> decorator;
element = new HTMLElement();
when(lienzoLayer.getLienzoLayer()).thenReturn(layer);
Widget panelWidget = mock(Widget.class);
Element panelElement = mock(Element.class);
// TODO: J2CL migration - when(panel.asWidget()).thenReturn(panelWidget);
when(panelWidget.getElement()).thenReturn(panelElement);
when(panelElement.getStyle()).thenReturn(panelStyle);
when(panel.getElement()).thenReturn(element);
when(lienzoLayer.getTopLayer()).thenReturn(topLayer);
when(panel.show(lienzoLayer)).thenReturn(panel);
this.tested = new LienzoCanvasViewStub(decoratorFactory);
}

@Ignore("TODO fix test once gwt widgets is replaced with native ones.")
@Test
public void testInitialize() {
assertEquals(tested, tested.initialize(panel,
settings));
assertEquals(tested, tested.initialize(panel, settings));
verify(panel, times(1)).show(eq(lienzoLayer));
verify(panelStyle, times(1)).setBackgroundColor(eq(LienzoCanvasView.BG_COLOR));
assertEquals(LienzoCanvasView.BG_COLOR, element.style.backgroundColor);
verify(topLayer, times(1)).add(eq(decorator));
}

@Ignore("TODO fix test once gwt widgets is replaced with native ones.")
@Test
public void testSetGrid() {
tested.initialize(panel, settings);
tested.setGrid(CanvasGrid.DEFAULT_GRID);
verify(panel, times(1)).setBackgroundLayer(any(Layer.class));
}

@Ignore("TODO fix test once gwt widgets is replaced with native ones.")
@Test
public void testCursor() {
Widget widget = mock(Widget.class);
Element element = mock(Element.class);
Style style = mock(Style.class);
// TODO: J2CL migration - when(panel.asWidget()).thenReturn(widget);
when(widget.getElement()).thenReturn(element);
when(element.getStyle()).thenReturn(style);
HTMLElement panelElement = mock(HTMLElement.class);
CSSStyleDeclaration style = mock(CSSStyleDeclaration.class);
panelElement.style = style;
when(panel.getElement()).thenReturn(panelElement);

tested.initialize(panel, settings);
tested.setCursor(AbstractCanvas.Cursors.GRAB);

verify(style, times(1))
.setProperty(AbstractCanvasView.CURSOR, "grab");
.setProperty(AbstractCanvasView.CURSOR,
AbstractCanvasView.toLienzoCursorKey(AbstractCanvas.Cursors.GRAB));
}

@Ignore("TODO fix test once gwt widgets is replaced with native ones.")
@Test
public void testRemoveGrid() {
tested.initialize(panel, settings);
Expand All @@ -142,7 +130,6 @@ public void testTransform() {
assertEquals(transform, tested.getTransform());
}

@Ignore("TODO fix test once gwt widgets is replaced with native ones.")
@Test
public void testDestroy() {
tested.initialize(panel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import elemental2.dom.HTMLElement;
import elemental2.dom.MouseEvent;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.client.lienzo.components.glyph.ShapeGlyphDragHandler.Callback;
Expand Down Expand Up @@ -111,7 +110,6 @@ public void setUp() throws Exception {
}

@Test
@Ignore //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
public void testShowProxy() {
tested.show(glyphDragItem, 11, 33, mock(Callback.class));
ArgumentCaptor<Layer> layerArgumentCaptor = ArgumentCaptor.forClass(Layer.class);
Expand All @@ -123,11 +121,10 @@ public void testShowProxy() {
assertEquals("absolute", proxyStyle.position);
assertEquals((11d + "px"), proxyStyle.left);
assertEquals((33d + "px"), proxyStyle.top);
//verify(rootPanel, times(1)).add(eq(proxyPanel)); //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
verify(body, times(1)).appendChild(proxyPanel.getElement());
}

@Test
@Ignore //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
public void testProxyHandlers() {
Callback callback = mock(Callback.class);

Expand Down Expand Up @@ -165,13 +162,12 @@ public void testProxyHandlers() {
callback);
verify(moveHandlerReg, times(1)).removeHandler();
verify(upHandlerReg, times(1)).removeHandler();
//verify(rootPanel, times(1)).remove(eq(proxyPanel)); //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
verify(body, times(1)).removeChild(proxyPanel.getElement());
verify(callback, times(1)).onComplete(eq(3), eq(5));
assertTrue(handlerRegistrations.isEmpty());
}

@Test
@Ignore //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
public void testKeyboardHandling() {
Callback callback = mock(Callback.class);
attachHandlers();
Expand All @@ -184,12 +180,11 @@ public void testKeyboardHandling() {
tested.onKeyDown(event);
verify(moveHandlerReg, times(1)).removeHandler();
verify(upHandlerReg, times(1)).removeHandler();
//verify(rootPanel, times(1)).remove(eq(proxyPanel)); //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
verify(body, times(1)).removeChild(proxyPanel.getElement());
assertTrue(handlerRegistrations.isEmpty());
}

@Test
@Ignore //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
public void testClear() throws Exception {
Callback callback = mock(Callback.class);
attachHandlers();
Expand All @@ -198,12 +193,11 @@ public void testClear() throws Exception {
verify(proxyPanel, never()).destroy();
verify(moveHandlerReg, times(1)).removeHandler();
verify(upHandlerReg, times(1)).removeHandler();
//verify(rootPanel, times(1)).remove(eq(proxyPanel));
verify(body, times(1)).removeChild(proxyPanel.getElement());
assertTrue(handlerRegistrations.isEmpty());
}

@Test
@Ignore //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
public void testDestroy() throws Exception {
Callback callback = mock(Callback.class);
attachHandlers();
Expand All @@ -212,7 +206,7 @@ public void testDestroy() throws Exception {
verify(proxyPanel, times(1)).destroy();
verify(moveHandlerReg, times(1)).removeHandler();
verify(upHandlerReg, times(1)).removeHandler();
//verify(rootPanel, times(1)).remove(eq(proxyPanel)); //TODO this test must be fixed, once the rootPanel is replaced with HtmlElement
verify(body, times(1)).removeChild(proxyPanel.getElement());
assertTrue(handlerRegistrations.isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/


Expand All @@ -38,7 +38,6 @@
import org.jboss.errai.ui.client.local.api.IsElement;
import org.jboss.errai.ui.client.local.spi.TranslationService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoCanvas;
Expand Down Expand Up @@ -145,8 +144,7 @@ public void setUp() {

floatingView = spy(new FloatingWidgetView());

doReturn(rootPanel).when(((FloatingWidgetView)floatingView)).getRootPanel();
//when(((FloatingWidgetView)floatingView).getRootPanel()).thenReturn(rootPanel);
doReturn(rootPanel).when(((FloatingWidgetView) floatingView)).getRootPanel();

tested = new ZoomLevelSelectorPresenter(translationService,
floatingView,
Expand Down Expand Up @@ -189,17 +187,13 @@ public void testAt() {
verify(floatingView, times(1)).setY(eq(25d));
}

//TODO: Fix me when the widgets are migrated to J2CL
// temporary Js.uncheckedCast() breaks these tests
@Ignore
@Test
public void testShow() {
tested.show();
verify(floatingView, times(1)).show();
}

//TODO: Fix me when the widgets are migrated to J2CL
// temporary Js.uncheckedCast() breaks these tests
@Ignore
@Test
public void testHideZoomOnLoad() {
//First call on canvas loading
verify(floatingView, times(0)).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
@Dependent
public class StunnerEditor {

private final ManagedInstance<SessionEditorPresenter<EditorSession>> editorSessionPresenterInstances;
private final ManagedInstance<SessionViewerPresenter<ViewerSession>> viewerSessionPresenterInstances;
private final ClientTranslationService translationService;
private final ErrorPage errorPage;
ManagedInstance<SessionEditorPresenter<EditorSession>> editorSessionPresenterInstances;
ManagedInstance<SessionViewerPresenter<ViewerSession>> viewerSessionPresenterInstances;
ClientTranslationService translationService;
ErrorPage errorPage;
private boolean hasErrors;

private SessionDiagramPresenter diagramPresenter;
Expand All @@ -79,7 +79,7 @@ public class StunnerEditor {
private Consumer<Throwable> exceptionProcessor;
private AlertsControl<AbstractCanvas> alertsControl;

private final HTMLDivElement rootContainer = (HTMLDivElement) DomGlobal.document.getElementById("root-container");
private HTMLDivElement rootContainer;

// CDI proxy.
public StunnerEditor() {
Expand All @@ -102,6 +102,13 @@ public StunnerEditor(ManagedInstance<SessionEditorPresenter<EditorSession>> edit
};
}

HTMLDivElement getRootContainer() {
if (null == rootContainer) {
rootContainer = (HTMLDivElement) DomGlobal.document.getElementById("root-container");
}
return rootContainer;
}

public void setReadOnly(boolean readOnly) {
isReadOnly = readOnly;
}
Expand Down Expand Up @@ -160,23 +167,29 @@ public void onError(ClientRuntimeError error) {
callback.onError(error);
}
});
removeAllChildren(rootContainer);
removeAllChildren(getRootContainer());

getRootContainer().appendChild(diagramPresenter.getView().getElement());

addResizeListener();

rootContainer.appendChild(diagramPresenter.getView().getElement());
resize();
}

void addResizeListener() {
DomGlobal.window.addEventListener("resize", evt -> {
resizeTo(DomGlobal.window.innerWidth, DomGlobal.window.innerHeight);
});
resize();
}

private void resize() {
void resize() {
resizeTo(DomGlobal.document.body.clientWidth,
DomGlobal.document.body.clientHeight);
DomGlobal.document.body.clientHeight);
}

private void resizeTo(int width,
int height) {
CSSStyleDeclaration style = rootContainer.style;
CSSStyleDeclaration style = getRootContainer().style;
style.width = WidthUnionType.of(width + "px");
style.height = HeightUnionType.of(height + "px");
}
Expand Down Expand Up @@ -243,8 +256,8 @@ public void handleError(final ClientRuntimeError error) {
(diagramPresenter.getView() != null)) {
addError(message);
} else {
removeAllChildren(rootContainer);
rootContainer.appendChild(Js.uncheckedCast(errorPage.getElement()));
removeAllChildren(getRootContainer());
getRootContainer().appendChild(Js.uncheckedCast(errorPage.getElement()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import com.ait.lienzo.client.core.shape.Layer;
import com.google.gwtmockito.GwtMockitoTestRunner;
import elemental2.dom.HTMLElement;
import org.jboss.errai.ui.client.local.api.IsElement;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer;
Expand Down Expand Up @@ -92,9 +90,8 @@ public void testDestroy() {
}

@Test
@Ignore("throws CCE")
public void testIsElement() {
HTMLElement e = (HTMLElement) mock(IsElement.class);
HTMLElement e = mock(HTMLElement.class);
when(delegate.getElement()).thenReturn(e);
assertEquals(e, tested.getElement());
}
Expand Down
Loading

0 comments on commit 3d0c58c

Please sign in to comment.