TranslationCardItem extends LinearLayout { public void setTranslation(Translation translation, String language){ this.translation = translation; this.dictionaryLanguage = language; initState(); } TranslationCardItem(Context context);  TranslationCardItem(Context context, AttributeSet attrs);  TranslationCardItem(Context context, AttributeSet attrs, int defStyleAttr); void setTranslation(Translation translation, String language); void setTranslation(Translation translation, String language, int index); void setEditClickListener(OnClickListener listener); void setDeleteClickListener(OnClickListener listener); void setCardExpanded(boolean cardExpanded); void setShowDeleteAndEditOptions(boolean showDeleteAndEditOptions); void setGreyOutIfNoAudio(boolean greyOutIfNoAudio); Translation getTranslation(); static final int DISABLED_OPACITY; static final int DEFAULT_OPACITY; }
@Test public void shouldBeExpandedWhenExpandAttributeSetToTrue() { ArrayList<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute("org.mercycorps.translationcards:attr/expandedOnStart", String.valueOf(true), "org.mercycorps.translationcards")); AttributeSet attrs = new RoboAttributeSet(attributes, shadowOf(activity).getResourceLoader()); TranslationCardItem tc = new TranslationCardItem(RuntimeEnvironment.application, attrs); Translation translationItem = new Translation("First Translation", false, null, 1, "Translated Text"); tc.setTranslation(translationItem, "English"); assertEquals(View.VISIBLE, tc.findViewById(R.id.translation_child).getVisibility()); }
@Test public void shouldBeCollapsedWhenExpandAttributeSetToFalse() { ArrayList<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute("org.mercycorps.translationcards:attr/expandedOnStart", String.valueOf(false), "org.mercycorps.translationcards")); AttributeSet attrs = new RoboAttributeSet(attributes, shadowOf(activity).getResourceLoader()); TranslationCardItem tc = new TranslationCardItem(RuntimeEnvironment.application, attrs); Translation translationItem = new Translation("First Translation", false, null, 1, "Translated Text"); tc.setTranslation(translationItem, "English"); assertEquals(View.GONE, tc.findViewById(R.id.translation_child).getVisibility()); }
@Test public void shouldShowTranslationCardChildWhenTranslationServiceReturnsExpanded() { TranslationCardItem translationCardItem = getDefaultTranslationCard(); Translation translationItem = new Translation("First Translation", false, DEFAULT_AUDIO_FILE, 1, ""); when(translationService.cardIsExpanded(0)).thenReturn(true); translationCardItem.setTranslation(translationItem, DEFAULT_DICTIONARY_LABEL, 0); View childView = translationCardItem.findViewById(R.id.translation_child); assertEquals(View.VISIBLE, childView.getVisibility()); }
@Test public void shouldHideTranslationCardChildWhenTranslationServiceReturnsNotExpanded() { TranslationCardItem translationCardItem = getDefaultTranslationCard(); Translation translationItem = new Translation("First Translation", false, DEFAULT_AUDIO_FILE, 1, ""); when(translationService.cardIsExpanded(0)).thenReturn(false); translationCardItem.setTranslation(translationItem, DEFAULT_DICTIONARY_LABEL, 0); View childView = translationCardItem.findViewById(R.id.translation_child); assertEquals(View.GONE, childView.getVisibility()); }
@Test public void shouldCallLanguageServiceOnExpansionClick() { TranslationCardItem translationCardItem = getDefaultTranslationCard(); Translation translationItem = new Translation("First Translation", false, DEFAULT_AUDIO_FILE, 1, ""); when(translationService.cardIsExpanded(0)).thenReturn(false); translationCardItem.setTranslation(translationItem, DEFAULT_DICTIONARY_LABEL, 0); translationCardItem.findViewById(R.id.translation_indicator_layout).performClick(); verify(translationService).expandCard(0); }
@Test public void shouldHaveCorrectTextFormattingWhenTranslatedTextIsEmpty() { int disabledTextColor = ContextCompat.getColor(activity, R.color.textDisabled); TranslationCardItem translationsListItem = getDefaultTranslationCard(); Translation translationItem = new Translation("First Translation", false, DEFAULT_AUDIO_FILE, 1, ""); translationsListItem.setTranslation(translationItem, "English"); TextView translatedText = (TextView) translationsListItem.findViewById(R.id.translated_text); assertEquals(18f, translatedText.getTextSize()); assertEquals(disabledTextColor, translatedText.getCurrentTextColor()); }
@Test public void shouldCallLanguageServiceOnCollapseClick() { TranslationCardItem translationCardItem = getDefaultTranslationCard(); Translation translationItem = new Translation("First Translation", false, DEFAULT_AUDIO_FILE, 1, ""); when(translationService.cardIsExpanded(0)).thenReturn(true); translationCardItem.setTranslation(translationItem, DEFAULT_DICTIONARY_LABEL, 0); translationCardItem.findViewById(R.id.translation_indicator_layout).performClick(); verify(translationService).minimizeCard(0); }