ReportTooltipPresenter extends BaseViperPresenter<LegacyTooltipView, ReportTooltipInteractor<? extends FragmentActivity>> implements BackupProviderChangeListener { @Override public void subscribe() { backupProvidersManager.registerChangeListener(this); updateProvider(backupProvidersManager.getSyncProvider()); compositeDisposable.add(interactor.checkTooltipCauses() .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .subscribe(view::present)); compositeDisposable.add(view.getTooltipsClicks() .doOnNext(uiIndicator -> { Logger.info(ReportTooltipPresenter.this, "User clicked on {} tooltip", uiIndicator); if (uiIndicator.getState() == ReportTooltipUiIndicator.State.GenerateInfo) { analytics.record(Events.Informational.ClickedGenerateReportTip); } else if (uiIndicator.getState() == ReportTooltipUiIndicator.State.BackupReminder) { analytics.record(Events.Informational.ClickedBackupReminderTip); } }) .subscribe(uiIndicator -> { view.present(ReportTooltipUiIndicator.none()); if (uiIndicator.getState() == ReportTooltipUiIndicator.State.SyncError) { interactor.handleClickOnErrorTooltip(uiIndicator.getErrorType().get()); } else if (uiIndicator.getState() == ReportTooltipUiIndicator.State.GenerateInfo) { interactor.generateInfoTooltipClosed(); } else if (uiIndicator.getState() == ReportTooltipUiIndicator.State.BackupReminder) { interactor.backupReminderTooltipClosed(); } })); compositeDisposable.add(view.getCloseButtonClicks() .subscribe(uiIndicator -> { view.present(ReportTooltipUiIndicator.none()); if (uiIndicator.getState() == ReportTooltipUiIndicator.State.GenerateInfo) { interactor.generateInfoTooltipClosed(); } else if (uiIndicator.getState() == ReportTooltipUiIndicator.State.BackupReminder) { interactor.backupReminderTooltipClosed(); } else if (uiIndicator.getState() == ReportTooltipUiIndicator.State.ImportInfo) { interactor.importInfoTooltipClosed(); } })); } @SuppressWarnings("unchecked") @Inject  ReportTooltipPresenter(@NonNull LegacyTooltipView view,
                                  @NonNull ReportTooltipInteractor interactor,
                                  @NonNull BackupProvidersManager backupProvidersManager,
                                  @NonNull Analytics analytics); @SuppressWarnings("unchecked")  ReportTooltipPresenter(@NonNull LegacyTooltipView view,
                                  @NonNull ReportTooltipInteractor interactor,
                                  @NonNull BackupProvidersManager backupProvidersManager,
                                  @NonNull Analytics analytics,
                                  @NonNull Scheduler subscribeOnScheduler,
                                  @NonNull Scheduler observeOnScheduler); @Override void subscribe(); @Override void unsubscribe(); @Override void onProviderChanged(@NonNull SyncProvider newProvider);  }
@Test public void passErrorTooltipClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.syncError(errorType))); when(tooltipView.getTooltipsClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.syncError(errorType))); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.syncError(errorType)); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(tooltipView, never()).present(ReportTooltipUiIndicator.generateInfo()); verify(interactor).handleClickOnErrorTooltip(errorType); }
@Test public void passGenerateInfoTooltipClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.generateInfo())); when(tooltipView.getTooltipsClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.generateInfo())); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.generateInfo()); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor).generateInfoTooltipClosed(); }
@Test public void passGenerateInfoTooltipCloseClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.generateInfo())); when(tooltipView.getCloseButtonClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.generateInfo())); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.generateInfo()); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor).generateInfoTooltipClosed(); }
@Test public void passErrorTooltipCloseClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.syncError(errorType))); when(tooltipView.getCloseButtonClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.syncError(errorType))); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.syncError(errorType)); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor, never()).handleClickOnErrorTooltip(errorType); }
@Test public void passBackupTooltipClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.backupReminder(DAYS))); when(tooltipView.getTooltipsClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.backupReminder(DAYS))); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.backupReminder(DAYS)); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor).backupReminderTooltipClosed(); }
@Test public void passBackupTooltipCloseClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.backupReminder(DAYS))); when(tooltipView.getCloseButtonClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.backupReminder(DAYS))); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.backupReminder(DAYS)); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor).backupReminderTooltipClosed(); }
@Test public void passImportInfoTooltipCloseClicks() { when(interactor.checkTooltipCauses()).thenReturn(Observable.just(ReportTooltipUiIndicator.importInfo())); when(tooltipView.getCloseButtonClicks()).thenReturn(Observable.just(ReportTooltipUiIndicator.importInfo())); presenter.subscribe(); verify(tooltipView).present(ReportTooltipUiIndicator.importInfo()); verify(tooltipView).present(ReportTooltipUiIndicator.none()); verify(interactor).importInfoTooltipClosed(); }