mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-612 Editor | Link to object block, default as text style (#2704)
* DROID-612 test setup fix * DROID-612 fix model * DROID-612 code style fix * DROID-612 add test Co-authored-by: konstantiniiv <ki@anytype.io>
This commit is contained in:
parent
8831bdcc05
commit
9306f5d5aa
6 changed files with 118 additions and 16 deletions
|
@ -5,6 +5,7 @@ import androidx.fragment.app.testing.FragmentScenario
|
|||
import androidx.fragment.app.testing.launchFragmentInContainer
|
||||
import com.anytypeio.anytype.R
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.app.DefaultFeatureToggles
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.DocumentInfo
|
||||
|
@ -13,6 +14,7 @@ import com.anytypeio.anytype.core_models.Id
|
|||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
import com.anytypeio.anytype.domain.`object`.ConvertObjectToSet
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
import com.anytypeio.anytype.domain.`object`.UpdateDetail
|
||||
|
@ -201,6 +203,8 @@ open class EditorTestSetup {
|
|||
|
||||
lateinit var downloadUnsplashImage: DownloadUnsplashImage
|
||||
|
||||
lateinit var featureToggles: FeatureToggles
|
||||
|
||||
@Mock
|
||||
lateinit var updateDivider: UpdateDivider
|
||||
|
||||
|
@ -333,6 +337,8 @@ open class EditorTestSetup {
|
|||
applyTemplate = applyTemplate
|
||||
)
|
||||
|
||||
featureToggles = DefaultFeatureToggles()
|
||||
|
||||
TestEditorFragment.testViewModelFactory = EditorViewModelFactory(
|
||||
openPage = openPage,
|
||||
closeObject = closePage,
|
||||
|
@ -413,7 +419,8 @@ open class EditorTestSetup {
|
|||
setDocImageIcon = setDocImageIcon,
|
||||
editorTemplateDelegate = editorTemplateDelegate,
|
||||
createNewObject = createNewObject,
|
||||
objectToSet = objectToSet
|
||||
objectToSet = objectToSet,
|
||||
featureToggles = featureToggles
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -2071,10 +2071,7 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
vm.proceedWithLinkToAction(
|
||||
link = link,
|
||||
target = target,
|
||||
text = text,
|
||||
icon = icon,
|
||||
isBookmark = isBookmark,
|
||||
isSet = isSet
|
||||
isBookmark = isBookmark
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -386,12 +386,11 @@ data class Block(
|
|||
) : Prototype()
|
||||
|
||||
data class Link(
|
||||
val target: Id
|
||||
) : Prototype() {
|
||||
val cardStyle: Content.Link.CardStyle = Content.Link.CardStyle.CARD
|
||||
val iconSize: Content.Link.IconSize = Content.Link.IconSize.MEDIUM
|
||||
val description: Content.Link.Description = Content.Link.Description.CONTENT
|
||||
}
|
||||
val target: Id,
|
||||
val cardStyle: Content.Link.CardStyle = Content.Link.CardStyle.TEXT,
|
||||
val iconSize: Content.Link.IconSize = Content.Link.IconSize.SMALL,
|
||||
val description: Content.Link.Description = Content.Link.Description.NONE
|
||||
) : Prototype()
|
||||
|
||||
object DividerLine : Prototype()
|
||||
object DividerDots : Prototype()
|
||||
|
|
|
@ -43,7 +43,7 @@ class AddBackLinkToObject(
|
|||
context = params.objectToPlaceLink,
|
||||
target = targetBlock,
|
||||
position = Position.BOTTOM,
|
||||
prototype = Block.Prototype.Link(params.objectToLink)
|
||||
prototype = Block.Prototype.Link(target = params.objectToLink)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -5067,11 +5067,9 @@ class EditorViewModel(
|
|||
fun proceedWithLinkToAction(
|
||||
link: Id,
|
||||
target: Id,
|
||||
isBookmark: Boolean,
|
||||
text: String,
|
||||
icon: ObjectIcon,
|
||||
isSet: Boolean
|
||||
isBookmark: Boolean
|
||||
) {
|
||||
Timber.d("proceedWithLinkToAction, link:[$link], target:[$target], isBookmark:[$isBookmark]")
|
||||
val targetBlock = blocks.firstOrNull { it.id == target }
|
||||
if (targetBlock != null) {
|
||||
val targetContent = targetBlock.content
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
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.Position
|
||||
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.domain.block.interactor.CreateBlock
|
||||
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
|
||||
import com.anytypeio.anytype.presentation.editor.editor.slash.SlashItem
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.times
|
||||
import org.mockito.kotlin.verify
|
||||
|
||||
class EditorCreateBlockTest : EditorPresentationTestSetup() {
|
||||
|
||||
@get:Rule
|
||||
val rule = InstantTaskExecutorRule()
|
||||
|
||||
@get:Rule
|
||||
val coroutineTestRule = CoroutinesTestRule()
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
}
|
||||
|
||||
val title = StubTitle()
|
||||
val header = StubHeader(children = listOf(title.id))
|
||||
val a = StubParagraph(text = "")
|
||||
|
||||
@Test
|
||||
fun `should create default link_to_object block with text style, small icon and no description`() =
|
||||
runTest {
|
||||
|
||||
// SETUP
|
||||
val page = Block(
|
||||
id = root,
|
||||
fields = Block.Fields(emptyMap()),
|
||||
content = Block.Content.Smart(),
|
||||
children = listOf(header.id, a.id)
|
||||
)
|
||||
|
||||
val document = listOf(page, header, title, a)
|
||||
|
||||
stubOpenDocument(document = document)
|
||||
stubInterceptEvents()
|
||||
stubInterceptThreadStatus()
|
||||
stubUpdateText()
|
||||
stubCreateBlock(root)
|
||||
|
||||
val vm = buildViewModel()
|
||||
|
||||
// TESTING
|
||||
|
||||
vm.onStart(root)
|
||||
vm.onBlockFocusChanged(id = a.id, hasFocus = true)
|
||||
vm.onSelectionChanged(
|
||||
id = a.id,
|
||||
selection = IntRange(1, 1)
|
||||
)
|
||||
val blockView = BlockView.Text.Paragraph(id = a.id, text = "/")
|
||||
vm.onTextBlockTextChanged(view = blockView)
|
||||
vm.onSlashItemClicked(item = SlashItem.Actions.LinkTo)
|
||||
|
||||
val linkToObject = MockDataFactory.randomUuid()
|
||||
|
||||
vm.proceedWithLinkToAction(
|
||||
link = linkToObject,
|
||||
target = a.id,
|
||||
isBookmark = false
|
||||
)
|
||||
|
||||
//VERIFY
|
||||
verify(createBlock, times(1)).execute(
|
||||
params = eq(
|
||||
CreateBlock.Params(
|
||||
context = root,
|
||||
target = a.id,
|
||||
position = Position.BOTTOM,
|
||||
prototype = Block.Prototype.Link(
|
||||
target = linkToObject,
|
||||
cardStyle = Block.Content.Link.CardStyle.TEXT,
|
||||
iconSize = Block.Content.Link.IconSize.SMALL,
|
||||
description = Block.Content.Link.Description.NONE
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
coroutineTestRule.advanceTime(300L)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue