Skip to content

Commit

Permalink
GUVNOR-3486: [Guided Decision Table Graph] Refresh after removal of t…
Browse files Browse the repository at this point in the history
…able (apache#656)

* GUVNOR-3486: [Guided Decision Table Graph] Refresh after removal of table

* GUVNOR-3486: [Guided Decision Table Graph] Refresh after removal of table. Updates following peer review.
  • Loading branch information
manstis authored Oct 17, 2017
1 parent b5eea24 commit 4c406d1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.enterprise.event.Event;

import com.google.gwt.user.client.ui.IsWidget;
Expand Down Expand Up @@ -318,10 +319,9 @@ public void removeDocument(final GuidedDecisionTableView.Presenter dtPresenter)
}

void openOtherDecisionTable() {
decisionTableSelectedEvent.fire(DecisionTableSelectedEvent.NONE);
final Set<GuidedDecisionTableView.Presenter> availableDecisionTables = modeller.getAvailableDecisionTables();
if (availableDecisionTables == null || availableDecisionTables.isEmpty()) {
decisionTableSelectedEvent.fire(DecisionTableSelectedEvent.NONE);
} else {
if (!(availableDecisionTables == null || availableDecisionTables.isEmpty())) {
final GuidedDecisionTableView.Presenter dtPresenter = availableDecisionTables.iterator().next();
decisionTableSelectedEvent.fire(new DecisionTableSelectedEvent(dtPresenter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.enterprise.context.Dependent;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
Expand Down Expand Up @@ -364,10 +365,12 @@ public void addOnExitPinnedModeCommand(final Command command) {
public void onDecisionTableSelected(final @Observes DecisionTableSelectedEvent event) {
final Optional<GuidedDecisionTableView.Presenter> dtPresenter = event.getPresenter();
if (!dtPresenter.isPresent()) {
activeDecisionTable = null;
return;
}
final GuidedDecisionTableView.Presenter presenter = dtPresenter.get();
if (!isDecisionTableAvailable(presenter)) {
activeDecisionTable = null;
return;
}
if (presenter.equals(getActiveDecisionTable())) {
Expand All @@ -384,7 +387,7 @@ public void openNewGuidedDecisionTableColumnWizard() {
wizard.start();
}

private void doDecisionTableSelected(final GuidedDecisionTableView.Presenter dtPresenter) {
void doDecisionTableSelected(final GuidedDecisionTableView.Presenter dtPresenter) {
//Store selected decision table
activeDecisionTable = dtPresenter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

Expand All @@ -27,7 +28,6 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
Expand Down Expand Up @@ -508,19 +508,6 @@ public void refreshConditionsWidget(final List<CompositeColumn<? extends BaseCol
getConditionsPanel().renderColumns(columnGroups);
}

private Widget deleteAnchor(final ClickHandler clickHandler) {
return anchor(GuidedDecisionTableConstants.INSTANCE.Delete(),
clickHandler);
}

private Anchor anchor(final String text,
final ClickHandler clickHandler) {
return new Anchor() {{
setText(text);
addClickHandler(clickHandler);
}};
}

@Override
public void refreshActionsWidget(final List<ActionCol52> actionColumns) {
getActionsConfigWidget().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@
import org.uberfire.workbench.events.NotificationEvent;
import org.uberfire.workbench.model.menu.Menus;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(GwtMockitoTestRunner.class)
public class BaseGuidedDecisionTableEditorPresenterTest extends BaseGuidedDecisionTablePresenterTest<BaseGuidedDecisionTableEditorPresenter> {
Expand Down Expand Up @@ -394,12 +404,15 @@ public void checkOpenOtherDecisionTableIsNotLastDecisionTable() {
verify(placeManager,
never()).forceClosePlace(any(PlaceRequest.class));
verify(decisionTableSelectedEvent,
times(1)).fire(dtSelectedEventCaptor.capture());

final DecisionTableSelectedEvent dtSelectedEvent = dtSelectedEventCaptor.getValue();
assertNotNull(dtSelectedEvent);
assertTrue(dtSelectedEvent.getPresenter().isPresent());
assertEquals(dtSelectedEvent.getPresenter().get(),
times(2)).fire(dtSelectedEventCaptor.capture());

final List<DecisionTableSelectedEvent> dtSelectedEvents = dtSelectedEventCaptor.getAllValues();
assertNotNull(dtSelectedEvents);
assertEquals(2,
dtSelectedEvents.size());
assertFalse(dtSelectedEvents.get(0).getPresenter().isPresent());
assertTrue(dtSelectedEvents.get(1).getPresenter().isPresent());
assertEquals(dtSelectedEvents.get(1).getPresenter().get(),
remainingDtPresenter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.enterprise.event.Event;

import com.ait.lienzo.client.core.event.NodeMouseMoveHandler;
Expand Down Expand Up @@ -70,8 +71,21 @@
import org.uberfire.mvp.ParameterizedCommand;
import org.uberfire.mvp.PlaceRequest;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(LienzoMockitoTestRunner.class)
public class GuidedDecisionTableModellerPresenterTest {
Expand Down Expand Up @@ -559,6 +573,34 @@ public void onDecisionTableSelectedWhenNotInPinnedMode() {
never()).flipToGridWidget(any(GuidedDecisionTableView.class));
}

@Test
public void onDecisionTableSelectedNoneSelected() {
final DecisionTableSelectedEvent event = DecisionTableSelectedEvent.NONE;

presenter.onDecisionTableSelected(event);

assertNull(presenter.getActiveDecisionTable());

verify(presenter,
never()).doDecisionTableSelected(any(GuidedDecisionTableView.Presenter.class));
}

@Test
public void onDecisionTableSelectedNotAvailable() {
final GuidedDecisionTableView.Presenter dtPresenter1 = makeDecisionTable();
final GuidedDecisionTableView.Presenter dtPresenter2 = makeDecisionTable();
final DecisionTableSelectedEvent event = new DecisionTableSelectedEvent(dtPresenter1);

when(presenter.getAvailableDecisionTables()).thenReturn(Collections.singleton(dtPresenter2));

presenter.onDecisionTableSelected(event);

assertNull(presenter.getActiveDecisionTable());

verify(presenter,
never()).doDecisionTableSelected(any(GuidedDecisionTableView.Presenter.class));
}

@Test
public void onDecisionTableLinkedColumnSelected() {
final GridColumn gridColumn = mock(GridColumn.class);
Expand Down

0 comments on commit 4c406d1

Please sign in to comment.