コード例 #1
0
  @Test
  public void testGetByIdOrNull() throws Exception {
    assertThat(service.getByIdOrNull(new TransUnitId(2)), Matchers.equalTo(data.get(1)));

    // not in current page
    assertThat(service.getByIdOrNull(new TransUnitId(99)), Matchers.nullValue());
  }
コード例 #2
0
  @Test
  public void testSelectByRowIndex() throws Exception {
    service.init(initContext);
    service.selectByRowIndex(1);

    assertThat(service.getCurrentRowIndexOnPage(), Matchers.equalTo(1));
    assertThat(service.getSelectedOrNull(), Matchers.equalTo(data.get(1)));
  }
コード例 #3
0
  @Test
  public void testFindRowIndexById() throws Exception {
    assertThat(service.findRowIndexById(new TransUnitId(2)), Matchers.equalTo(1));

    // not in current page
    assertThat(
        service.findRowIndexById(new TransUnitId(99)),
        Matchers.equalTo(NavigationService.UNSELECTED));
  }
コード例 #4
0
  @Test
  public void testOnPageSizeChange() throws Exception {
    service.init(initContext);

    service.onPageSizeChange(new EditorPageSizeChangeEvent(5));

    verify(dispatcher, times(2)).execute(actionCaptor.capture(), resultCaptor.capture());
    GetTransUnitList getTransUnitList = actionCaptor.getValue();
    assertThat(getTransUnitList.getCount(), Matchers.equalTo(5));
  }
コード例 #5
0
  @Test
  public void testOnFindMessage() throws Exception {
    service.init(initContext);

    service.onFindMessage(new FindMessageEvent("search"));

    verify(dispatcher, times(2)).execute(actionCaptor.capture(), resultCaptor.capture());
    GetTransUnitList getTransUnitList = actionCaptor.getValue();
    assertThat(getTransUnitList.getPhrase(), Matchers.equalTo("search"));
  }
コード例 #6
0
  @Test
  public void onPreviousEntry() {
    service.init(initContext);
    service.selectByRowIndex(2);
    service.onNavTransUnit(NavTransUnitEvent.PREV_ENTRY_EVENT);

    verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture());
    TableRowSelectedEvent tableRowSelectedEvent =
        TestFixture.extractFromEvents(eventCaptor.getAllValues(), TableRowSelectedEvent.class);
    assertThat(tableRowSelectedEvent.getSelectedId(), Matchers.equalTo(data.get(1).getId()));
  }
コード例 #7
0
  @Test
  public void onNavigationEventOnDifferentPage() {
    service.init(initContext);
    service.selectByRowIndex(0);

    service.onNavTransUnit(NavTransUnitEvent.LAST_ENTRY_EVENT);

    verify(dispatcher, times(2)).execute(actionCaptor.capture(), resultCaptor.capture());
    GetTransUnitList action = actionCaptor.getValue();
    assertThat(action.getOffset(), Matchers.equalTo(3));
    assertThat(action.getCount(), Matchers.equalTo(EDITOR_PAGE_SIZE));
    assertThat(action.getTargetTransUnitId(), Matchers.equalTo(data.get(data.size() - 1).getId()));
  }
コード例 #8
0
  @Test
  public void testOnTransUnitUpdatedNotInCurrentDocument() throws Exception {
    // Given: updated trans unit is from another document
    service.init(initContext);
    HasTransUnitUpdatedData updatedData =
        mock(HasTransUnitUpdatedData.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
    when(updatedData.getUpdateInfo().getDocumentId()).thenReturn(initContext.getDocumentId());

    // When:
    service.onTransUnitUpdated(new TransUnitUpdatedEvent(updatedData));

    // Then:
    verifyZeroInteractions(pageDataChangeListener);
  }
コード例 #9
0
  @BeforeMethod
  public void beforeMethod() {
    MockitoAnnotations.initMocks(this);
    initData();
    UserConfigHolder configHolder = new UserConfigHolder();
    configHolder.setEditorPageSize(EDITOR_PAGE_SIZE);
    SinglePageDataModelImpl pageModel = new SinglePageDataModelImpl();
    ModalNavigationStateHolder navigationStateHolder = new ModalNavigationStateHolder(configHolder);
    service =
        new NavigationService(
            eventBus,
            dispatcher,
            configHolder,
            mock(TableEditorMessages.class),
            pageModel,
            navigationStateHolder);
    service.addPageDataChangeListener(pageDataChangeListener);

    verify(eventBus).addHandler(DocumentSelectionEvent.getType(), service);
    verify(eventBus).addHandler(TransUnitUpdatedEvent.getType(), service);
    verify(eventBus).addHandler(FindMessageEvent.getType(), service);
    verify(eventBus).addHandler(NavTransUnitEvent.getType(), service);
    verify(eventBus).addHandler(EditorPageSizeChangeEvent.TYPE, service);

    pageModel.setData(data.subList(0, configHolder.getState().getEditorPageSize()));
    navigationStateHolder.init(idStateMap, idIndexList);
    initContext =
        new GetTransUnitActionContext(new DocumentId(1, ""))
            .changeCount(configHolder.getState().getEditorPageSize());
  }
コード例 #10
0
  @Test
  public void testOnDocumentSelected() throws Exception {
    DocumentId documentId = new DocumentId(2, "");
    service.onDocumentSelected(new DocumentSelectionEvent(documentId));

    verify(dispatcher).execute(actionCaptor.capture(), resultCaptor.capture());
    GetTransUnitList getTransUnitList = actionCaptor.getValue();
    assertThat(getTransUnitList.getDocumentId(), Matchers.equalTo(documentId));
  }
コード例 #11
0
 @Override
 public void onLoaded(WeatherForecast result) {
   if (!result.isSuccessed()) {
     Bundle data = new Bundle();
     data.putCharSequence(ErrorActivity.ERROR_DESCRIPTION, getString(R.string.no_cache));
     NavigationService.navigate(ForecastPageActivity.this, ErrorActivity.class);
     finish();
   }
   updateWeatherInfo(result);
 }
コード例 #12
0
  @Test
  public void testOnTransUnitUpdatedInCurrentPage() throws Exception {
    // Given: updated trans unit is from same document and it's on current page
    service.init(initContext);
    HasTransUnitUpdatedData updatedData =
        mock(HasTransUnitUpdatedData.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
    when(updatedData.getUpdateInfo().getDocumentId()).thenReturn(initContext.getDocumentId());
    TransUnit updatedTU = data.get(0);
    when(updatedData.getUpdateInfo().getTransUnit()).thenReturn(updatedTU);
    EditorClientId editorClientId = new EditorClientId("sessionId", 1);
    when(updatedData.getEditorClientId()).thenReturn(editorClientId);
    when(updatedData.getUpdateType()).thenReturn(TransUnitUpdated.UpdateType.WebEditorSave);

    // When:
    service.onTransUnitUpdated(new TransUnitUpdatedEvent(updatedData));

    // Then:
    verify(pageDataChangeListener)
        .refreshRow(updatedTU, editorClientId, TransUnitUpdated.UpdateType.WebEditorSave);
  }
コード例 #13
0
  @Test
  public void testOnTransUnitUpdatedNotInCurrentPage() throws Exception {
    // Given: updated trans unit is from same document but NOT on current page
    service.init(initContext);
    HasTransUnitUpdatedData updatedData =
        mock(HasTransUnitUpdatedData.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
    when(updatedData.getUpdateInfo().getDocumentId()).thenReturn(initContext.getDocumentId());
    // updated TU has something different so that we can assert it won't update current page data
    // model
    TransUnit updatedTU =
        TransUnit.Builder.from(data.get(data.size() - 1)).setSourceComment("different").build();
    when(updatedData.getUpdateInfo().getTransUnit()).thenReturn(updatedTU);

    // When:
    service.onTransUnitUpdated(new TransUnitUpdatedEvent(updatedData));

    // Then:
    verifyZeroInteractions(pageDataChangeListener);
    assertThat(
        data.get(data.size() - 1).getSourceComment(),
        Matchers.not(Matchers.equalTo(updatedTU.getSourceComment())));
  }
コード例 #14
0
 private boolean stateHasNotChanged(TransUnitSaveEvent event) {
   TransUnit transUnit = navigationService.getByIdOrNull(event.getTransUnitId());
   if (transUnit == null) {
     return false;
   }
   Log.info(
       "id:"
           + transUnit.getId()
           + " old contents: "
           + transUnit.getTargets()
           + " state: "
           + transUnit.getStatus());
   return Objects.equal(transUnit.getStatus(), event.getAdjustedStatus())
       && Objects.equal(transUnit.getTargets(), event.getTargets());
 }
コード例 #15
0
  @Test
  public void testUpdateDataModel() throws Exception {
    service.init(initContext);
    service.selectByRowIndex(0);
    assertThat(service.getSelectedOrNull().getStatus(), Matchers.equalTo(ContentState.Approved));

    service.updateDataModel(
        TestFixture.makeTransUnit(
            service.getSelectedOrNull().getId().getId(), ContentState.NeedReview));

    assertThat(service.getSelectedOrNull().getStatus(), Matchers.equalTo(ContentState.NeedReview));
  }
コード例 #16
0
  /**
   * Display confirmation dialog box if new status of TU has been changed to approved without any
   * content changes.
   */
  @Override
  public void onCheckStateHasChanged(CheckStateHasChangedEvent event) {
    TransUnit transUnit = navigationService.getByIdOrNull(event.getTransUnitId());
    if (transUnit == null) {
      return;
    }

    boolean targetChanged = !Objects.equal(transUnit.getTargets(), event.getTargets());
    boolean targetUnchangedButCanSaveAsApproved =
        (event.getAdjustedState() == ContentState.Translated)
            && !Objects.equal(transUnit.getStatus(), event.getAdjustedState());

    if (targetChanged) {
      targetContentsPresenter.saveAsApprovedAndMoveNext(event.getTransUnitId());
    } else if (targetUnchangedButCanSaveAsApproved) {
      targetContentsPresenter.showSaveAsApprovedConfirmation(event.getTransUnitId());
    } else {
      eventBus.fireEvent(NavTransUnitEvent.NEXT_ENTRY_EVENT);
    }
  }
コード例 #17
0
 @Test
 public void testGetCurrentPageValues() throws Exception {
   assertThat(service.getCurrentPageValues(), Matchers.equalTo(data.subList(0, EDITOR_PAGE_SIZE)));
 }