FillTheFormDialogModel { public void showDialog(@EventType int modelEventType, List<ConfigurationItem> selectedConfigurationItems) { if (isDialogVisible() && isFastModeEnabled() && modelEventType == EVENT_TYPE_VIEW_LONG_CLICKED) { return; } else if (!isDialogVisible() && (modelEventType == EVENT_TYPE_VIEW_CLICKED || modelEventType == EVENT_TYPE_VIEW_FOCUSED)) { return; } helper.clearConfigurationVariables(); setSortedConfigurationItems(selectedConfigurationItems); if (!isDialogVisible()) { setExpandIconVisible(true); setDialogVisible(true); notifyPropertyChanged(PROPERTY_DIALOG_INITIAL_POSITION); } notifyPropertyChanged(PROPERTY_DATA_SET); notifyPropertyChanged(PROPERTY_DATA_SET_SCROLL_POSITION); if (isFastModeEnabled() || modelEventType == EVENT_TYPE_VIEW_LONG_CLICKED) { setSelectedConfigItem(sortedConfigurationItems.get(0)); actionCallbacks.setText(getSelectedConfigItemValue()); notifyPropertyChanged(PROPERTY_DATA_SET); } } FillTheFormDialogModel(FillTheFormDialogModelHelper helper); void setActionCallbacks(ActionCallbacks actionCallbacks); void onConfigurationItemClicked(int position); void onConfigurationItemLongClicked(int position); void onRemoveItemButtonClicked(int position); void setProfiles(List<String> profiles); void selectNextProfile(); List<ConfigurationItem> getSortedConfigurationItems(); int getItemsCount(); @ViewType int getSortedConfigItemType(int position); ConfigurationItem getConfigurationItem(int position); void setDialogPosition(int x, int y); int getDialogPositionX(); int getDialogPositionY(); void onActionMove(float x, float y); void onActionUp(); void setInitialTouchEvent(float x, float y); void setInitialDialogPosition(int x, int y); void setScreenDimensions(int screenWidth, int screenHeight); void setStatusBarHeight(int statusBarHeight); void setExpandedDialogDimensions(int expandedDialogWidth, int expandedDialogHeight); int getExpandedDialogWidth(); int getExpandedDialogHeight(); void setNormalDialogDimensions(int normalDialogWidth, int normalDialogHeight); int getNormalDialogWidth(); int getNormalDialogHeight(); void showDialog(@EventType int modelEventType, List<ConfigurationItem> selectedConfigurationItems); boolean isDialogVisible(); void hideDialog(); boolean isDialogExpanded(); void onCloseButtonClicked(); void onMinimizeButtonClicked(); void onOpenFillTheFormAppButtonClicked(); boolean isExpandIconVisible(); void toggleFastMode(); void setFastModeEnabled(boolean enabled); boolean isFastModeEnabled(); void setPropertyChangedListener(PropertyChangedListener propertyChangedListener); static final int EVENT_TYPE_UNKNOWN; static final int EVENT_TYPE_VIEW_LONG_CLICKED; static final int EVENT_TYPE_VIEW_CLICKED; static final int EVENT_TYPE_VIEW_FOCUSED; static final int VIEW_TYPE_SELECTED_ITEM; static final int VIEW_TYPE_NORMAL_ITEM; static final int VIEW_TYPE_REMOVABLE_ITEM; static final String PROPERTY_EXPAND_ICON; static final String PROPERTY_EXPAND_ICON_FAST_MODE; static final String PROPERTY_DIALOG_VISIBILITY; static final String PROPERTY_DIALOG_EXPANDED; static final String PROPERTY_DIALOG_POSITION; static final String PROPERTY_DIALOG_INITIAL_POSITION; static final String PROPERTY_FAST_MODE_BUTTON_ICON; static final String PROPERTY_DATA_SET; static final String PROPERTY_DATA_SET_SCROLL_POSITION; }
@Test public void testGetSelectedConfigItemValueShouldReturnRandomValueForFirstName() throws Exception { List<ConfigurationItem> selectedConfigurationItems = new ArrayList<>(); selectedConfigurationItems.add(new ConfigurationItem("first_name", "myprofile", "random_first_name")); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(eq("Luke")); }
@Test public void testSelectedItemValueShouldAlternate() throws Exception { List<ConfigurationItem> selectedConfigurationItems = new ArrayList<>(); selectedConfigurationItems.add(new ConfigurationItem("first_name", "myprofile", "&random_first_name;")); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(eq("Luke")); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(eq("Peter")); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(2)).setText(eq("Luke")); }
@Test public void testItemShouldBeSelectedTwiceAfterTwoLongClicksInNormalMode() throws Exception { List<ConfigurationItem> selectedConfigurationItems = createSelectedConfigurationItemsForFirstName(); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(anyString()); verify(propertyChangedListener, times(2)).onPropertyChanged(FillTheFormDialogModel.PROPERTY_DATA_SET); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(2)).setText(anyString()); verify(propertyChangedListener, times(4)).onPropertyChanged(FillTheFormDialogModel.PROPERTY_DATA_SET); }
@Test public void testItemShouldBeSelectedOnceAfterLongClickThenFocusChangeAndClickInNormalMode() throws Exception { List<ConfigurationItem> selectedConfigurationItems = createSelectedConfigurationItemsForFirstName(); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_LONG_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(anyString()); verify(propertyChangedListener, times(2)).onPropertyChanged(FillTheFormDialogModel.PROPERTY_DATA_SET); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_CLICKED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(anyString()); verify(propertyChangedListener, times(3)).onPropertyChanged(FillTheFormDialogModel.PROPERTY_DATA_SET); model.showDialog(FillTheFormDialogModel.EVENT_TYPE_VIEW_FOCUSED, selectedConfigurationItems); verify(actionCallbacks, times(1)).setText(anyString()); verify(propertyChangedListener, times(4)).onPropertyChanged(FillTheFormDialogModel.PROPERTY_DATA_SET); }