Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sl-eng committed Sep 20, 2012
1 parent d610a78 commit 83df779
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
Expand Up @@ -301,12 +301,12 @@ public void showView(MainView viewToShow)
*/
public void selectDocument(DocumentId docId)
{
display.enableTab(MainView.Editor, true);
if (selectedDocument == null || !docId.equals(selectedDocument.getId()))
{
DocumentInfo docInfo = documentListPresenter.getDocumentInfo(docId);
if (docInfo != null)
{
display.enableTab(MainView.Editor, true);
selectedDocument = docInfo;
selectedDocumentStats.set(selectedDocument.getStats());
if (currentView == MainView.Editor)
Expand Down Expand Up @@ -415,7 +415,6 @@ public void onEditorClicked()
@Override
public void onDocumentListClicked()
{

HistoryToken token = HistoryToken.fromTokenString(history.getToken());
if (!token.getView().equals(MainView.Documents))
{
Expand Down
Expand Up @@ -22,19 +22,28 @@
import org.zanata.webtrans.client.history.Window;
import org.zanata.webtrans.client.keys.KeyShortcut;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.client.view.AppDisplay;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.model.WorkspaceId;
import org.zanata.webtrans.shared.rpc.HasWorkspaceContextUpdateData;

import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.HasBeforeSelectionHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.PresenterRevealedEvent;
import static org.hamcrest.MatcherAssert.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand Down Expand Up @@ -90,7 +99,13 @@ public void onBind()
{
when(location.getParameter("title")).thenReturn("blah");
when(messages.windowTitle2(userWorkspace.getWorkspaceContext().getWorkspaceName(), userWorkspace.getWorkspaceContext().getLocaleName(), "blah")).thenReturn("new title");


HasSelectionHandlers<Integer> contentBodySelection = mock(HasSelectionHandlers.class);
HasBeforeSelectionHandlers<Integer> contentBodyBeforeSelection = mock(HasBeforeSelectionHandlers.class);

when(display.getContentBodySelection()).thenReturn(contentBodySelection);
when(display.getContentBodyBeforeSelection()).thenReturn(contentBodyBeforeSelection);

presenter.onBind();

verify(keyShortcutPresenter).bind();
Expand All @@ -107,6 +122,10 @@ public void onBind()

WorkspaceId workspaceId = userWorkspace.getWorkspaceContext().getWorkspaceId();
String localeId = workspaceId.getLocaleId().getId();

verify(contentBodySelection).addSelectionHandler(isA(SelectionHandler.class));
verify(contentBodyBeforeSelection).addBeforeSelectionHandler(isA(BeforeSelectionHandler.class));

verify(display).setProjectLinkLabel(workspaceId.getProjectIterationId().getProjectSlug());
verify(display).setIterationFilesLabel(workspaceId.getProjectIterationId().getIterationSlug() + " [" + localeId + "]");
verify(display).setReadOnlyVisible(userWorkspace.hasReadOnlyAccess());
Expand Down Expand Up @@ -201,14 +220,14 @@ public void canSwitchToDocumentView()
{
// Given: current selected document is null
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(Matchers.nullValue()));
when(messages.noDocumentSelected()).thenReturn("no document selected");
when(messages.documentListTitle()).thenReturn("Documents");
presenter.setStatesForTest(projectStats, selectedDocumentStats, null);

// When:
presenter.showView(MainView.Documents);

// Then:
verify(display).setDocumentLabel("", "no document selected");
verify(display).setDocumentLabel("", "Documents");
verify(translationPresenter).concealDisplay();
verify(searchResultPresenter).concealDisplay();
verify(sideMenuPresenter).showEditorMenu(false);
Expand Down Expand Up @@ -258,6 +277,8 @@ public void canSelectDocumentNotInEditorView()
presenter.selectDocument(docId);

// Then:
verify(display).enableTab(MainView.Editor, true);

verifyNoMoreInteractions(display);
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(docId));
}
Expand All @@ -282,6 +303,7 @@ public void onDocumentStatsUpdateWillDoNothingIsDifferentDocument()
// When:
presenter.onDocumentStatsUpdated(new DocumentStatsUpdatedEvent(new DocumentId(1L), new TranslationStats()));


// Then:
verifyZeroInteractions(display);
}
Expand Down Expand Up @@ -361,25 +383,6 @@ public void onDocumentsClickWillFireNewHistoryItemAndSwitchToDocumentView()
verifyNoMoreInteractions(history);
}

@Test
public void onDocumentsClickWillFireNewHistoryItemAndSwitchToEditorView()
{
// Given: current token is document view and has selected doc
DocumentId docId = new DocumentId(1L);
DocumentInfo documentInfo = new DocumentInfo(docId, "a.po", "pot/", new LocaleId("en-US"), selectedDocumentStats);
when(documentListPresenter.getDocumentInfo(docId)).thenReturn(documentInfo);
when(history.getToken()).thenReturn("doc:pot/a.po");
presenter.selectDocument(docId);

// When:
presenter.onDocumentListClicked();

// Then:
verify(history).getToken();
verify(history).newItem("view:doc;doc:pot/a.po");
verifyNoMoreInteractions(history);
}

@Test
public void onKeyShortcutClick()
{
Expand Down

0 comments on commit 83df779

Please sign in to comment.