mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DataView | Fix | Filter by relation hidden (#1702)
* fix crash * add test * add log
This commit is contained in:
parent
0948a821d8
commit
17c8f6b72b
2 changed files with 123 additions and 8 deletions
|
@ -12,6 +12,7 @@ import com.anytypeio.anytype.presentation.sets.ObjectSet
|
|||
import com.anytypeio.anytype.presentation.sets.ObjectSetViewState
|
||||
import com.anytypeio.anytype.presentation.sets.filter.CreateFilterView
|
||||
import com.anytypeio.anytype.presentation.sets.model.*
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
@ -122,15 +123,17 @@ fun ObjectSet.simpleRelations(viewerId: Id?): ArrayList<SimpleRelationView> {
|
|||
}
|
||||
|
||||
fun DVViewer.toViewRelation(relation: Relation): SimpleRelationView {
|
||||
return viewerRelations.first { it.key == relation.key }.let { vRelation ->
|
||||
SimpleRelationView(
|
||||
key = relation.key,
|
||||
isHidden = relation.isHidden,
|
||||
isVisible = vRelation.isVisible,
|
||||
title = relation.name,
|
||||
format = relation.format.toView()
|
||||
)
|
||||
val viewerRelation = viewerRelations.firstOrNull { it.key == relation.key }
|
||||
if (viewerRelation == null) {
|
||||
Timber.e("ViewerRelations is not containing relation:$relation")
|
||||
}
|
||||
return SimpleRelationView(
|
||||
key = relation.key,
|
||||
isHidden = relation.isHidden,
|
||||
isVisible = viewerRelation?.isVisible ?: false,
|
||||
title = relation.name,
|
||||
format = relation.format.toView()
|
||||
)
|
||||
}
|
||||
|
||||
fun Relation.toCreateFilterCheckboxView(isSelected: Boolean? = null): List<CreateFilterView.Checkbox> {
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package com.anytypeio.anytype.presentation.relations
|
||||
|
||||
import MockDataFactory
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.presentation.mapper.toView
|
||||
import com.anytypeio.anytype.presentation.sets.model.SimpleRelationView
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ObjectSetRenderMapperTest {
|
||||
|
||||
|
||||
@Test
|
||||
fun `should return relation view with visibility true`() {
|
||||
|
||||
val viewerRel1 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRel2 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRel3 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRelations = listOf(viewerRel1, viewerRel2, viewerRel3)
|
||||
|
||||
val relation = Relation(
|
||||
key = viewerRel2.key,
|
||||
name = MockDataFactory.randomString(),
|
||||
source = Relation.Source.ACCOUNT,
|
||||
format = Relation.Format.NUMBER
|
||||
)
|
||||
|
||||
val viewer1 = DVViewer(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
filters = emptyList(),
|
||||
sorts = emptyList(),
|
||||
type = Block.Content.DataView.Viewer.Type.GRID,
|
||||
name = MockDataFactory.randomString(),
|
||||
viewerRelations = viewerRelations
|
||||
)
|
||||
|
||||
val result = viewer1.toViewRelation(relation)
|
||||
|
||||
val expected = SimpleRelationView(
|
||||
key = relation.key,
|
||||
title = relation.name,
|
||||
format = relation.format.toView(),
|
||||
isVisible = true,
|
||||
isHidden = false
|
||||
)
|
||||
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return relation view with visibility false`() {
|
||||
|
||||
val viewerRel1 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRel2 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRel3 = Block.Content.DataView.Viewer.ViewerRelation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
isVisible = true
|
||||
)
|
||||
|
||||
val viewerRelations = listOf(viewerRel1, viewerRel2, viewerRel3)
|
||||
|
||||
val relation = Relation(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
name = MockDataFactory.randomString(),
|
||||
source = Relation.Source.ACCOUNT,
|
||||
format = Relation.Format.NUMBER
|
||||
)
|
||||
|
||||
val viewer1 = DVViewer(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
filters = emptyList(),
|
||||
sorts = emptyList(),
|
||||
type = Block.Content.DataView.Viewer.Type.GRID,
|
||||
name = MockDataFactory.randomString(),
|
||||
viewerRelations = viewerRelations
|
||||
)
|
||||
|
||||
val result = viewer1.toViewRelation(relation)
|
||||
|
||||
val expected = SimpleRelationView(
|
||||
key = relation.key,
|
||||
title = relation.name,
|
||||
format = relation.format.toView(),
|
||||
isVisible = false,
|
||||
isHidden = false
|
||||
)
|
||||
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue