1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DV | Feature | Relation number, date value (#1492)

* rename method

* date + input filter fixes

* fix tests

* test fix

* filter date value format fix
This commit is contained in:
Konstantin Ivanov 2021-05-25 13:49:15 +02:00 committed by GitHub
parent 3300442bbf
commit 4335499432
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 258 additions and 111 deletions

View file

@ -311,12 +311,13 @@ class ModifyInputValueFilterTest {
// Veryfying that the appropriate request was made
val value = (initialFilterText + textToType).toDouble()
verifyBlocking(repo, times(1)) {
updateDataViewViewer(
context = root,
target = dv.id,
viewer = viewer.copy(
filters = listOf(filter.copy(value = initialFilterText + textToType))
filters = listOf(filter.copy(value = value))
)
)
}

View file

@ -24,6 +24,6 @@ class FilterDateViewHolder(view: View) : FilterViewHolder(view) {
condition = item.condition.title,
format = item.format
)
tvValue.text = item.filterValue.value.formatTimestamp(isMillis = false)
tvValue.text = item.filterValue.value?.formatTimestamp(isMillis = true)
}
}

View file

@ -331,14 +331,6 @@ fun Relation.toEmail(value: Any?): String? =
throw IllegalArgumentException("Text relation format $format value should be String, actual:$value")
}
fun Relation.toDate(value: Any?): Long =
if (value is Double?) {
val date = value
date?.toLong() ?: EMPTY_TIMESTAMP
} else {
throw IllegalArgumentException("Relation format $format value should be Double, actual:$value")
}
fun Relation.toCheckbox(value: Any?): Boolean? =
if (value is Boolean?) {
value
@ -489,7 +481,7 @@ fun DVFilter.toView(
title = relation.name,
operator = operator.toView(),
condition = condition.toNumberView(),
filterValue = FilterValue.Date(relation.toDate(value)),
filterValue = FilterValue.Date(DateParser.parse(value)),
format = relation.format.toView(),
isValueRequired = condition.isValueRequired(),
isInEditMode = isInEditMode
@ -557,7 +549,7 @@ fun Relation.toFilterValue(
Relation.Format.NUMBER -> FilterValue.Number(NumberParser.parse(value))
Relation.Format.STATUS -> FilterValue.Status(toStatus(value))
Relation.Format.TAG -> FilterValue.Tag(toTags(value))
Relation.Format.DATE -> FilterValue.Date(toDate(value))
Relation.Format.DATE -> FilterValue.Date(DateParser.parse(value))
Relation.Format.URL -> FilterValue.Url(toText(value))
Relation.Format.EMAIL -> FilterValue.Email(toText(value))
Relation.Format.PHONE -> FilterValue.Phone(toText(value))

View file

@ -4,8 +4,10 @@ import com.anytypeio.anytype.core_models.*
import com.anytypeio.anytype.core_utils.const.DateConst
import com.anytypeio.anytype.core_utils.ext.isWhole
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.presentation.extension.hasValue
import com.anytypeio.anytype.presentation.sets.*
import com.anytypeio.anytype.presentation.sets.model.ColumnView
import com.anytypeio.anytype.presentation.sets.model.Viewer
import java.sql.Date
import java.text.SimpleDateFormat
import java.util.*
@ -64,7 +66,7 @@ fun Relation.view(
// see {SetsExtension:buildGridRow()}
val format = SimpleDateFormat(DateConst.DEFAULT_DATE_FORMAT, Locale.getDefault())
val value = values[relation.key]
val timeInMillis = value.convertToRelationDateValue()
val timeInMillis = DateParser.parse(value)
val formattedDate = if (timeInMillis != null) {
format.format(Date(timeInMillis))
} else {
@ -144,18 +146,35 @@ fun Relation.searchObjectsFilter(): List<DVFilter> {
return filter.toList()
}
object FilterInputValueParser {
fun parse(
value: String?,
format: ColumnView.Format,
condition: Viewer.Filter.Condition
): Any? = when (format) {
ColumnView.Format.NUMBER -> {
if (condition.hasValue()) value?.toDoubleOrNull() else null
}
else -> {
if (condition.hasValue()) value else null
}
}
}
/**
* Converts relation {format DATE} value {Any?} to time in millis {Long} or null
* @tests [RelationValueExtensionTest]
*/
fun Any?.convertToRelationDateValue(): Long? {
val timeInMillis: Long? = when (this) {
is String -> this.toLongOrNull()
is Double -> this.toLong()
is Long -> this
else -> null
object DateParser {
fun parse(value: Any?): Long? {
val timeInMillis: Long? = when (value) {
is String -> value.toLongOrNull()
is Double -> value.toLong()
is Long -> value
else -> null
}
return timeInMillis?.times(1000)
}
return timeInMillis?.times(1000)
}
/**

View file

@ -4,10 +4,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_utils.const.DateConst
import com.anytypeio.anytype.core_utils.const.DateConst.DEFAULT_DATE_FORMAT
import com.anytypeio.anytype.core_utils.ext.*
import com.anytypeio.anytype.presentation.relations.convertToRelationDateValue
import com.anytypeio.anytype.presentation.relations.DateParser
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider
import kotlinx.coroutines.flow.MutableSharedFlow
@ -29,7 +28,7 @@ class RelationDateValueViewModel(
val relation = relations.get(relationId)
val value = values.get(objectId)
setName(relation.name)
val timeInMillis = value[relationId].convertToRelationDateValue()
val timeInMillis = DateParser.parse(value[relationId])
setDate(timeInSeconds = timeInMillis?.toTimeSecondsLong())
}

View file

@ -3,7 +3,6 @@ package com.anytypeio.anytype.presentation.sets
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_utils.ext.isWhole
import com.anytypeio.anytype.core_utils.ext.typeOf
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.presentation.relations.*
@ -49,7 +48,7 @@ fun List<ColumnView>.buildGridRow(
CellView.Date(
id = record[ObjectSetConfig.ID_KEY] as String,
key = column.key,
timeInMillis = value.convertToRelationDateValue(),
timeInMillis = DateParser.parse(value),
dateFormat = column.getDateRelationFormat()
)
}

View file

@ -339,12 +339,19 @@ open class FilterViewModel(
fun onCreateInputValueFilterClicked(ctx: Id, relation: Id, input: String) {
val condition = conditionState.value?.condition
checkNotNull(condition)
val format = relationState.value?.format
checkNotNull(format)
val value = FilterInputValueParser.parse(
value = input,
condition = condition,
format = format
)
viewModelScope.launch {
proceedWithCreatingFilter(
ctx = ctx,
filter = DVFilter(
relationKey = relation,
value = if (condition.hasValue()) input else "",
value = value,
condition = condition.toDomain()
)
)
@ -454,6 +461,13 @@ open class FilterViewModel(
checkNotNull(relation)
val idx = filterIndex
checkNotNull(idx)
val format = relationState.value?.format
checkNotNull(format)
val value = FilterInputValueParser.parse(
value = input,
condition = condition,
format = format
)
viewModelScope.launch {
val block = objectSetState.value.dataview
val dv = block.content as DV
@ -466,7 +480,7 @@ open class FilterViewModel(
updatedFilter = DVFilter(
relationKey = relation,
condition = condition.toDomain(),
value = if (condition.hasValue()) input else ""
value = value
)
)
}

View file

@ -61,8 +61,8 @@ sealed class FilterValue : Parcelable {
}
@Parcelize
data class Date(val value: Long) : FilterValue() {
fun isEmpty(): Boolean = this == empty()
data class Date(val value: Long?) : FilterValue() {
fun isEmpty(): Boolean = this.value == null || this == empty()
companion object {
fun empty() = Date(0L)

View file

@ -3,7 +3,7 @@ package com.anytypeio.anytype.presentation.extension
import MockDataFactory
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_utils.const.DateConst
import com.anytypeio.anytype.presentation.relations.convertToRelationDateValue
import com.anytypeio.anytype.presentation.relations.DateParser
import com.anytypeio.anytype.presentation.relations.getDateRelationFormat
import com.anytypeio.anytype.presentation.sets.model.ColumnView
import org.junit.Assert.assertNotNull
@ -19,7 +19,7 @@ class RelationValueExtensionTest {
val value: Any? = null
val result = value.convertToRelationDateValue()
val result = DateParser.parse(value)
assertNull(result)
}
@ -29,7 +29,7 @@ class RelationValueExtensionTest {
val value: Any = "t123"
val result = value.convertToRelationDateValue()
val result = DateParser.parse(value)
assertNull(result)
}
@ -39,7 +39,7 @@ class RelationValueExtensionTest {
val value: Any = "1621596602"
val result: Long? = value.convertToRelationDateValue()
val result: Long? = DateParser.parse(value)
val expected: Long = 1621596602000L
@ -56,7 +56,7 @@ class RelationValueExtensionTest {
val value: Any = 1621596602.0
val result: Long? = value.convertToRelationDateValue()
val result: Long? = DateParser.parse(value)
val expected: Long = 1621596602000L
@ -73,7 +73,7 @@ class RelationValueExtensionTest {
val value: Any = 1621596602L
val result: Long? = value.convertToRelationDateValue()
val result: Long? = DateParser.parse(value)
val expected: Long = 1621596602000L
@ -90,7 +90,7 @@ class RelationValueExtensionTest {
val value: Any = 1621596602
val result: Long? = value.convertToRelationDateValue()
val result: Long? = DateParser.parse(value)
assertNull(result)
}

View file

@ -6,6 +6,7 @@ import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.DVFilter
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.domain.config.Gateway
import com.anytypeio.anytype.domain.dataview.interactor.SearchObjects
import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
@ -22,8 +23,7 @@ import org.junit.Rule
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
import org.mockito.kotlin.*
class FilterViewModelInputFieldValueCreateTest {
@ -164,47 +164,47 @@ class FilterViewModelInputFieldValueCreateTest {
//region LONG TEXT
@Test
fun `should empty string value, long text 1`() {
fun `should null string value, long text 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation1.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, long text 2`() {
fun `should null string value, long text 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation1.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, long text 3`() {
fun `should null string value, long text 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation1.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, long text 4`() {
fun `should null string value, long text 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation1.key, condition, textInput, filterIndex)
}
@Test
@ -255,47 +255,47 @@ class FilterViewModelInputFieldValueCreateTest {
//region SHORT TEXT
@Test
fun `should empty string value, short text 1`() {
fun `should null string value, short text 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation3.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation3.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, short text 2`() {
fun `should null string value, short text 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation3.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation3.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, short text 3`() {
fun `should null string value, short text 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation3.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation3.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, short text 4`() {
fun `should null string value, short text 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation3.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation3.key, condition, textInput, filterIndex)
}
@Test
@ -345,137 +345,185 @@ class FilterViewModelInputFieldValueCreateTest {
//region NUMBER
@Test
fun `should empty string value, number 1`() {
fun `should null string value, number 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation2.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation2.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, number 2`() {
fun `should null string value, number 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation2.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation2.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, number 3`() {
fun `should null string value, number 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation2.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation2.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, number 4`() {
fun `should null string value, number 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation2.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation2.key, condition, textInput, filterIndex)
}
@Test
fun `should not empty string value, number 1`() {
fun `should send null, number 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Equal()
val textInput = NOT_EMPTY_STRING
val textInput = ""
val filterIndex = null
shouldSendFilterValueAsNotEmptyString(relation2.key, condition, textInput, filterIndex)
val value: Double? = null
shouldSendFilterValueAsAny(
relationKey = relation2.key,
condition = condition,
textInput = textInput,
value = value,
filterIndex = filterIndex)
}
@Test
fun `should not empty string value, number 2`() {
fun `should send double, number 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEqual()
val textInput = NOT_EMPTY_STRING
val condition = Viewer.Filter.Condition.Text.Equal()
val textInput = "1.01"
val filterIndex = null
shouldSendFilterValueAsNotEmptyString(relation2.key, condition, textInput, filterIndex)
val value = 1.01
shouldSendFilterValueAsAny(
relationKey = relation2.key,
condition = condition,
textInput = textInput,
value = value,
filterIndex = filterIndex)
}
@Test
fun `should not empty string value, number 3`() {
fun `should send negative double, number 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Like()
val textInput = NOT_EMPTY_STRING
val condition = Viewer.Filter.Condition.Text.Equal()
val textInput = "-3.0"
val filterIndex = null
shouldSendFilterValueAsNotEmptyString(relation2.key, condition, textInput, filterIndex)
val value = -3.0
shouldSendFilterValueAsAny(
relationKey = relation2.key,
condition = condition,
textInput = textInput,
value = value,
filterIndex = filterIndex)
}
@Test
fun `should not empty string value, number 4`() {
fun `should send negative double, number 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotLike()
val textInput = NOT_EMPTY_STRING
val condition = Viewer.Filter.Condition.Text.Equal()
val textInput = "-4"
val filterIndex = null
shouldSendFilterValueAsNotEmptyString(relation2.key, condition, textInput, filterIndex)
val value = -4.0
shouldSendFilterValueAsAny(
relationKey = relation2.key,
condition = condition,
textInput = textInput,
value = value,
filterIndex = filterIndex)
}
@Test
fun `should send null, number 5`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Equal()
val textInput = "e1.0"
val filterIndex = null
val value = null
shouldSendFilterValueAsAny(
relationKey = relation2.key,
condition = condition,
textInput = textInput,
value = value,
filterIndex = filterIndex)
}
//endregion
//region URL
@Test
fun `should empty string value, url 1`() {
fun `should null string value, url 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation4.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation4.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, url 2`() {
fun `should null string value, url 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation4.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation4.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, url 3`() {
fun `should null string value, url 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation4.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation4.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, url 4`() {
fun `should null string value, url 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation4.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation4.key, condition, textInput, filterIndex)
}
@Test
@ -525,47 +573,47 @@ class FilterViewModelInputFieldValueCreateTest {
//region EMAIL
@Test
fun `should empty string value, email 1`() {
fun `should null string value, email 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation5.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation5.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, email 2`() {
fun `should null string value, email 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation5.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation5.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, email 3`() {
fun `should null string value, email 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation5.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation5.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, email 4`() {
fun `should null string value, email 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation5.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation5.key, condition, textInput, filterIndex)
}
@Test
@ -615,47 +663,47 @@ class FilterViewModelInputFieldValueCreateTest {
//region PHONE
@Test
fun `should empty string value, phone 1`() {
fun `should null string value, phone 1`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation6.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation6.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, phone 2`() {
fun `should null string value, phone 2`() {
//INIT
val condition = Viewer.Filter.Condition.Text.Empty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation6.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation6.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, phone 3`() {
fun `should null string value, phone 3`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation6.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation6.key, condition, textInput, filterIndex)
}
@Test
fun `should empty string value, phone 4`() {
fun `should null string value, phone 4`() {
//INIT
val condition = Viewer.Filter.Condition.Text.NotEmpty()
val textInput = NOT_EMPTY_STRING
val filterIndex = null
shouldSendFilterValueAsEmptyString(relation6.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNull(relation6.key, condition, textInput, filterIndex)
}
@Test
@ -703,12 +751,14 @@ class FilterViewModelInputFieldValueCreateTest {
}
//endregion
private fun shouldSendFilterValueAsEmptyString(
private fun shouldSendFilterValueAsNull(
relationKey: String,
condition: Viewer.Filter.Condition,
textInput: String,
filterIndex: Int?
) {
stubUpdateDataView()
viewModel.onStart(
relationId = relation1.key,
filterIndex = filterIndex
@ -735,7 +785,7 @@ class FilterViewModelInputFieldValueCreateTest {
relationKey = relationKey,
operator = DEFAULT_OPERATOR,
condition = condition.toDomain(),
value = EMPTY_STRING
value = null
)
)
)
@ -750,6 +800,8 @@ class FilterViewModelInputFieldValueCreateTest {
textInput: String,
filterIndex: Int?
) {
stubUpdateDataView()
viewModel.onStart(
relationId = relation1.key,
filterIndex = filterIndex
@ -785,6 +837,61 @@ class FilterViewModelInputFieldValueCreateTest {
}
}
private fun shouldSendFilterValueAsAny(
relationKey: String,
condition: Viewer.Filter.Condition,
textInput: String,
filterIndex: Int?,
value: Any?
) {
stubUpdateDataView()
viewModel.onStart(
relationId = relationKey,
filterIndex = filterIndex
)
viewModel.onConditionUpdate(condition)
viewModel.onCreateInputValueFilterClicked(
ctx = root,
relation = relationKey,
input = textInput
)
val viewer = state.value.viewers[0]
verifyBlocking(updateDataViewViewer, times(1)) {
invoke(
UpdateDataViewViewer.Params(
context = root,
target = dataViewId,
viewer = viewer.copy(
filters = listOf(
DVFilter(
relationKey = relationKey,
operator = DEFAULT_OPERATOR,
condition = condition.toDomain(),
value = value
)
)
)
)
)
}
}
private fun stubUpdateDataView() {
updateDataViewViewer.stub {
onBlocking { invoke(any()) } doReturn Either.Right(
Payload(
context = "",
events = emptyList()
)
)
}
}
companion object {
const val EMPTY_STRING = ""
const val NOT_EMPTY_STRING = "not empty"

View file

@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.sets.filter
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.*
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.domain.config.Gateway
import com.anytypeio.anytype.domain.dataview.interactor.SearchObjects
import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
@ -18,8 +19,7 @@ import org.junit.Rule
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
import org.mockito.kotlin.*
class FilterViewModelInputFieldValueModifyTest {
@ -175,7 +175,7 @@ class FilterViewModelInputFieldValueModifyTest {
val textInput = EMPTY_STRING
val filterIndex = 0
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNullString(relation1.key, condition, textInput, filterIndex)
}
@Test
@ -186,7 +186,7 @@ class FilterViewModelInputFieldValueModifyTest {
val textInput = NOT_EMPTY_STRING
val filterIndex = 0
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNullString(relation1.key, condition, textInput, filterIndex)
}
@Test
@ -197,7 +197,7 @@ class FilterViewModelInputFieldValueModifyTest {
val textInput = EMPTY_STRING
val filterIndex = 0
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNullString(relation1.key, condition, textInput, filterIndex)
}
@Test
@ -208,7 +208,7 @@ class FilterViewModelInputFieldValueModifyTest {
val textInput = NOT_EMPTY_STRING
val filterIndex = 0
shouldSendFilterValueAsEmptyString(relation1.key, condition, textInput, filterIndex)
shouldSendFilterValueAsNullString(relation1.key, condition, textInput, filterIndex)
}
@Test
@ -257,12 +257,14 @@ class FilterViewModelInputFieldValueModifyTest {
//endregion
private fun shouldSendFilterValueAsEmptyString(
private fun shouldSendFilterValueAsNullString(
relationKey: String,
condition: Viewer.Filter.Condition,
textInput: String,
filterIndex: Int?
) {
stubUpdateDataView()
viewModel.onStart(
relationId = relation1.key,
filterIndex = filterIndex
@ -288,7 +290,7 @@ class FilterViewModelInputFieldValueModifyTest {
relationKey = relationKey,
operator = DEFAULT_OPERATOR,
condition = condition.toDomain(),
value = EMPTY_STRING
value = null
)
)
)
@ -303,6 +305,9 @@ class FilterViewModelInputFieldValueModifyTest {
textInput: String,
filterIndex: Int?
) {
stubUpdateDataView()
viewModel.onStart(
relationId = relation1.key,
filterIndex = filterIndex
@ -337,6 +342,17 @@ class FilterViewModelInputFieldValueModifyTest {
}
}
private fun stubUpdateDataView() {
updateDataViewViewer.stub {
onBlocking { invoke(any()) } doReturn Either.Right(
Payload(
context = "",
events = emptyList()
)
)
}
}
companion object {
const val EMPTY_STRING = ""
const val NOT_EMPTY_STRING = "not empty"