mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Regression. Text is not always set when creating a lot of text blocks (#740)
This commit is contained in:
parent
6099373baf
commit
ecd84e2b38
6 changed files with 509 additions and 6 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
### Fixes & tech 🚒
|
||||
|
||||
* Regression. Text is not always set when creating a lot of text blocks (#741)
|
||||
* Respective theme colors should differ for text color and background colors in action menu (#738)
|
||||
* Fix app configuration lifetime (#735)
|
||||
* Avatar image is not displayed after registration started after logout (#692)
|
||||
|
|
|
@ -47,6 +47,8 @@ abstract class Text(
|
|||
|
||||
makeLinkClickable(item)
|
||||
|
||||
clearTextWatchers()
|
||||
|
||||
setContent(
|
||||
item = item,
|
||||
clicked = clicked
|
||||
|
@ -102,8 +104,6 @@ abstract class Text(
|
|||
|
||||
content.apply {
|
||||
|
||||
clearTextWatchers()
|
||||
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
|
|
|
@ -273,7 +273,7 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override val color: String? = null,
|
||||
override val backgroundColor: String? = null,
|
||||
override val isChecked: Boolean = false,
|
||||
override val indent: Int,
|
||||
override val indent: Int = 0,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false,
|
||||
override val cursor: Int? = null,
|
||||
|
@ -323,7 +323,7 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override var isFocused: Boolean = false,
|
||||
override val color: String? = null,
|
||||
override val backgroundColor: String? = null,
|
||||
override val indent: Int,
|
||||
override val indent: Int = 0,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false,
|
||||
override val cursor: Int? = null,
|
||||
|
@ -346,7 +346,7 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override val id: String,
|
||||
override var text: String,
|
||||
override var marks: List<Markup.Mark> = emptyList(),
|
||||
override var isFocused: Boolean,
|
||||
override var isFocused: Boolean = false,
|
||||
override val color: String? = null,
|
||||
override val backgroundColor: String? = null,
|
||||
override val indent: Int = 0,
|
||||
|
|
|
@ -237,4 +237,8 @@ interface TextBlockHolder : TextHolder {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearTextWatchers() {
|
||||
content.clearTextWatchers()
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ open class BlockAdapterTestSetup {
|
|||
views: List<BlockView>,
|
||||
onFocusChanged: (String, Boolean) -> Unit = { _, _ -> },
|
||||
onTitleTextChanged: (Editable) -> Unit = {},
|
||||
onTextBlockTextChanged: (BlockView.Text) -> Unit = {},
|
||||
onEndLineEnterTitleClicked: (Editable) -> Unit = {},
|
||||
onTextChanged: (String, Editable) -> Unit = { _, _ -> },
|
||||
onToggleClicked: (String) -> Unit = {}
|
||||
|
@ -37,7 +38,7 @@ open class BlockAdapterTestSetup {
|
|||
onProfileIconClicked = {},
|
||||
onTogglePlaceholderClicked = {},
|
||||
onToggleClicked = onToggleClicked,
|
||||
onTextBlockTextChanged = {},
|
||||
onTextBlockTextChanged = onTextBlockTextChanged,
|
||||
onTitleTextChanged = onTitleTextChanged,
|
||||
onEndLineEnterTitleClicked = onEndLineEnterTitleClicked,
|
||||
onMarkupActionClicked = { _, _ -> },
|
||||
|
|
|
@ -0,0 +1,497 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor
|
||||
|
||||
import android.os.Build
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.agileburo.anytype.core_ui.MockDataFactory
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.text.*
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Config(sdk = [Build.VERSION_CODES.P])
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class BlockAdapterTextBindingTest : BlockAdapterTestSetup() {
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice paragraph view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Paragraph(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_PARAGRAPH)
|
||||
|
||||
check(holder is Paragraph)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice header1 view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Header.One(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_HEADER_ONE)
|
||||
|
||||
check(holder is HeaderOne)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice header2 view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Header.Two(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_HEADER_TWO)
|
||||
|
||||
check(holder is HeaderTwo)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice header3 view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Header.Three(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_HEADER_THREE)
|
||||
|
||||
check(holder is HeaderThree)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice highlight view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Highlight(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_HIGHLIGHT)
|
||||
|
||||
check(holder is Highlight)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice checkbox view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Checkbox(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_CHECKBOX)
|
||||
|
||||
check(holder is Checkbox)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice bullet view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Bulleted(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_BULLET)
|
||||
|
||||
check(holder is Bulleted)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice numbered view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Numbered(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString(),
|
||||
number = 1
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_NUMBERED)
|
||||
|
||||
check(holder is Numbered)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not trigger text changed event when binding twice toggle view holder`() {
|
||||
|
||||
var textChangedTriggerCount = 0
|
||||
|
||||
val a = BlockView.Text.Toggle(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
text = MockDataFactory.randomString()
|
||||
)
|
||||
|
||||
val views = listOf(a)
|
||||
|
||||
val adapter = buildAdapter(
|
||||
views = views,
|
||||
onTextBlockTextChanged = { textChangedTriggerCount += 1 }
|
||||
)
|
||||
|
||||
val recycler = RecyclerView(context).apply {
|
||||
this.layoutManager = LinearLayoutManager(context)
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_TOGGLE)
|
||||
|
||||
check(holder is Toggle)
|
||||
|
||||
// TESTING
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
assertEquals(
|
||||
expected = 0,
|
||||
actual = textChangedTriggerCount
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected = a.text,
|
||||
actual = holder.content.text.toString()
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue