diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/PeopleSearchPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/PeopleSearchPresenter.java index 4c5e42e69a..58cca0a5e3 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/PeopleSearchPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/PeopleSearchPresenter.java @@ -96,6 +96,9 @@ public void loadMore() { >() { @Override public void onSuccess(UserGroupHeaderResponsePage result) { + boolean hasNoResults = offset == 0 && result.getChildren().isEmpty(); + view.setShowNoResults(hasNoResults); + for (UserGroupHeader header : result.getChildren()) { if (header.getIsIndividual()) { UserBadge badge = ginInjector.getUserBadgeWidget(); diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/TeamSearchPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/TeamSearchPresenter.java index 15f2ac7a86..3f18a4f91f 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/TeamSearchPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/TeamSearchPresenter.java @@ -108,6 +108,9 @@ public void loadMore() { >() { @Override public void onSuccess(PaginatedResults result) { + boolean hasNoResults = offset == 0 && result.getResults().isEmpty(); + view.setShowNoResults(hasNoResults); + for (Team team : result.getResults()) { BigTeamBadge teamBadge = ginInjector.getBigTeamBadgeWidget(); teamBadge.configure(team, ""); diff --git a/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchView.java b/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchView.java index 15eb8eca4b..07d3f2ac1f 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchView.java +++ b/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchView.java @@ -23,4 +23,6 @@ public interface Presenter { public void setSynAlertWidget(Widget asWidget); public void setSynAlertWidgetVisible(boolean b); + + public void setShowNoResults(boolean show); } diff --git a/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.java index b852fb851a..3565dad93a 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.java @@ -9,6 +9,7 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; @@ -39,6 +40,9 @@ public interface PeopleSearchViewImplUiBinder @UiField TextBox searchField; + @UiField + HTMLPanel noSearchResultsContainer; + private Header headerWidget; private Presenter presenter; @@ -103,4 +107,9 @@ public void setSynAlertWidget(Widget synAlert) { public void setSynAlertWidgetVisible(boolean isVisible) { synAlertPanel.setVisible(isVisible); } + + @Override + public void setShowNoResults(boolean show) { + noSearchResultsContainer.setVisible(show); + } } diff --git a/src/main/java/org/sagebionetworks/web/client/view/SearchViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/SearchViewImpl.java index 56028ec299..b9a0ed3c65 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/SearchViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/SearchViewImpl.java @@ -202,6 +202,9 @@ public Widget getResults( searchResultsPanel = new HTMLPanel( new SafeHtmlBuilder() + .appendHtmlConstant( + "" + ) .appendHtmlConstant( "

" + DisplayConstants.LABEL_NO_SEARCH_RESULTS_PART1 ) @@ -211,6 +214,7 @@ public Widget getResults( ) .toSafeHtml() ); + searchResultsPanel.addStyleName("text-align-center"); facetPanel.clear(); } else { searchResultsPanel = new SimplePanel(); diff --git a/src/main/java/org/sagebionetworks/web/client/view/TeamSearchView.java b/src/main/java/org/sagebionetworks/web/client/view/TeamSearchView.java index 96a11c175e..88c8ed4b03 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/TeamSearchView.java +++ b/src/main/java/org/sagebionetworks/web/client/view/TeamSearchView.java @@ -21,4 +21,6 @@ public interface Presenter { public void setSynAlertWidget(Widget asWidget); void setLoadMoreContainer(Widget w); + + public void setShowNoResults(boolean show); } diff --git a/src/main/java/org/sagebionetworks/web/client/view/TeamSearchViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/TeamSearchViewImpl.java index 2e53efab7e..61a6b25ae2 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/TeamSearchViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/TeamSearchViewImpl.java @@ -10,6 +10,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; @@ -39,6 +40,9 @@ public interface TeamSearchViewImplUiBinder @UiField SimplePanel synAlertPanel; + @UiField + HTMLPanel noSearchResultsContainer; + private Header headerWidget; private Presenter presenter; private SynapseJSNIUtils synapseJsniUtils; @@ -105,4 +109,9 @@ public void onKeyDown(KeyDownEvent event) { public void setSynAlertWidget(Widget synAlert) { synAlertPanel.setWidget(synAlert); } + + @Override + public void setShowNoResults(boolean show) { + noSearchResultsContainer.setVisible(show); + } } diff --git a/src/main/resources/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.ui.xml b/src/main/resources/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.ui.xml index 8d27522779..284fb611a7 100644 --- a/src/main/resources/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.ui.xml +++ b/src/main/resources/org/sagebionetworks/web/client/view/PeopleSearchViewImpl.ui.xml @@ -36,6 +36,17 @@ visible="false" /> + + + + + + + + diff --git a/src/test/java/org/sagebionetworks/web/unitclient/presenter/PeopleSearchPresenterTest.java b/src/test/java/org/sagebionetworks/web/unitclient/presenter/PeopleSearchPresenterTest.java index cff5d1fe2f..a0899d5e59 100644 --- a/src/test/java/org/sagebionetworks/web/unitclient/presenter/PeopleSearchPresenterTest.java +++ b/src/test/java/org/sagebionetworks/web/unitclient/presenter/PeopleSearchPresenterTest.java @@ -4,13 +4,14 @@ import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.Widget; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -109,6 +110,57 @@ public void testSearch() throws RestServiceException { verify(mockView).setSearchTerm(searchTerm); verify(mockPortalGinInjector, times(3)).getUserBadgeWidget(); verify(mockLoadMoreWidgetContainer, times(3)).add(any()); + verify(mockView).setShowNoResults(false); + + // Call loadMore with no results in the 2nd page + AsyncMockStubber + .callSuccessWith( + new UserGroupHeaderResponsePage().setChildren(Collections.emptyList()) + ) + .when(mockSynapseJavascriptClient) + .getUserGroupHeadersByPrefix( + anyString(), + any(TypeFilter.class), + anyLong(), + anyLong(), + any(AsyncCallback.class) + ); + + presenter.loadMore(); + + verify(mockView, never()).setShowNoResults(true); + } + + @Test + public void testEmptySearch() throws RestServiceException { + AsyncMockStubber + .callSuccessWith( + new UserGroupHeaderResponsePage().setChildren(Collections.emptyList()) + ) + .when(mockSynapseJavascriptClient) + .getUserGroupHeadersByPrefix( + anyString(), + any(TypeFilter.class), + anyLong(), + anyLong(), + any(AsyncCallback.class) + ); + + String searchTerm = "test"; + when(mockPlace.getSearchTerm()).thenReturn(searchTerm); + presenter.setPlace(mockPlace); + verify(mockSynapseJavascriptClient) + .getUserGroupHeadersByPrefix( + eq(searchTerm), + eq(TypeFilter.USERS_ONLY), + anyLong(), + anyLong(), + any(AsyncCallback.class) + ); + verify(mockView).setSearchTerm(searchTerm); + verify(mockPortalGinInjector, never()).getUserBadgeWidget(); + verify(mockLoadMoreWidgetContainer, never()).add(any()); + verify(mockView).setShowNoResults(true); } @Test diff --git a/src/test/java/org/sagebionetworks/web/unitclient/presenter/TeamSearchPresenterTest.java b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TeamSearchPresenterTest.java index f9b6665865..9afb20bd69 100644 --- a/src/test/java/org/sagebionetworks/web/unitclient/presenter/TeamSearchPresenterTest.java +++ b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TeamSearchPresenterTest.java @@ -2,9 +2,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -139,6 +141,7 @@ public void testSearch() throws RestServiceException { // add both test teams verify(mockPortalGinInjector, times(2)).getBigTeamBadgeWidget(); verify(mockLoadMoreWidgetContainer, times(2)).add(any()); + verify(mockView).setShowNoResults(false); } @Test @@ -155,6 +158,7 @@ public void testSearchFailure() throws RestServiceException { ); presenter.setPlace(mockPlace); verify(mockSynAlert).handleException(caught); + verify(mockView, never()).setShowNoResults(anyBoolean()); } @Test @@ -192,6 +196,8 @@ public void testEmptyTeams() { anyInt(), any(AsyncCallback.class) ); + + verify(mockView).setShowNoResults(true); } @Test