MMIARequisitionFragment extends BaseReportFragment implements MMIARequisitionPresenter.MMIARequisitionView { @Override public void refreshRequisitionForm(RnRForm form) { scrollView.setVisibility(View.VISIBLE); List<RegimenItemThreeLines> regimeTypes = form.getRegimenThreeLineListWrapper(); rnrFormList.initView(form.getRnrFormItemListWrapper(), !(regimeTypes != null && !regimeTypes.isEmpty())); if (regimeTypes != null && !regimeTypes.isEmpty()) { mmiaRegimeThreeLineListView.initView(mmiaRegimeThreeLineTotal, mmiaRegimeThreeLinePharmacy, regimeTypes); } else { mmiaThreaPeuticLayout.setVisibility(View.GONE); tvRegimeTotalPharmacy.setVisibility(View.GONE); tvTotalPharmacyTitle.setVisibility(View.GONE); } regimeWrap.initView(tvRegimeTotal, tvRegimeTotalPharmacy, tvTotalPharmacyTitle, presenter); mmiaPatientInfoListView.initView(form.getBaseInfoItemListWrapper()); InflateFreezeHeaderView(); getActivity().setTitle(getString(R.string.label_mmia_title, DateUtil.formatDateWithoutYear(form.getPeriodBegin()), DateUtil.formatDateWithoutYear(form.getPeriodEnd()))); etComment.setText(form.getComments()); highlightTotalDifference(); bindListeners(); }  @Override void onCreate(Bundle savedInstanceState); @Override View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState); @Override void onViewCreated(View view, Bundle savedInstanceState); @Override void refreshRequisitionForm(RnRForm form); @NonNull Subscriber<Void> getOnSavedSubscriber(); @Override void showValidationAlert(); @Override void setProcessButtonName(String buttonName); @Override void completeSuccess(); @NonNull String getSignatureDialogTitle(); @Override void onActivityResult(int requestCode, int resultCode, Intent data); static final int REQUEST_FOR_CUSTOM_REGIME; }
@Test public void shouldInitRegimeAndMMIAListView() { ArrayList<RegimenItem> regimenItems = new ArrayList<>(); ArrayList<BaseInfoItem> baseInfoItems = new ArrayList<>(); form.setBaseInfoItemListWrapper(baseInfoItems); form.setRegimenItemListWrapper(regimenItems); mmiaRequisitionFragment.refreshRequisitionForm(form); verify(rnrFormList).initView(any(ArrayList.class), anyBoolean()); verify(regimeListWrap).initView(mmiaRequisitionFragment.tvRegimeTotal, mmiaRequisitionFragment.tvRegimeTotalPharmacy, mmiaRequisitionFragment.tvTotalPharmacyTitle, mmiaFormPresenter); verify(mmiaPatientInfoListView).initView(baseInfoItems); }
@Test public void shouldSetTitleWithPeriod() { form.setPeriodBegin(Date.valueOf("2015-04-21")); form.setPeriodEnd(Date.valueOf("2015-05-20")); mmiaRequisitionFragment.refreshRequisitionForm(form); assertThat(mmiaRequisitionFragment.getActivity().getTitle()).isEqualTo("MMIA - 21 Apr to 20 May"); }
@Test public void shouldDeHighLightWhenTotalMatches() { when(mmiaPatientInfoListView.getTotal()).thenReturn(20L); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); verify(regimeListWrap).deHighLightTotal(); verify(mmiaPatientInfoListView).deHighLightTotal(); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); }
@Test public void shouldDisplayRegimeThreeLine() { List<RegimenItemThreeLines> linesList = new ArrayList<>(); linesList.add(new RegimenItemThreeLines(0, getString(R.string.mmia_1stline))); linesList.add(new RegimenItemThreeLines(1, getString(R.string.mmia_2ndline))); linesList.add(new RegimenItemThreeLines(2, getString(R.string.mmia_3rdline))); form.setRegimenThreeLinesWrapper(linesList); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); verify(regimeListWrap).deHighLightTotal(); verify(mmiaPatientInfoListView).deHighLightTotal(); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); assertFalse(mmiaRequisitionFragment.mmiaRegimeThreeLineListView.isCompleted()); assertTrue(mmiaRequisitionFragment.mmiaRegimeThreeLineListView.hasEmptyField()); assertThat(mmiaRequisitionFragment.mmiaRegimeThreeLineListView.getDataList().size()).isEqualTo(3); assertThat(mmiaRequisitionFragment.mmiaRegimeThreeLineListView.getTotal(MMIARegimeThreeLineList.COUNTTYPE.PATIENTSAMOUNT)).isEqualTo(0); }
@Test public void shouldDeHighlightWhenTotalNotMatchesAndLessThanFiveWithEmptyField() { when(mmiaPatientInfoListView.getTotal()).thenReturn(40L); when(mmiaPatientInfoListView.hasEmptyField()).thenReturn(true); form.setComments("ab"); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); }
@Test public void shouldDeHighlightWhenTotalNotMatchesAndMoreThanFive() { when(mmiaPatientInfoListView.getTotal()).thenReturn(40L); when(mmiaPatientInfoListView.hasEmptyField()).thenReturn(false); form.setComments("abdasdsa"); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); }
@Test public void shouldDeHighlightWhenTotalMatchesAndCommentLengthLessThanFiveAndWithoutEmptyField() { when(mmiaPatientInfoListView.getTotal()).thenReturn(20L); when(mmiaPatientInfoListView.hasEmptyField()).thenReturn(false); mmiaRequisitionFragment.etComment.setText("ab"); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); }
@Test public void shouldDeHighlightWhenTotalMatchesWithoutEmptyField() { when(mmiaPatientInfoListView.getTotal()).thenReturn(20L); when(mmiaPatientInfoListView.hasEmptyField()).thenReturn(false); mmiaRequisitionFragment.etComment.setText("abcde"); mmiaRequisitionFragment.regimeWrap = regimeListWrap; mmiaRequisitionFragment.mmiaPatientInfoListView = mmiaPatientInfoListView; mmiaRequisitionFragment.refreshRequisitionForm(form); assertThat(mmiaRequisitionFragment.tvMismatch.getVisibility()).isEqualTo(View.INVISIBLE); }