Skip to content

Commit

Permalink
SWC-6869: add tests for new method in GlobalAppState
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Jun 12, 2024
1 parent c81282e commit b13897a
Showing 1 changed file with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.web.client.DateTimeUtils;
import org.sagebionetworks.web.client.GWTWrapper;
Expand All @@ -50,6 +49,7 @@
import org.sagebionetworks.web.client.cookie.CookieProvider;
import org.sagebionetworks.web.client.mvp.AppActivityMapper;
import org.sagebionetworks.web.client.mvp.AppPlaceHistoryMapper;
import org.sagebionetworks.web.client.place.Home;
import org.sagebionetworks.web.client.place.Synapse;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.client.widget.footer.VersionState;
Expand All @@ -61,12 +61,24 @@ public class GlobalApplicationStateImplTest {
@Mock
StackConfigServiceAsync mockStackConfigService;

@Mock
CookieProvider mockCookieProvider;

@Mock
PlaceController mockPlaceController;

@Mock
EventBus mockEventBus;

GlobalApplicationStateImpl globalApplicationState;

@Mock
AppPlaceHistoryMapper mockAppPlaceHistoryMapper;

@Mock
SynapseJSNIUtils mockSynapseJSNIUtils;

@Mock
GlobalApplicationStateView mockView;

@Mock
Expand Down Expand Up @@ -96,19 +108,16 @@ public class GlobalApplicationStateImplTest {
@Mock
SessionStorage mockSessionStorage;

@Captor
ArgumentCaptor<Place> placeCaptor;

public static final String REPO_ENDPOINT =
"https://repo-staging.prod.sagebase.org/";
public static final String SWC_ENDPOINT = "https://staging.synapse.org/";

@Before
public void before() {
MockitoAnnotations.initMocks(this);
mockCookieProvider = Mockito.mock(CookieProvider.class);
mockPlaceController = Mockito.mock(PlaceController.class);
mockEventBus = Mockito.mock(EventBus.class);
mockAppPlaceHistoryMapper = mock(AppPlaceHistoryMapper.class);
mockSynapseJSNIUtils = mock(SynapseJSNIUtils.class);
mockView = mock(GlobalApplicationStateView.class);
AsyncMockStubber
.callSuccessWith("v1")
.when(mockJsClient)
Expand Down Expand Up @@ -512,4 +521,55 @@ public void testSetShowUTCTime() {
any(Date.class)
);
}

@Test
public void testHandleClickSynapsePlace() {
when(mockPlaceController.getWhere()).thenReturn(mock(Home.class));
Synapse mockSynapsePlace = mock(Synapse.class);
when(mockAppPlaceHistoryMapper.getPlace("Synapse:syn123"))
.thenReturn(mockSynapsePlace);
String href = "http://www.synapse.org/Synapse:syn123";

boolean isHandled = globalApplicationState.handleRelativePathClick(href);

assertTrue(isHandled);
verify(mockPlaceController).goTo(mockSynapsePlace);
}

@Test
public void testHandleRelativePathClickSynapsePlace() {
when(mockPlaceController.getWhere()).thenReturn(mock(Home.class));
Synapse mockSynapsePlace = mock(Synapse.class);
when(mockAppPlaceHistoryMapper.getPlace("Synapse:syn123"))
.thenReturn(mockSynapsePlace);
String href = "/Synapse:syn123";

boolean isHandled = globalApplicationState.handleRelativePathClick(href);

assertTrue(isHandled);
verify(mockPlaceController).goTo(mockSynapsePlace);
}

@Test
public void testHandleRelativePathClickInvalidFormat() {
when(mockPlaceController.getWhere()).thenReturn(mock(Home.class));
String href = "https://www.synapse.org/notaplace";

boolean isHandled = globalApplicationState.handleRelativePathClick(href);

assertFalse(isHandled);
verify(mockPlaceController, never()).goTo(any(Place.class));
}

@Test
public void testHandleRelativePathNotAGWTPlace() {
when(mockPlaceController.getWhere()).thenReturn(mock(Home.class));
String href =
"https://www.synapse.org/AppearsToBeCorrectFormatButNotAPlace:syn1234";

boolean isHandled = globalApplicationState.handleRelativePathClick(href);

assertFalse(isHandled);
verify(mockPlaceController, never()).goTo(any(Place.class));
}
}

0 comments on commit b13897a

Please sign in to comment.