36fe52e5ad
* DROID-439 App | Relations refactoring, use SearchObjects for object types (#2592) * DROID-446 Objects | Enhancement | Store relation links and process its updates (#2597) * DROID-456 Tech | Remove deprecated API for creating object types (#2601) * DROID-455 Object types | Enhancement Get object type list from ObjectSearch on Global search screen (#2602) * DROID-459 Sets | Refactoring | Use relations links instead of relations for building search params to get data view data (#2603) * DROID-458 Objects | Refactoring | Integrate new api for creating objets (#2604) * DROID-464 Relations | Refactoring | New API for creating a relation from scratch - for data view or for an object (#2605) * DROID-467 Relations | Refactoring | New API for creating options - for tags and statuses (#2607) * DROID-470 Relations | Refactoring | New API for removing any relation from an object or from a data view (#2608) * DROID-460 Tech | Object relations list (#2610) * DROID-486 Sets | Refactoring | Displaying and controlling visibility of data view relations (#2611) * DROID-500 Relations | Refactoring | Extend API of ObjectStore to be able to get a relation by its id (#2619) * DROID-459 Sets | Fix | Get relations from store by id and not by key (#2618) * DROID-489 Tech | Relations as object, add relationKey to relation connected screens (#2622) * DROID-490 Sets | Refactoring | Displaying relation values for current object in bottom sheet cells (#2629) * DROID-505 Relations | Refactoring | New interface for relations store (#2633) * DROID-509 Relations | Refactoring | Bind new relations store with subscription container (#2635) * DROID-507 Tech | MW , migration + relation links (#2636) * DROID-507 Tech | MW , migration + relation links, fixes (#2637) * DROID-517 Sets | Fix | Provide correct keys for data view search-and-subscribe query (#2641) * DROID-409 Relations | Refactoring | Use relation key instead of id when creating new relation (#2642) * DROID-521 Sets & Objects | Refactoring | Add relation to a data view or to an object from existing relations (#2644) * DROID-522 Relations | Refactoring | Add objects to relations with object format (#2645) * DROID-523 Object types | Refactoring | Implement global store for object types (#2646) * DROID-527 Object types | Refactoring | Integrate global store for object types (#2647) * DROID-531 Relations | Refactoring | Parse tag and status relations values (#2649) * DROID-535 Tech | Integrate new MW lib with migration fixes (#2653) * DROID-535 Tech | MW integration fixes (#2660) * DROID-559 Relations | Refactoring | Parse tag and status values in editor (#2662) * DROID-560 Relations | Refactoring | Integrate new lib with fixes (#2663) * DROID-561 Relations | Refactoring | Parsing tag and status values in dv (#2665) * DROID-562 Dashboard | Refactoring | Use store of object types as object type provider for favorites tab on dashboard (#2667) * DROID-567 Relations | Refactoring | Suggest available options to populate a relation (#2671) * DROID-604 Relations | Refactoring | Use details from Object.CreateRelation.Response to populate relation store (#2705) * DROID-603 Relations | Refactoring | Creating relation options + Deleting relation from object (#2706) * DROID-619 Relations | Refactoring | Migrate data view sorts and filters to the new relation-as-object paradigm (#2711) * DROID-622 Relations | Tech | Update MW to 0.24.0-rc1 (#2714) * DROID-598 Sets | Refactoring | Provide relation format for date filters (#2715) * DROID-625 Protocol | Enhancement | Integrate v0.24.0-rc2 (#2718)
669 lines
21 KiB
Kotlin
669 lines
21 KiB
Kotlin
package com.anytypeio.anytype.features.relations
|
|
|
|
import android.os.Bundle
|
|
import androidx.core.os.bundleOf
|
|
import androidx.fragment.app.testing.FragmentScenario
|
|
import androidx.fragment.app.testing.launchFragmentInContainer
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
|
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import androidx.test.filters.LargeTest
|
|
import com.anytypeio.anytype.R
|
|
import com.anytypeio.anytype.analytics.base.Analytics
|
|
import com.anytypeio.anytype.core_models.Block
|
|
import com.anytypeio.anytype.core_models.Id
|
|
import com.anytypeio.anytype.core_models.Payload
|
|
import com.anytypeio.anytype.core_models.Relation
|
|
import com.anytypeio.anytype.core_models.ThemeColor
|
|
import com.anytypeio.anytype.core_ui.extensions.dark
|
|
import com.anytypeio.anytype.core_utils.const.DateConst
|
|
import com.anytypeio.anytype.core_utils.ext.toTimeSeconds
|
|
import com.anytypeio.anytype.domain.`object`.UpdateDetail
|
|
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
|
import com.anytypeio.anytype.domain.config.Gateway
|
|
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
|
import com.anytypeio.anytype.domain.objects.StoreOfRelations
|
|
import com.anytypeio.anytype.domain.relations.AddToFeaturedRelations
|
|
import com.anytypeio.anytype.domain.relations.DeleteRelationFromObject
|
|
import com.anytypeio.anytype.domain.relations.ObjectRelationList
|
|
import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations
|
|
import com.anytypeio.anytype.presentation.editor.Editor
|
|
import com.anytypeio.anytype.presentation.editor.editor.DetailModificationManager
|
|
import com.anytypeio.anytype.presentation.relations.ObjectRelationListViewModelFactory
|
|
import com.anytypeio.anytype.presentation.util.Dispatcher
|
|
import com.anytypeio.anytype.test_utils.MockDataFactory
|
|
import com.anytypeio.anytype.test_utils.utils.checkHasText
|
|
import com.anytypeio.anytype.test_utils.utils.checkHasTextColor
|
|
import com.anytypeio.anytype.test_utils.utils.checkIsRecyclerSize
|
|
import com.anytypeio.anytype.test_utils.utils.onItemView
|
|
import com.anytypeio.anytype.test_utils.utils.rVMatcher
|
|
import com.anytypeio.anytype.test_utils.utils.resources
|
|
import com.anytypeio.anytype.ui.relations.RelationListFragment
|
|
import com.anytypeio.anytype.utils.CoroutinesTestRule
|
|
import com.bartoszlipinski.disableanimationsrule.DisableAnimationsRule
|
|
import kotlinx.coroutines.runBlocking
|
|
import org.junit.Before
|
|
import org.junit.Rule
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
import org.mockito.Mock
|
|
import org.mockito.MockitoAnnotations
|
|
import java.text.SimpleDateFormat
|
|
import java.util.*
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
@LargeTest
|
|
class ObjectRelationListTest {
|
|
|
|
@get:Rule
|
|
val animationsRule = DisableAnimationsRule()
|
|
|
|
@get:Rule
|
|
val coroutineTestRule = CoroutinesTestRule()
|
|
|
|
@Mock
|
|
lateinit var gateway: Gateway
|
|
|
|
@Mock
|
|
lateinit var repo: BlockRepository
|
|
|
|
@Mock
|
|
lateinit var dispatcher: Dispatcher<Payload>
|
|
|
|
@Mock
|
|
lateinit var detailModificationManager: DetailModificationManager
|
|
|
|
@Mock
|
|
lateinit var analytics: Analytics
|
|
|
|
@Mock
|
|
lateinit var storeOfRelations: StoreOfRelations
|
|
|
|
private lateinit var objectRelationList: ObjectRelationList
|
|
private lateinit var updateDetail: UpdateDetail
|
|
private lateinit var addToFeaturedRelations: AddToFeaturedRelations
|
|
private lateinit var removeFromFeaturedRelations: RemoveFromFeaturedRelations
|
|
private lateinit var deleteRelationFromObject: DeleteRelationFromObject
|
|
|
|
private val ctx = MockDataFactory.randomUuid()
|
|
private val storage = Editor.Storage()
|
|
|
|
lateinit var urlBuilder: UrlBuilder
|
|
|
|
@Before
|
|
fun setup() {
|
|
MockitoAnnotations.openMocks(this)
|
|
urlBuilder = UrlBuilder(gateway)
|
|
objectRelationList = ObjectRelationList(repo)
|
|
updateDetail = UpdateDetail(repo)
|
|
addToFeaturedRelations = AddToFeaturedRelations(repo)
|
|
removeFromFeaturedRelations = RemoveFromFeaturedRelations(repo)
|
|
deleteRelationFromObject = DeleteRelationFromObject(repo)
|
|
TestRelationListFragment.testVmFactory = ObjectRelationListViewModelFactory(
|
|
stores = storage,
|
|
urlBuilder = urlBuilder,
|
|
objectRelationList = objectRelationList,
|
|
dispatcher = dispatcher,
|
|
detailModificationManager = detailModificationManager,
|
|
updateDetail = updateDetail,
|
|
addToFeaturedRelations = addToFeaturedRelations,
|
|
removeFromFeaturedRelations = removeFromFeaturedRelations,
|
|
deleteRelationFromObject = deleteRelationFromObject,
|
|
analytics = analytics,
|
|
storeOfRelations = storeOfRelations
|
|
)
|
|
}
|
|
|
|
@Test(expected = RuntimeException::class)
|
|
fun shouldThrowAnExceptionIfArgsNotProvided() {
|
|
launchFragment(bundleOf())
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayOneRelationWithoutValueInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name = "Description"
|
|
|
|
val relation = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(
|
|
listOf(relation)
|
|
)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText("")
|
|
checkIsRecyclerSize(2)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayOnlyFirstRelationBecauseSecondIsHiddenInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name1 = "Description"
|
|
val name2 = "Identifier"
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
isHidden = true,
|
|
name = name1
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name2
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(
|
|
listOf(relation1, relation2)
|
|
)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText("")
|
|
checkIsRecyclerSize(2)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoRelationsWithoutValueInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name1 = "Description"
|
|
val name2 = "Comment"
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name1
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name2
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(
|
|
listOf(relation1, relation2)
|
|
)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name1)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText("")
|
|
onItemView(2, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(2, R.id.tvRelationValue).checkHasText("")
|
|
checkIsRecyclerSize(3)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoRelationsWithValuesInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name1 = "Description"
|
|
val name2 = "Comment"
|
|
val value1 = "A mountain is an elevated portion of the Earth's crust, generally with steep sides that show significant exposed bedrock."
|
|
val value2 = "We've never seen that mountain before."
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name1
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.LONG_TEXT,
|
|
source = Relation.Source.values().random(),
|
|
name = name2
|
|
)
|
|
|
|
val relations = listOf(relation1, relation2)
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation1.key to value1,
|
|
relation2.key to value2,
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(
|
|
bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
)
|
|
)
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name1)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText(value1)
|
|
onItemView(2, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(2, R.id.tvRelationValue).checkHasText(value2)
|
|
checkIsRecyclerSize(3)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoObjectRelationsWithNameAndAvatarInitialsInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name1 = "Assignee"
|
|
val target1: Id = MockDataFactory.randomUuid()
|
|
val username1 = "Konstantin"
|
|
|
|
val name2 = "Created by"
|
|
val target2: Id = MockDataFactory.randomUuid()
|
|
val username2 = "Roman"
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.OBJECT,
|
|
source = Relation.Source.values().random(),
|
|
name = name1
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.OBJECT,
|
|
source = Relation.Source.values().random(),
|
|
name = name2
|
|
)
|
|
|
|
val relations = listOf(relation1, relation2)
|
|
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation1.key to target1,
|
|
relation2.key to target2,
|
|
)
|
|
),
|
|
target1 to Block.Fields(
|
|
mapOf(
|
|
Block.Fields.NAME_KEY to username1
|
|
)
|
|
),
|
|
target2 to Block.Fields(
|
|
mapOf(
|
|
Block.Fields.NAME_KEY to username2
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name1)
|
|
onItemView(1, R.id.obj0).check(matches(hasDescendant(withText(username1))))
|
|
onItemView(2, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(2, R.id.obj0).check(matches(hasDescendant(withText(username2))))
|
|
checkIsRecyclerSize(3)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoDateRelationsInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val format = SimpleDateFormat(DateConst.DEFAULT_DATE_FORMAT, Locale.getDefault())
|
|
|
|
val name1 = "Date of birth"
|
|
val date1 = System.currentTimeMillis()
|
|
val date1Screen = format.format(Date(date1))
|
|
|
|
val name2 = "Last modified at"
|
|
val date2 = System.currentTimeMillis()
|
|
val date2Screen = format.format(Date(date2))
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.DATE,
|
|
source = Relation.Source.values().random(),
|
|
name = name1,
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.DATE,
|
|
source = Relation.Source.values().random(),
|
|
name = name2
|
|
)
|
|
|
|
val relations = listOf(relation1, relation2)
|
|
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation1.key to date1.toTimeSeconds(),
|
|
relation2.key to date2.toTimeSeconds(),
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name1)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText(date1Screen)
|
|
onItemView(2, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(2, R.id.tvRelationValue).checkHasText(date2Screen)
|
|
checkIsRecyclerSize(3)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoStatusRelationsInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val color1 = ThemeColor.RED
|
|
val color2 = ThemeColor.TEAL
|
|
|
|
val option1 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "In progress",
|
|
color = color1.code
|
|
)
|
|
|
|
val option2 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "Done",
|
|
color = color2.code
|
|
)
|
|
|
|
val name1 = "Status 1"
|
|
val name2 = "Status 2"
|
|
|
|
val relation1 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.STATUS,
|
|
source = Relation.Source.values().random(),
|
|
name = name1,
|
|
selections = listOf(option1)
|
|
)
|
|
|
|
val relation2 = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.STATUS,
|
|
source = Relation.Source.values().random(),
|
|
name = name2,
|
|
selections = listOf(option2)
|
|
)
|
|
|
|
val relations = listOf(relation1, relation2)
|
|
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation1.key to option1.id,
|
|
relation2.key to option2.id,
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name1)
|
|
onItemView(1, R.id.tvRelationValue).checkHasText(option1.text)
|
|
onItemView(1, R.id.tvRelationValue).checkHasTextColor(resources.dark(color1))
|
|
onItemView(2, R.id.tvRelationTitle).checkHasText(name2)
|
|
onItemView(2, R.id.tvRelationValue).checkHasText(option2.text)
|
|
onItemView(2, R.id.tvRelationValue).checkHasTextColor(resources.dark(color2))
|
|
checkIsRecyclerSize(3)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayFourTagRelationsInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val color1 = ThemeColor.RED
|
|
val color2 = ThemeColor.TEAL
|
|
val color3 = ThemeColor.ICE
|
|
val color4 = ThemeColor.PURPLE
|
|
|
|
val name = "Role"
|
|
|
|
val option1 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "Essayist",
|
|
color = color1.code
|
|
)
|
|
|
|
val option2 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "Journalist",
|
|
color = color2.code
|
|
)
|
|
|
|
val option3 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "Politik",
|
|
color = color3.code
|
|
)
|
|
|
|
val option4 = Relation.Option(
|
|
id = MockDataFactory.randomUuid(),
|
|
text = "Critic",
|
|
color = color4.code
|
|
)
|
|
|
|
val relation = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.TAG,
|
|
source = Relation.Source.values().random(),
|
|
name = name,
|
|
selections = listOf(option1, option2, option3, option4)
|
|
)
|
|
|
|
val relations = listOf(relation)
|
|
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation.key to listOf(option1.id, option2.id, option3.id, option4.id)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name)
|
|
onItemView(1, R.id.tag0).check(matches((withText(option1.text))))
|
|
onItemView(1, R.id.tag1).check(matches((withText(option2.text))))
|
|
onItemView(1, R.id.tag2).check(matches((withText(option3.text))))
|
|
onItemView(1, R.id.tag3).check(matches((withText(option4.text))))
|
|
checkIsRecyclerSize(2)
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun shouldDisplayTwoFileRelationsInsideOtherRelationsSection() {
|
|
|
|
// SETUP
|
|
|
|
val name = "Attachement"
|
|
|
|
val relation = Relation(
|
|
key = MockDataFactory.randomUuid(),
|
|
format = Relation.Format.FILE,
|
|
source = Relation.Source.values().random(),
|
|
name = name,
|
|
selections = emptyList()
|
|
)
|
|
|
|
val relations = listOf(relation)
|
|
|
|
val file1 = MockDataFactory.randomUuid()
|
|
val file2 = MockDataFactory.randomUuid()
|
|
|
|
val details = Block.Details(
|
|
mapOf(
|
|
ctx to Block.Fields(
|
|
mapOf(
|
|
relation.key to listOf(file1, file2)
|
|
)
|
|
),
|
|
file1 to Block.Fields(
|
|
mapOf(
|
|
"name" to "Document",
|
|
"ext" to "pdf",
|
|
"mime" to "application/pdf"
|
|
)
|
|
),
|
|
file2 to Block.Fields(
|
|
mapOf(
|
|
"name" to "Image",
|
|
"ext" to "jpg",
|
|
"mime" to "image/jpeg"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
runBlocking {
|
|
storage.relations.update(relations)
|
|
storage.details.update(details)
|
|
}
|
|
|
|
launchFragment(bundleOf(
|
|
RelationListFragment.ARG_CTX to ctx,
|
|
RelationListFragment.ARG_MODE to RelationListFragment.MODE_LIST
|
|
))
|
|
|
|
// TESTING
|
|
|
|
with(R.id.recycler.rVMatcher()) {
|
|
onItemView(0, R.id.tvSectionName).checkHasText(R.string.other_relations)
|
|
onItemView(1, R.id.tvRelationTitle).checkHasText(name)
|
|
onItemView(1, R.id.file0).check(matches(hasDescendant(withText("Document"))))
|
|
onItemView(1, R.id.file1).check(matches(hasDescendant(withText("Image"))))
|
|
checkIsRecyclerSize(2)
|
|
}
|
|
}
|
|
|
|
private fun launchFragment(args: Bundle): FragmentScenario<TestRelationListFragment> {
|
|
return launchFragmentInContainer(
|
|
fragmentArgs = args,
|
|
themeResId = R.style.AppTheme
|
|
)
|
|
}
|
|
} |