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

DROID-1027 Editor | Internal flags (#3038)

* DROID-1027 code added to internal flags

* DROID-1027 internalFlags relation

* DROID-1027 internalFlags added to object wrapper + tests
This commit is contained in:
Konstantin Ivanov 2023-03-23 10:57:13 +01:00 committed by GitHub
parent a74bcb787f
commit b575ae9264
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 127 additions and 5 deletions

View file

@ -1,19 +1,19 @@
package com.anytypeio.anytype.core_models
sealed class InternalFlags {
sealed class InternalFlags(val code: Int) {
/**
* show the object type selection interface
*/
object ShouldSelectType : InternalFlags()
object ShouldSelectType : InternalFlags(1)
/**
* Flag to remove the object from the account, in case of closing this object when it is empty
*/
object ShouldEmptyDelete : InternalFlags()
object ShouldEmptyDelete : InternalFlags(0)
/**
* show the template selection interface
*/
object ShouldSelectTemplate : InternalFlags()
object ShouldSelectTemplate : InternalFlags(2)
}

View file

@ -101,6 +101,26 @@ sealed class ObjectWrapper {
val relationOptionColor: String? by default
val relationReadonlyValue: Boolean? by default
val internalFlags: List<InternalFlags>
get() = when (val value = map[Relations.INTERNAL_FLAGS]) {
is Double -> buildList {
when (value.toInt()) {
InternalFlags.ShouldSelectType.code -> InternalFlags.ShouldSelectType
InternalFlags.ShouldSelectTemplate.code -> InternalFlags.ShouldSelectTemplate
InternalFlags.ShouldEmptyDelete.code -> InternalFlags.ShouldEmptyDelete
}
}
is List<*> -> value.typeOf<Double>().mapNotNull { code ->
when (code.toInt()) {
InternalFlags.ShouldSelectType.code -> InternalFlags.ShouldSelectType
InternalFlags.ShouldSelectTemplate.code -> InternalFlags.ShouldSelectTemplate
InternalFlags.ShouldEmptyDelete.code -> InternalFlags.ShouldEmptyDelete
else -> null
}
}
else -> emptyList()
}
}
/**

View file

@ -42,7 +42,7 @@ object Relations {
const val RELATION_DEFAULT_VALUE = "relationDefaultValue"
const val RELATION_FORMAT_OBJECT_TYPES = "relationFormatObjectTypes"
const val SOURCE_OBJECT = "sourceObject"
const val INTERNAL_FLAGS = "internalFlags"
const val PAGE_COVER = "pageCover"

View file

@ -0,0 +1,102 @@
package com.anytypeio.anytype.presentation.editor.editor
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.InternalFlags
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubSmartBlock
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
@ExperimentalCoroutinesApi
class EditorInternalFlagsTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@get:Rule
val coroutineTestRule = DefaultCoroutineTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
}
@Test
fun `should has all internal flags on object open`() = runTest {
val title = StubTitle()
val header = StubHeader(children = listOf(title.id))
val page = StubSmartBlock(id = root, children = listOf(header.id))
val document = listOf(page, header, title)
stubInterceptEvents()
val detailsList = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.TYPE to ObjectTypeIds.NOTE,
Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble(),
Relations.INTERNAL_FLAGS to listOf(2.0, 0.0, 1.0)
)
)
)
)
stubOpenDocument(document = document, details = detailsList)
val vm = buildViewModel()
vm.onStart(root)
advanceUntilIdle()
val storedDetails = orchestrator.stores.details.current()
val objectDetails = ObjectWrapper.Basic(storedDetails.details[root]?.map.orEmpty())
val expectedFlags = listOf(
InternalFlags.ShouldSelectTemplate,
InternalFlags.ShouldEmptyDelete,
InternalFlags.ShouldSelectType
)
val actualFlags = objectDetails.internalFlags
assertEquals(expected = expectedFlags, actual = actualFlags)
}
@Test
fun `should hasn't internal flags on object open`() = runTest {
val title = StubTitle()
val header = StubHeader(children = listOf(title.id))
val page = StubSmartBlock(id = root, children = listOf(header.id))
val document = listOf(page, header, title)
stubInterceptEvents()
stubOpenDocument(document = document)
val vm = buildViewModel()
vm.onStart(root)
advanceUntilIdle()
val storedDetails = orchestrator.stores.details.current()
val objectDetails = ObjectWrapper.Basic(storedDetails.details[root]?.map.orEmpty())
val expectedFlags = emptyList<InternalFlags>()
val actualFlags = objectDetails.internalFlags
assertEquals(expected = expectedFlags, actual = actualFlags)
}
}