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

DROID-885 Set | Enhancement | Change source logic (#2869)

* DROID-885 remove source from data view model + fix tests

* DROID-885 update from SetSource Event to blockDataviewTargetObjectIdSet

* DROID-885 fix tests

* DROID-885 SetTargetObjectId event

* DROID-885 get set of from set details + test

* DROID-885 inline set, deleted source view state

* DROID-885 editor blockView setTargetObjectId, event

* DROID-885 fix test + stub

* DROID-885 stub added

* DROID-885 test

* DROID-885 rename

* DROID-885 pr fix
This commit is contained in:
Konstantin Ivanov 2023-01-27 16:33:20 +01:00 committed by GitHub
parent aa58ae4d04
commit 87a2b73e8a
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 493 additions and 382 deletions

View file

@ -162,10 +162,7 @@ class AddRelationStatusValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -243,10 +240,7 @@ class AddRelationStatusValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -338,10 +332,7 @@ class AddRelationStatusValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -432,10 +423,7 @@ class AddRelationStatusValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -535,10 +523,7 @@ class AddRelationStatusValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)

View file

@ -158,10 +158,7 @@ class AddRelationTagValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -271,10 +268,7 @@ class AddRelationTagValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -365,10 +359,7 @@ class AddRelationTagValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
@ -468,10 +459,7 @@ class AddRelationTagValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)

View file

@ -118,10 +118,7 @@ class DisplayObjectRelationTextValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
),
@ -196,10 +193,7 @@ class DisplayObjectRelationTextValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
),
@ -276,10 +270,7 @@ class DisplayObjectRelationTextValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
),
@ -356,10 +347,7 @@ class DisplayObjectRelationTextValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
),
@ -434,10 +422,7 @@ class DisplayObjectRelationTextValueTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)
),
@ -514,9 +499,7 @@ class DisplayObjectRelationTextValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -127,9 +127,7 @@ class DisplayRelationNumberValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -200,9 +198,7 @@ class DisplayRelationNumberValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -273,9 +269,7 @@ class DisplayRelationNumberValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -161,9 +161,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -238,9 +236,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -310,9 +306,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -412,9 +406,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -542,9 +534,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -662,9 +652,7 @@ class DisplayRelationObjectValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -156,9 +156,7 @@ class DisplayRelationStatusValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -231,9 +229,7 @@ class DisplayRelationStatusValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -326,9 +322,7 @@ class DisplayRelationStatusValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -407,9 +401,7 @@ class DisplayRelationStatusValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -498,9 +490,7 @@ class DisplayRelationStatusValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -154,9 +154,7 @@ class DisplayRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -229,9 +227,7 @@ class DisplayRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -324,9 +320,7 @@ class DisplayRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -414,9 +408,7 @@ class DisplayRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -505,9 +497,7 @@ class DisplayRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -183,9 +183,7 @@ class EditRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -301,9 +299,7 @@ class EditRelationTagValueTest {
)
),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -108,9 +108,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -179,9 +177,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -251,9 +247,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -323,9 +317,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -395,9 +387,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -468,9 +458,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),
@ -554,9 +542,7 @@ class ObjectRelationDateValueTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -133,9 +133,7 @@ class ObjectSetGridColumnRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation1, relation2, relation3, relation4, relation5),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -123,9 +123,7 @@ class ObjectSetGridFileCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -108,9 +108,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -207,9 +205,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -306,9 +302,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -405,9 +399,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -504,9 +496,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -603,9 +593,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -122,9 +122,7 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -241,9 +239,7 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -173,9 +173,7 @@ class ObjectSetGridPrimitiveRelationTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation1, relation2, relation3, relation4, relation5),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -134,9 +134,7 @@ class ObjectSetGridTagCellRenderingTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -63,9 +63,7 @@ class ObjectSetHeaderTest : TestObjectSetSetup() {
content = Block.Content.DataView(
relations = emptyList(),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -167,9 +167,7 @@ class CreateSelectedFilterTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -262,9 +260,7 @@ class CreateSelectedFilterTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -144,9 +144,7 @@ class FilterListTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -237,9 +235,7 @@ class FilterListTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -330,9 +326,7 @@ class FilterListTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -174,9 +174,6 @@ class ModifyInputValueFilterTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
@ -298,9 +295,6 @@ class ModifyInputValueFilterTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)

View file

@ -188,10 +188,7 @@ class ModifyStatusFilterTest {
fields = Block.Fields.empty(),
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
viewers = listOf(viewer)
)
)

View file

@ -192,9 +192,7 @@ class ModifyTagFilterTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
),

View file

@ -126,9 +126,7 @@ class ViewerObjectSortTest {
content = Block.Content.DataView(
relations = listOf(relation),
viewers = listOf(viewer),
sources = listOf(
MockDataFactory.randomUuid()
)
)
)
)

View file

@ -284,7 +284,6 @@ data class Block(
data class RelationBlock(val key: Id?) : Content()
data class DataView(
val sources: List<String>,
val viewers: List<Viewer>,
@Deprecated("To be deleted")
val relations: List<Relation>,

View file

@ -243,6 +243,12 @@ sealed class Event {
val viewer: String
) : DataView()
data class SetTargetObjectId(
override val context: String,
val dv: String,
val targetObjectId: String
) : DataView()
/**
* Sent when a data-view's relation has been changed or added.
* @property [dv] data view's block id
@ -254,13 +260,6 @@ sealed class Event {
val links: List<RelationLink>
) : DataView()
data class SetSource(
override val context: Id,
val dv: Id,
val sources: List<Id>
) : DataView()
data class UpdateView(
override val context: Id,
val block: Id,

View file

@ -71,6 +71,7 @@ import com.anytypeio.anytype.core_ui.databinding.ItemBlockVideoUploadingBinding
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Payload
import com.anytypeio.anytype.core_ui.features.editor.decoration.DecoratableViewHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.dataview.DataViewBlockDefaultHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.dataview.DataViewBlockDeleteHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.dataview.DataViewBlockEmptyDataHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.dataview.DataViewBlockEmptySourceHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.`interface`.TextHolder
@ -143,6 +144,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_CHECKBOX
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_CODE_SNIPPET
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_DEFAULT
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_SOURCE_DELETED
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_EMPTY_DATA
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_EMPTY_SOURCE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DESCRIPTION
@ -835,6 +837,11 @@ class BlockAdapter(
ItemBlockDataViewDefaultBinding.inflate(inflater, parent, false)
)
}
HOLDER_DATA_VIEW_SOURCE_DELETED -> {
DataViewBlockDeleteHolder(
ItemBlockDataViewEmptyDataBinding.inflate(inflater, parent, false)
)
}
else -> throw IllegalStateException("Unexpected view type: $viewType")
}
@ -1266,6 +1273,12 @@ class BlockAdapter(
item = blocks[position] as BlockView.DataView.EmptyData
)
}
is DataViewBlockDeleteHolder -> {
holder.processChangePayloads(
payloads = payloads.typeOf(),
item = blocks[position] as BlockView.DataView.Deleted
)
}
else -> throw IllegalStateException("Unexpected view holder: $holder")
}
checkIfDecorationChanged(holder, payloads.typeOf(), position)
@ -1604,6 +1617,12 @@ class BlockAdapter(
clicked = onClickListener
)
}
is DataViewBlockDeleteHolder -> {
holder.bind(
item = blocks[position] as BlockView.DataView.Deleted,
clicked = onClickListener
)
}
}
if (holder is Text<*>) {

View file

@ -132,6 +132,50 @@ data class DataViewBlockDefaultHolder(
}
}
data class DataViewBlockDeleteHolder(
val binding: ItemBlockDataViewEmptyDataBinding
) : DataViewBlockViewHolder(binding.root) {
override val decoratableContainer: EditorDecorationContainer = binding.decorationContainer
override val rootView: View = binding.root
override val containerView: ConstraintLayout = binding.containerWithBackground
override val objectIconView: ObjectIconWidget = binding.cardIcon
override val titleView: TextView = binding.cardName
override val descriptionView: TextView = binding.cardDescription
override val selectedView: View = binding.selected
override val decoratableCard: CardView = binding.card
init {
itemView.setOnTouchListener { v, e -> editorTouchProcessor.process(v, e) }
}
fun bind(
item: BlockView.DataView.Deleted,
clicked: (ListenerType) -> Unit
) {
super.bind(item = updateTitle(item), clicked = clicked)
}
fun processChangePayloads(
payloads: List<BlockViewDiffUtil.Payload>,
item: BlockView.DataView.Deleted
) {
payloads.forEach { payload ->
if (payload.isDataViewTitleChanged) {
processChangeBasePayloads(payload, updateTitle(item))
} else {
processChangeBasePayloads(payload, item)
}
}
}
private fun updateTitle(item: BlockView.DataView.Deleted): BlockView.DataView {
return item.copy(
title = itemView.resources.getString(R.string.non_existent_object),
)
}
}
sealed class DataViewBlockViewHolder(
view: View
) : BlockViewHolder(view),

View file

@ -34,7 +34,8 @@ class MiddlewareEventChannel(
msg.blockDataviewViewSet,
msg.objectRelationsAmend,
msg.objectRelationsRemove,
msg.blockDataviewViewUpdate
msg.blockDataviewViewUpdate,
msg.blockDataviewTargetObjectIdSet
)
return events.any { it != null }
}

View file

@ -189,13 +189,13 @@ fun anytype.Event.Message.toCoreModels(
viewer = event.viewId
)
}
blockDataviewSourceSet != null -> {
val event = blockDataviewSourceSet
blockDataviewTargetObjectIdSet != null -> {
val event = blockDataviewTargetObjectIdSet
checkNotNull(event)
Event.Command.DataView.SetSource(
Event.Command.DataView.SetTargetObjectId(
context = context,
dv = event.id,
sources = event.source
targetObjectId = event.targetObjectId
)
}
blockSetRelation != null -> {

View file

@ -351,7 +351,6 @@ fun MBookmarkState.toCoreModelsBookmarkState(): Block.Content.Bookmark.State {
fun MBlock.toCoreModelsDataView(): Block.Content.DataView {
val content = checkNotNull(dataview)
return Block.Content.DataView(
sources = content.source,
viewers = content.views.map { it.toCoreModels() },
relations = content.relations.map { it.toCoreModels() },
relationsIndex = content.relationLinks.map { it.toCoreModels() },

View file

@ -142,7 +142,19 @@ class DocumentExternalEventReducer : StateReducer<List<Block>, Event> {
},
target = { block -> block.id == event.id }
)
is Event.Command.DataView.SetTargetObjectId -> {
state.replace(
replacement = { block ->
val content = block.content<Block.Content.DataView>()
block.copy(
content = content.copy(
targetObjectId = event.targetObjectId
)
)
},
target = { block -> block.id == event.dv }
)
}
else -> state.also {
Timber.d("Ignoring event: ${event::class.java.canonicalName}:\n${event.toPrettyString()}")
}

View file

@ -365,6 +365,9 @@ fun List<BlockView>.enterSAM(
is BlockView.DataView.EmptyData -> view.copy(
isSelected = isSelected
)
is BlockView.DataView.Deleted -> view.copy(
isSelected = isSelected
)
is BlockView.DataView.EmptySource -> view.copy(
isSelected = isSelected
)
@ -599,6 +602,7 @@ fun List<BlockView>.clearSearchHighlights(): List<BlockView> = map { view ->
is BlockView.DataView.Default -> view.copy(searchFields = emptyList())
is BlockView.DataView.EmptyData -> view.copy(searchFields = emptyList())
is BlockView.DataView.EmptySource -> view.copy(searchFields = emptyList())
is BlockView.DataView.Deleted -> view.copy(searchFields = emptyList())
else -> view.also { check(view !is BlockView.Searchable) }
}
}
@ -711,6 +715,10 @@ fun List<BlockView>.highlight(
val fields = listOf(DEFAULT_SEARCH_FIELD_KEY to view.title.orEmpty())
view.copy(searchFields = highlighter(fields))
}
is BlockView.DataView.Deleted -> {
val fields = listOf(DEFAULT_SEARCH_FIELD_KEY to view.title.orEmpty())
view.copy(searchFields = highlighter(fields))
}
else -> {
view.also { v ->
if (v is BlockView.Searchable) {
@ -769,6 +777,7 @@ fun BlockView.setHighlight(
is BlockView.DataView.EmptySource -> copy(searchFields = highlights)
is BlockView.DataView.EmptyData -> copy(searchFields = highlights)
is BlockView.DataView.Default -> copy(searchFields = highlights)
is BlockView.DataView.Deleted -> copy(searchFields = highlights)
else -> this.also { check(this !is BlockView.Searchable) }
}
@ -1063,6 +1072,7 @@ fun BlockView.updateSelection(newSelection: Boolean) = when (this) {
is BlockView.Table -> copy(isSelected = newSelection)
is BlockView.DataView.EmptyData -> copy(isSelected = newSelection)
is BlockView.DataView.EmptySource -> copy(isSelected = newSelection)
is BlockView.DataView.Deleted -> copy(isSelected = newSelection)
is BlockView.DataView.Default -> copy(isSelected = newSelection)
else -> this.also {
if (this is BlockView.Selectable)

View file

@ -17,6 +17,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_CHECKBOX
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_CODE_SNIPPET
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_DEFAULT
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_SOURCE_DELETED
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_EMPTY_DATA
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DATA_VIEW_EMPTY_SOURCE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_DESCRIPTION
@ -1433,5 +1434,17 @@ sealed class BlockView : ViewType {
) : DataView() {
override fun getViewType(): Int = HOLDER_DATA_VIEW_DEFAULT
}
data class Deleted(
override val id: String,
override val isSelected: Boolean,
override val decorations: List<Decoration>,
override val searchFields: List<Searchable.Field> = emptyList(),
override val title: String?,
override val icon: ObjectIcon,
override val background: ThemeColor
) : DataView() {
override fun getViewType(): Int = HOLDER_DATA_VIEW_SOURCE_DELETED
}
}
}

View file

@ -74,4 +74,5 @@ object Types {
const val HOLDER_DATA_VIEW_DEFAULT = 300
const val HOLDER_DATA_VIEW_EMPTY_SOURCE = 301
const val HOLDER_DATA_VIEW_EMPTY_DATA = 302
const val HOLDER_DATA_VIEW_SOURCE_DELETED = 303
}

View file

@ -2196,6 +2196,16 @@ class DefaultBlockViewRenderer @Inject constructor(
val targetSet = ObjectWrapper.Basic(
map = details.details[content.targetObjectId]?.map ?: emptyMap()
)
if (targetSet.isDeleted == true) {
return BlockView.DataView.Deleted(
id = block.id,
decorations = decorations,
isSelected = isSelected,
background = background,
icon = ObjectIcon.None,
title = null
)
}
val icon = ObjectIcon.getEditorLinkToObjectIcon(
obj = targetSet,
layout = targetSet.layout,

View file

@ -351,6 +351,7 @@ fun List<BlockView>.toggleTableMode(
is BlockView.DataView.Default -> view.copy(isSelected = false)
is BlockView.DataView.EmptyData -> view.copy(isSelected = false)
is BlockView.DataView.EmptySource -> view.copy(isSelected = false)
is BlockView.DataView.Deleted -> view.copy(isSelected = false)
}
}
}

View file

@ -282,4 +282,8 @@ fun List<DVViewerRelation>.updateViewerRelations(updates: List<DVViewerRelationU
}
}
return relations
}
fun ObjectSet.getSetOf(ctx: Id): List<Id> {
return ObjectWrapper.Basic(details[ctx]?.map.orEmpty()).setOf
}

View file

@ -83,7 +83,6 @@ class ObjectSetReducer {
}
block.copy(
content = content.copy(
sources = content.sources,
relations = content.relations,
viewers = result
)
@ -130,20 +129,22 @@ class ObjectSetReducer {
}
)
}
is Command.DataView.SetSource -> {
is Command.DataView.SetTargetObjectId -> {
state.copy(
blocks = state.blocks.map { block ->
if (block.id == event.dv) {
val content = block.content
check(content is DV)
block.copy(
content = content.copy(
sources = event.sources
if (content is DV) {
block.copy(
content = content.copy(
targetObjectId = event.targetObjectId
)
)
)
} else {
} else {
block
}
} else
block
}
}
)
}

View file

@ -214,7 +214,7 @@ class ObjectSetViewModel(
)
addAll(ObjectSearchConstants.defaultDataViewFilters())
},
sources = dv.sources,
sources = s.getSetOf(ctx = context),
keys = defaultKeys + dataViewKeys,
limit = DEFAULT_LIMIT,
offset = o

View file

@ -145,7 +145,6 @@ class TypicalTwoRecordObjectSet {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = relations,
relationsIndex = relations.map {
RelationLink(

View file

@ -0,0 +1,129 @@
package com.anytypeio.anytype.presentation.editor
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Event
import com.anytypeio.anytype.core_models.StubDataViewBlock
import com.anytypeio.anytype.core_models.StubDataViewView
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubParagraph
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.core_models.ThemeColor
import com.anytypeio.anytype.core_models.ext.content
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSetup
import com.anytypeio.anytype.presentation.editor.editor.ViewState
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.objects.ObjectIcon
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
private val title = StubTitle()
private val header = StubHeader(children = listOf(title.id))
private val block = StubParagraph()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
}
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun `when getting event for set target object id for data view block, should render as empty data inline set block`() =
runBlocking {
// SETUP
stubInterceptThreadStatus()
val params = InterceptEvents.Params(context = root)
val emptyViewer = StubDataViewView(
name = "",
viewerRelations = emptyList(),
sorts = emptyList()
)
val dv = StubDataViewBlock(viewers = listOf(emptyViewer))
val targetObjectId = MockDataFactory.randomUuid()
val page = Block(
id = root,
fields = Block.Fields.empty(),
children = listOf(header.id, block.id, dv.id),
content = Block.Content.Smart()
)
val events = flow<List<Event>> {
delay(DELAY)
emit(
listOf(
Event.Command.DataView.SetTargetObjectId(
context = root,
dv = dv.id,
targetObjectId = targetObjectId
)
)
)
}
stubOpenDocument(document = listOf(page, header, title, block, dv))
stubInterceptEvents(
params = params,
flow = events
)
val vm = buildViewModel()
//EXPECTING
val state = ViewState.Success(
blocks = listOf(
BlockView.Title.Basic(
id = title.id,
text = title.content<Block.Content.Text>().text,
isFocused = false
),
BlockView.Text.Paragraph(
id = block.id,
text = block.content<Block.Content.Text>().text,
decorations = listOf(BlockView.Decoration())
),
BlockView.DataView.EmptyData(
id = dv.id,
title = null,
background = ThemeColor.DEFAULT,
isSelected = false,
icon = ObjectIcon.None,
decorations = listOf(BlockView.Decoration(style = BlockView.Decoration.Style.Card)),
)
)
)
// TESTING
vm.onStart(root)
coroutineTestRule.advanceTime(DELAY)
assertEquals(
expected = state,
actual = vm.state.value
)
}
companion object {
private const val DELAY = 100L
}
}

View file

@ -111,7 +111,6 @@ object MockObjectSetFactory {
val dataView = Block(
id = dataViewId ?: MockDataFactory.randomString(),
content = Block.Content.DataView(
sources = listOf("source://1"),
viewers = listOf(viewerGrid),
relations = emptyList(),
relationsIndex = relations.map {

View file

@ -139,7 +139,7 @@ class ObjectSetReducerTest {
val dataView = Block(
id = MockDataFactory.randomUuid(),
content = Block.Content.DataView(
sources = listOf("source://1"),
viewers = listOf(viewerGrid),
relations = dataViewRelations
),
@ -181,7 +181,6 @@ class ObjectSetReducerTest {
val expectedDataView = Block(
id = dataView.id,
content = Block.Content.DataView(
sources = (dataView.content as Block.Content.DataView).sources,
viewers = listOf(
Block.Content.DataView.Viewer(
id = viewerGrid.id,
@ -293,7 +292,6 @@ class ObjectSetReducerTest {
val dataView = Block(
id = MockDataFactory.randomUuid(),
content = Block.Content.DataView(
sources = listOf("source://1"),
viewers = listOf(viewerGrid, viewerList),
relations = dataViewRelations
),
@ -331,7 +329,6 @@ class ObjectSetReducerTest {
val expectedDataView = Block(
id = dataView.id,
content = Block.Content.DataView(
sources = (dataView.content as Block.Content.DataView).sources,
viewers = listOf(
Block.Content.DataView.Viewer(
id = viewerGrid.id,
@ -396,8 +393,7 @@ class ObjectSetReducerTest {
)
val dataView = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(viewer1, viewer2),
sources = listOf(MockDataFactory.randomString())
views = listOf(viewer1, viewer2)
)
val blocks = listOf(title, dataView)
@ -454,7 +450,6 @@ class ObjectSetReducerTest {
val expectedDataView = Block(
id = dataView.id,
content = Block.Content.DataView(
sources = (dataView.content as Block.Content.DataView).sources,
viewers = listOf(
Block.Content.DataView.Viewer(
id = viewer1.id,
@ -511,8 +506,7 @@ class ObjectSetReducerTest {
)
val dataView = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(viewer1),
sources = listOf(MockDataFactory.randomString())
views = listOf(viewer1)
)
val blocks = listOf(title, dataView)
@ -563,7 +557,6 @@ class ObjectSetReducerTest {
val expectedDataView = Block(
id = dataView.id,
content = Block.Content.DataView(
sources = (dataView.content as Block.Content.DataView).sources,
viewers = listOf(
Block.Content.DataView.Viewer(
id = viewer1.id,
@ -612,8 +605,7 @@ class ObjectSetReducerTest {
)
val dataView = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(viewer1),
sources = listOf(MockDataFactory.randomString())
views = listOf(viewer1)
)
val blocks = listOf(title, dataView)
@ -664,7 +656,6 @@ class ObjectSetReducerTest {
val expectedDataView = Block(
id = dataView.id,
content = Block.Content.DataView(
sources = (dataView.content as Block.Content.DataView).sources,
viewers = listOf(
Block.Content.DataView.Viewer(
id = viewer1.id,

View file

@ -38,12 +38,6 @@ class ObjectSetAddOrUpdateViewerTest : ObjectSetViewModelTestSetup() {
children = listOf(title.id)
)
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -67,7 +61,6 @@ class ObjectSetAddOrUpdateViewerTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer)
),
@ -169,7 +162,6 @@ class ObjectSetAddOrUpdateViewerTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer)
),

View file

@ -1,7 +1,6 @@
package com.anytypeio.anytype.presentation.sets.main
import android.util.Log
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.DVViewer
@ -9,10 +8,8 @@ import com.anytypeio.anytype.core_models.DVViewerRelation
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.RelationLink
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.SearchResult
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubRelation
import com.anytypeio.anytype.core_models.StubRelationObject
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.core_models.ext.content
@ -22,8 +19,8 @@ import com.anytypeio.anytype.presentation.relations.ObjectSetConfig
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultDataViewKeys
import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel
import com.anytypeio.anytype.presentation.sets.model.CellView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import net.lachlanmckee.timberjunit.TimberTestRule
@ -32,16 +29,9 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import kotlin.test.assertEquals
class ObjectSetCellTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@get:Rule
val timberTestRule: TimberTestRule = TimberTestRule.builder()
.minPriority(Log.DEBUG)
@ -128,7 +118,6 @@ class ObjectSetCellTest : ObjectSetViewModelTestSetup() {
private val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relationsIndex = relations.map {
RelationLink(
key = it.key,
@ -171,7 +160,7 @@ class ObjectSetCellTest : ObjectSetViewModelTestSetup() {
sorts = dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = dv.content<DV>().sources,
sources = listOf(MockDataFactory.randomUuid()),
keys = dv.content<DV>().relationsIndex.map { it.key } + defaultDataViewKeys,
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,

View file

@ -1,6 +1,5 @@
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
@ -16,10 +15,8 @@ import com.anytypeio.anytype.core_models.StubDataViewView
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.times
@ -27,12 +24,6 @@ import org.mockito.kotlin.verifyBlocking
class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
private val title = StubTitle()
private val header = StubHeader(children = listOf(title.id))
@ -53,8 +44,7 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
val dv = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(viewer),
sources = listOf(MockDataFactory.randomString())
views = listOf(viewer)
)
val givenType = MockDataFactory.randomUuid()
@ -120,8 +110,7 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
val dv = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(viewer),
sources = listOf(MockDataFactory.randomString())
views = listOf(viewer)
)
val newObjectId = MockDataFactory.randomUuid()
@ -193,7 +182,6 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer)
),
@ -317,7 +305,6 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(givenType),
relations = listOf(relationStakeHolders),
viewers = listOf(viewer)
),

View file

@ -34,12 +34,6 @@ class ObjectSetHeaderTest : ObjectSetViewModelTestSetup() {
children = listOf(title.id)
)
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -63,7 +57,6 @@ class ObjectSetHeaderTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer)
),
@ -119,7 +112,6 @@ class ObjectSetHeaderTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer)
),

View file

@ -1,19 +1,26 @@
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.Id
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.StubDataView
import com.anytypeio.anytype.core_models.StubDataViewView
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubRelationLink
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.domain.status.InterceptThreadStatus
import com.anytypeio.anytype.presentation.relations.ObjectSetConfig
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants
import com.anytypeio.anytype.test_utils.MockDataFactory
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
import org.mockito.kotlin.verifyNoInteractions
class ObjectSetInitializationTest : ObjectSetViewModelTestSetup() {
@ -23,12 +30,6 @@ class ObjectSetInitializationTest : ObjectSetViewModelTestSetup() {
private val ctx: Id = MockDataFactory.randomUuid()
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -68,4 +69,59 @@ class ObjectSetInitializationTest : ObjectSetViewModelTestSetup() {
verifyNoInteractions(createObject)
}
@Test
fun `when open object set, should start subscription to the records by object setOf details`() {
stubInterceptEvents()
stubInterceptThreadStatus(InterceptThreadStatus.Params(ctx))
initDataViewSubscriptionContainer()
stubSearchWithSubscription()
stubSubscriptionEventChannel()
val view = StubDataViewView()
val relLink1 = StubRelationLink()
val relLink2 = StubRelationLink()
val dataView = StubDataView(
id = MockDataFactory.randomUuid(),
views = listOf(view),
relations = listOf(relLink1, relLink2),
targetObjectId = MockDataFactory.randomUuid()
)
val type = MockDataFactory.randomString()
stubOpenObjectSet(
doc = listOf(header, title, dataView),
details = Block.Details(
mapOf(
root to Block.Fields(
mapOf(Relations.SET_OF to listOf(type))
)
)
)
)
val vm = givenViewModel()
vm.onStart(ctx = root)
verifyBlocking(repo, times(1)) {
searchObjectsWithSubscription(
subscription = root,
sorts = listOf(),
filters = buildList { addAll(ObjectSearchConstants.defaultDataViewFilters()) },
keys = ObjectSearchConstants.defaultDataViewKeys.distinct() + listOf(relLink1, relLink2).map { it.key },
source = arrayListOf(type),
offset = 0,
limit = ObjectSetConfig.DEFAULT_LIMIT,
beforeId = null,
afterId = null,
ignoreWorkspace = null,
noDepSubscription = null
)
}
coroutineTestRule.advanceTime(100L)
}
}

View file

@ -1,6 +1,5 @@
package com.anytypeio.anytype.presentation.sets.main
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import app.cash.turbine.test
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.DV
@ -27,13 +26,11 @@ import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultDa
import com.anytypeio.anytype.presentation.sets.ObjectSetCommand
import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel
import com.anytypeio.anytype.presentation.sets.model.Viewer
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.doReturn
@ -46,12 +43,6 @@ import kotlin.time.ExperimentalTime
class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -95,7 +86,6 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
private val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(viewer),
relationsIndex = objectRelations.map {
@ -125,6 +115,8 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
val obj = ObjectWrapper.Basic(record)
val setOf = listOf(MockDataFactory.randomString())
stubInterceptEvents()
stubInterceptThreadStatus()
stubSubscriptionEventChannel()
@ -134,7 +126,7 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
sorts = dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = dv.content<DV>().sources,
sources = setOf,
keys = (ObjectSearchConstants.defaultDataViewKeys + dv.content<DV>().relationsIndex.map { it.key }).distinct(),
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,
@ -154,7 +146,14 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
title,
dv
),
dataViewRestrictions = emptyList()
dataViewRestrictions = emptyList(),
details = Block.Details(
mapOf(
root to Block.Fields(
mapOf("setOf" to setOf)
)
)
)
)
storeOfRelations.merge(listOf(linkedProjectRelation))
@ -238,6 +237,8 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
)
)
val setOf = listOf(MockDataFactory.randomString())
val details = Block.Details(
details = mapOf(
linkedProjectTargetId to Block.Fields(
@ -245,6 +246,9 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
Relations.ID to linkedProjectTargetId,
Relations.LAYOUT to supportedObjectLayouts.random().code.toDouble()
)
),
root to Block.Fields(
mapOf("setOf" to setOf)
)
)
)
@ -259,7 +263,7 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
sorts = dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = dv.content<DV>().sources,
sources = setOf,
keys = (ObjectSearchConstants.defaultDataViewKeys + dv.content<DV>().relationsIndex.map { it.key }).distinct(),
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,
@ -360,6 +364,8 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
)
)
val setOf = listOf(MockDataFactory.randomString())
val details = Block.Details(
details = mapOf(
linkedProjectTargetId to Block.Fields(
@ -367,6 +373,9 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
Relations.ID to linkedProjectTargetId,
Relations.LAYOUT to SupportedLayouts.layouts.random().code.toDouble()
)
),
root to Block.Fields(
mapOf("setOf" to setOf)
)
)
)
@ -381,7 +390,7 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
sorts = dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = dv.content<DV>().sources,
sources = setOf,
keys = (ObjectSearchConstants.defaultDataViewKeys + dv.content<DV>().relationsIndex.map { it.key }).distinct(),
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,
@ -477,6 +486,8 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
)
)
val setOf = listOf(MockDataFactory.randomString())
val details = Block.Details(
details = mapOf(
linkedProjectTargetId to Block.Fields(
@ -484,6 +495,9 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
Relations.ID to linkedProjectTargetId,
Relations.LAYOUT to unsupportedLayouis.random().code.toDouble()
)
),
root to Block.Fields(
mapOf("setOf" to setOf)
)
)
)
@ -498,7 +512,7 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
sorts = dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = dv.content<DV>().sources,
sources = setOf,
keys = (ObjectSearchConstants.defaultDataViewKeys + dv.content<DV>().relationsIndex.map { it.key }).distinct(),
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,

View file

@ -17,12 +17,6 @@ import kotlin.test.assertEquals
class ObjectSetRestrictionsTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)

View file

@ -1,7 +1,7 @@
package com.anytypeio.anytype.presentation.sets.main
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import app.cash.turbine.test
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.DV
import com.anytypeio.anytype.core_models.SearchResult
import com.anytypeio.anytype.core_models.SubscriptionEvent
@ -13,13 +13,12 @@ import com.anytypeio.anytype.presentation.search.ObjectSearchConstants.defaultDa
import com.anytypeio.anytype.presentation.sets.model.CellView
import com.anytypeio.anytype.presentation.sets.model.ColumnView
import com.anytypeio.anytype.presentation.sets.model.Viewer
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import kotlin.test.assertEquals
@ -30,12 +29,6 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
val doc = TypicalTwoRecordObjectSet()
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
@ -64,6 +57,8 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
)
}
)
val setOf = listOf(MockDataFactory.randomString())
val keys = (ObjectSearchConstants.defaultDataViewKeys + doc.dv.content<DV>().relationsIndex.map { it.key }).distinct()
stubSearchWithSubscription(
@ -72,7 +67,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
sorts = doc.dv.content<DV>().viewers.first().sorts,
afterId = null,
beforeId = null,
sources = doc.dv.content<DV>().sources,
sources = setOf,
keys = keys,
limit = ObjectSetConfig.DEFAULT_LIMIT,
offset = 0,
@ -86,12 +81,22 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
)
)
)
val details = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf("setOf" to setOf)
)
)
)
stubOpenObjectSet(
doc = listOf(
doc.header,
doc.title,
doc.dv
)
),
details = details
)
println(storeOfRelations.getAll().toString())

View file

@ -20,12 +20,6 @@ import org.mockito.kotlin.verifyBlocking
class ObjectSetUpdateViewerSortTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)

View file

@ -1,5 +1,6 @@
package com.anytypeio.anytype.presentation.sets.main
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.DVFilter
@ -51,12 +52,13 @@ import com.anytypeio.anytype.presentation.sets.ObjectSetPaginator
import com.anytypeio.anytype.presentation.sets.ObjectSetReducer
import com.anytypeio.anytype.presentation.sets.ObjectSetSession
import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.presentation.util.Dispatcher
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.StandardTestDispatcher
import org.junit.Rule
import org.mockito.Mock
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
@ -66,6 +68,12 @@ open class ObjectSetViewModelTestSetup {
val root: Id = MockDataFactory.randomString()
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Mock
lateinit var openObjectSet: OpenObjectSet
@ -133,7 +141,7 @@ open class ObjectSetViewModelTestSetup {
protected val storeOfRelations: StoreOfRelations = DefaultStoreOfRelations()
private val database = ObjectSetDatabase(store)
private lateinit var container: DataViewSubscriptionContainer
lateinit var container: DataViewSubscriptionContainer
val urlBuilder: UrlBuilder get() = UrlBuilder(gateway)
@ -143,9 +151,9 @@ open class ObjectSetViewModelTestSetup {
store = store,
channel = subscriptionEventChannel,
dispatchers = AppCoroutineDispatchers(
io = StandardTestDispatcher(),
computation = StandardTestDispatcher(),
main = StandardTestDispatcher()
io = coroutineTestRule.testDispatcher,
computation = coroutineTestRule.testDispatcher,
main = coroutineTestRule.testDispatcher
)
)
}

View file

@ -100,7 +100,6 @@ class ObjectSetViewerDeleteTest {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(firstViewer, secondViewer, thirdViewer)
),
@ -174,7 +173,6 @@ class ObjectSetViewerDeleteTest {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(firstViewer, secondViewer, thirdViewer)
),
@ -258,7 +256,6 @@ class ObjectSetViewerDeleteTest {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = listOf(firstViewer, secondViewer, thirdViewer)
),

View file

@ -21,12 +21,6 @@ import kotlin.test.assertEquals
class ObjectSetViewerFilterTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)

View file

@ -14,12 +14,6 @@ import kotlin.test.assertEquals
class ObjectSetZeroDataViewTest : ObjectSetViewModelTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
val title = Block(
id = MockDataFactory.randomUuid(),
content = Block.Content.Text(

View file

@ -1,26 +1,15 @@
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.Relations
import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import kotlin.test.assertEquals
class ObjectSetZeroViewTest : ObjectSetViewModelTestSetup() {
@get:Rule
internal val rule = InstantTaskExecutorRule()
@get:Rule
internal val coroutineTestRule = CoroutinesTestRule()
val title = Block(
id = MockDataFactory.randomUuid(),
content = Block.Content.Text(
@ -65,7 +54,6 @@ class ObjectSetZeroViewTest : ObjectSetViewModelTestSetup() {
val dv = Block(
id = MockDataFactory.randomUuid(),
content = DV(
sources = listOf(MockDataFactory.randomString()),
relations = emptyList(),
viewers = emptyList()
),

View file

@ -49,9 +49,6 @@ class SetByRelationTest : ObjectSetViewModelTestSetup() {
}
)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)

View file

@ -315,4 +315,26 @@ fun StubTableCells(columns: List<Block>, rows: List<Block>): List<Block> {
}
}
return cells.toList()
}
}
fun StubDataViewBlock(
id: Id = MockDataFactory.randomUuid(),
children: List<Id> = emptyList(),
fields: Block.Fields = Block.Fields.empty(),
backgroundColor: String? = null,
targetObjectId: Id = "",
viewers: List<Block.Content.DataView.Viewer> = emptyList(),
relations: List<Relation> = emptyList(),
relationsIndex: List<RelationLink> = emptyList(),
): Block = Block(
id = id,
content = Block.Content.DataView(
targetObjectId = targetObjectId,
relationsIndex = relationsIndex,
viewers = viewers,
relations = relations
),
children = children,
fields = fields,
backgroundColor = backgroundColor
)

View file

@ -6,12 +6,10 @@ fun StubDataView(
id : Id = MockDataFactory.randomUuid(),
views: List<DVViewer> = emptyList(),
relations: List<RelationLink> = emptyList(),
sources: List<Id> = emptyList(),
targetObjectId: Id = MockDataFactory.randomUuid()
) : Block = Block(
id = id,
content = DV(
sources = sources,
relations = emptyList(),
relationsIndex= relations,
viewers = views,
@ -45,6 +43,14 @@ fun StubDataViewViewRelation(
isVisible = isVisible
)
fun StubRelationLink(
key: Key = MockDataFactory.randomUuid(),
format: RelationFormat = RelationFormat.LONG_TEXT,
): RelationLink = RelationLink(
key = key,
format = format
)
fun StubSort(
relationKey: Key = MockDataFactory.randomUuid(),
type: DVSortType = DVSortType.ASC