Skip to content

Commit

Permalink
Clicking the news button switches between show and hide
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Feb 2, 2018
1 parent ca0cd71 commit 0b5ead4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pdfsam-gui/src/main/java/org/pdfsam/ui/banner/NewsButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.sejda.eventstudio.StaticStudio.eventStudio;

import org.pdfsam.i18n.DefaultI18nContext;
import org.pdfsam.news.HideNewsPanelRequest;
import org.pdfsam.news.ShowNewsPanelRequest;
import org.pdfsam.ui.commons.Animations;
import org.sejda.eventstudio.annotation.EventListener;
Expand All @@ -38,15 +39,25 @@ class NewsButton extends BannerButton {

static final String UP_TO_DATE_CSS_CLASS = "news-not-up-to-date";
private Timeline anim;
private Object action = ShowNewsPanelRequest.INSTANCE;

NewsButton() {
super(MaterialDesignIcon.NEWSPAPER);
setOnAction(e -> eventStudio().broadcast(ShowNewsPanelRequest.INSTANCE));
setOnAction(e -> {
eventStudio().broadcast(action);
action = switchAction();
});
setTooltip(new Tooltip(DefaultI18nContext.getInstance().i18n("What's new")));
anim = Animations.shake(this);
eventStudio().addAnnotatedListeners(this);
}

private Object switchAction() {
if (action instanceof ShowNewsPanelRequest) {
return HideNewsPanelRequest.INSTANCE;
}
return ShowNewsPanelRequest.INSTANCE;
}
/**
* Sets the button in upToDate state or else, based on the input value
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.sejda.eventstudio.StaticStudio.eventStudio;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.loadui.testfx.GuiTest;
import org.loadui.testfx.categories.TestFX;
import org.pdfsam.news.HideNewsPanelRequest;
import org.pdfsam.news.ShowNewsPanelRequest;
import org.sejda.eventstudio.Listener;

Expand All @@ -47,9 +50,14 @@ protected Parent getRootNode() {
@Test
public void onClick() {
Listener<ShowNewsPanelRequest> listener = mock(Listener.class);
Listener<HideNewsPanelRequest> hideListener = mock(Listener.class);
eventStudio().add(ShowNewsPanelRequest.class, listener);
eventStudio().add(HideNewsPanelRequest.class, hideListener);
click(".button");
verify(listener).onEvent(any());
verify(listener).onEvent(eq(ShowNewsPanelRequest.INSTANCE));
verify(hideListener, never()).onEvent(any());
click(".button");
verify(hideListener).onEvent(eq(HideNewsPanelRequest.INSTANCE));
}

@Test
Expand Down

0 comments on commit 0b5ead4

Please sign in to comment.