RequisitionFormViewHolder extends BaseViewHolder { public void populate(RequisitionFormItemViewModel entry, RnRForm.STATUS status) { productCode.setText(entry.getFmn()); productName.setText(entry.getProductName()); initAmount.setText(entry.getInitAmount()); received.setText(entry.getReceived()); issued.setText(entry.getIssued()); theoreticalInventory.setText(entry.getTheoretical()); total.setText(entry.getTotal()); inventory.setText(entry.getInventory()); different.setText(entry.getDifferent()); totalRequest.setText(entry.getAdjustedTotalRequest()); populateAdjustmentTheoreticalIcon(entry); if (LMISApp.getInstance().getFeatureToggleFor(R.bool.feature_training)) { fakePopulateRequestApprovedAmount(entry, status); } else { populateRequestApprovedAmount(entry, status); } } RequisitionFormViewHolder(View itemView); void populate(RequisitionFormItemViewModel entry, RnRForm.STATUS status);  }
@Test public void shouldHighLightRequestAmount() { viewHolder.populate(viewModel, RnRForm.STATUS.DRAFT); int bgReqColor = ((ColorDrawable) viewHolder.requestAmount.getBackground()).getColor(); int bgAprColor = ((ColorDrawable) viewHolder.approvedAmount.getBackground()).getColor(); assertThat(bgReqColor, is(RuntimeEnvironment.application.getApplicationContext().getResources().getColor(R.color.color_white))); assertThat(bgAprColor, is(RuntimeEnvironment.application.getApplicationContext().getResources().getColor(android.R.color.transparent))); assertThat(viewHolder.requestAmount.isEnabled(), is(true)); assertThat(viewHolder.approvedAmount.isEnabled(), is(false)); }
@Test public void shouldHighLightApprovedAmount() { viewHolder.populate(viewModel, RnRForm.STATUS.SUBMITTED); int bgReqColor = ((ColorDrawable) viewHolder.requestAmount.getBackground()).getColor(); int bgAprColor = ((ColorDrawable) viewHolder.approvedAmount.getBackground()).getColor(); assertThat(bgReqColor, is(RuntimeEnvironment.application.getApplicationContext().getResources().getColor(android.R.color.transparent))); assertThat(bgAprColor, is(RuntimeEnvironment.application.getApplicationContext().getResources().getColor(R.color.color_white))); assertThat(viewHolder.requestAmount.isEnabled(), is(false)); assertThat(viewHolder.approvedAmount.isEnabled(), is(true)); }
@Test public void shouldUpdateApprovedAmountWhenRequestAmountChanged() { viewHolder.populate(viewModel, RnRForm.STATUS.DRAFT); viewHolder.requestAmount.setText("123"); assertThat(viewModel.getRequestAmount(), is("123")); assertThat(viewModel.getApprovedAmount(), is("123")); assertThat(viewHolder.requestAmount.getText().toString(), is("123")); }
@Test public void shouldUpdateApprovedAmountModelWhenTextChanged() { viewHolder.populate(viewModel, RnRForm.STATUS.SUBMITTED); viewHolder.approvedAmount.setText("123"); assertThat(viewModel.getRequestAmount(), is("0")); assertThat(viewModel.getApprovedAmount(), is("123")); }
@Test public void shouldOnlyShowAdjustIconWhenAdjustmentQuantityIsNotZero() throws Exception { viewHolder.populate(viewModel, RnRForm.STATUS.DRAFT); assertThat(viewHolder.adjustTheoreticalIcon.getVisibility(), is(View.GONE)); viewModel.setAdjustmentViewModels(Arrays.asList(generateAdjustmentViewModel())); viewHolder.populate(viewModel, RnRForm.STATUS.DRAFT); assertThat(viewHolder.adjustTheoreticalIcon.getVisibility(), is(View.VISIBLE)); }
@Test public void shouldShowPopTipsTotalReminderIconClicked() { viewModel.setAdjustmentViewModels(Arrays.asList(generateAdjustmentViewModel())); viewHolder.populate(viewModel, RnRForm.STATUS.DRAFT); viewHolder.adjustTheoreticalIcon.performClick(); Fragment dialogFragment = dummyActivity.getFragmentManager().findFragmentByTag("adjustmentTheoreticalDialog"); assertNotNull(dialogFragment); }