mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-232 Sets | Enhancement | Pre-populate records, release brunch (#2561)
Co-authored-by: konstantiniiv <ki@anytype.io>
This commit is contained in:
parent
d768a96a09
commit
eceecee6a8
2 changed files with 128 additions and 1 deletions
|
@ -764,9 +764,11 @@ class ObjectSetViewModel(
|
|||
}
|
||||
|
||||
private fun resolvePrefilledRecordData(setOfObjects: ObjectSet): Map<Id, Any> = buildMap {
|
||||
val block = setOfObjects.dataview
|
||||
val dv = block.content as DV
|
||||
val viewer = setOfObjects.viewerById(session.currentViewerId)
|
||||
viewer.filters.forEach { filter ->
|
||||
val relation = reducer.state.value.relations.find { it.key == filter.relationKey }
|
||||
val relation = dv.relations.find { it.key == filter.relationKey }
|
||||
if (relation != null && !relation.isReadOnly) {
|
||||
if (filter.condition == DVFilterCondition.ALL_IN || filter.condition == DVFilterCondition.IN || filter.condition == DVFilterCondition.EQUAL) {
|
||||
filter.value?.let { put(filter.relationKey, it) }
|
||||
|
|
|
@ -3,7 +3,12 @@ package com.anytypeio.anytype.presentation.sets.main
|
|||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.DV
|
||||
import com.anytypeio.anytype.core_models.DVFilter
|
||||
import com.anytypeio.anytype.core_models.DVFilterCondition
|
||||
import com.anytypeio.anytype.core_models.DVFilterOperator
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerRelation
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewRecord
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
|
@ -319,4 +324,124 @@ class ObjectSetRecordCreateTest : ObjectSetViewModelTestSetup() {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should create new pre-populated record - when filter has all_in condition`() {
|
||||
`create pre-populated record`(DVFilterCondition.ALL_IN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should create new pre-populated record - when filter has in condition`() {
|
||||
`create pre-populated record`(DVFilterCondition.IN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should create new pre-populated record - when filter has equal condition`() {
|
||||
`create pre-populated record`(DVFilterCondition.EQUAL)
|
||||
}
|
||||
|
||||
private fun `create pre-populated record`(condition: DVFilterCondition) {
|
||||
|
||||
// SETUP
|
||||
|
||||
val relationStakeholderKey = MockDataFactory.randomUuid()
|
||||
val relationStakeholderValue = MockDataFactory.randomString()
|
||||
|
||||
val relationStakeHolders = Relation(
|
||||
key = relationStakeholderKey,
|
||||
defaultValue = null,
|
||||
isHidden = false,
|
||||
isReadOnly = false,
|
||||
isMulti = true,
|
||||
name = MockDataFactory.randomString(),
|
||||
source = Relation.Source.values().random(),
|
||||
format = Relation.Format.OBJECT,
|
||||
selections = emptyList()
|
||||
)
|
||||
|
||||
val givenTemplate = MockDataFactory.randomUuid()
|
||||
|
||||
val source = MockDataFactory.randomString()
|
||||
|
||||
val filter = DVFilter(
|
||||
relationKey = relationStakeholderKey,
|
||||
operator = DVFilterOperator.AND,
|
||||
condition = condition,
|
||||
value = relationStakeholderValue,
|
||||
)
|
||||
|
||||
val viewerRelationName = DVViewerRelation(
|
||||
key = MockDataFactory.randomString(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRelationStakeHolder = DVViewerRelation(
|
||||
key = relationStakeholderKey,
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewer = DVViewer(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
filters = listOf(filter),
|
||||
sorts = emptyList(),
|
||||
type = Block.Content.DataView.Viewer.Type.GRID,
|
||||
name = MockDataFactory.randomString(),
|
||||
viewerRelations = listOf(viewerRelationName, viewerRelationStakeHolder)
|
||||
)
|
||||
|
||||
val dv = Block(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
content = DV(
|
||||
sources = listOf(source),
|
||||
relations = listOf(relationStakeHolders),
|
||||
viewers = listOf(viewer)
|
||||
),
|
||||
children = emptyList(),
|
||||
fields = Block.Fields.empty()
|
||||
)
|
||||
|
||||
stubInterceptEvents()
|
||||
stubSetActiveViewer()
|
||||
stubCreateDataViewRecord()
|
||||
stubInterceptThreadStatus()
|
||||
stubGetTemplates(
|
||||
type = source,
|
||||
templates = listOf(givenTemplate)
|
||||
)
|
||||
stubOpenObjectSet(
|
||||
doc = listOf(
|
||||
header,
|
||||
title,
|
||||
dv
|
||||
),
|
||||
details = Block.Details(
|
||||
mapOf(
|
||||
root to Block.Fields(
|
||||
map = mapOf(
|
||||
Relations.SET_OF to listOf(source)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val vm = givenViewModel()
|
||||
|
||||
// TESTING
|
||||
|
||||
vm.onStart(root)
|
||||
|
||||
vm.onCreateNewRecord()
|
||||
|
||||
verifyBlocking(createDataViewRecord, times(1)) {
|
||||
invoke(
|
||||
CreateDataViewRecord.Params(
|
||||
context = root,
|
||||
target = dv.id,
|
||||
template = givenTemplate,
|
||||
prefilled = mapOf(relationStakeholderKey to relationStakeholderValue)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue