1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-07 21:37:02 +09:00

DROID-2326 App | Tech | Update Kotlin, Gradle, Compose and other framework libraries (#1017)

This commit is contained in:
Mikhail 2024-03-27 17:21:20 +01:00 committed by GitHub
parent c3c30e6e26
commit 6e8d8c78fc
Signed by: github
GPG key ID: B5690EEEBB952194
100 changed files with 1769 additions and 1424 deletions

View file

@ -14,15 +14,6 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.analytics'
}

View file

@ -127,15 +127,6 @@ android {
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
splits {
// Configures multiple APKs based on ABI.
abi {

View file

@ -36,7 +36,6 @@ class AndroidApplication : Application(), HasComponentDependencies {
@Inject
override lateinit var dependencies: ComponentDependenciesProvider
protected set
private val main: MainComponent by lazy {
DaggerMainComponent

View file

@ -144,7 +144,7 @@ interface MainComponent :
}
@Module
private abstract class ComponentDependenciesModule private constructor() {
abstract class ComponentDependenciesModule {
@Binds
@IntoMap

View file

@ -1,4 +1,5 @@
import com.android.build.gradle.LibraryPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
buildscript {
ext.compile_sdk = 34
@ -70,6 +71,18 @@ subprojects {
}
}
}
if (plugin instanceof KotlinAndroidPluginWrapper) {
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
}
}
}
plugins.withId("kotlin") {

View file

@ -16,15 +16,6 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.clipboard'
}

View file

@ -19,15 +19,6 @@ android {
compose true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.core_ui'
}

View file

@ -13,15 +13,6 @@ android {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.core_utils'
}

View file

@ -18,19 +18,11 @@ android {
includeDependenciesReport = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.crash_reporting'
}
dependencies {
implementation libs.timber
implementation libs.sentry
implementation libs.sentryTimber
implementation project(path: ':core-utils')

View file

@ -24,14 +24,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.device'
}

View file

@ -15,13 +15,6 @@ android {
kotlinCompilerExtensionVersion libs.versions.composeKotlinCompilerVersion.get()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.galleryexperience'
}

View file

@ -1,33 +1,33 @@
[versions]
middlewareVersion = "v0.33.0-rc2"
kotlinVersion = '1.8.22'
kotlinVersion = '1.9.22'
androidxCoreVersion = "1.12.0"
androidxComposeVersion = '1.5.0'
composeKotlinCompilerVersion = '1.4.8'
composeMaterial3Version = '1.2.0'
composeMaterialVersion = '1.5.0'
androidxComposeVersion = '1.6.3'
composeKotlinCompilerVersion = '1.5.10'
composeMaterial3Version = '1.2.1'
composeMaterialVersion = '1.6.3'
composeConstraintLayoutVersion = '1.0.1'
dokkaVersion = '1.8.20'
dokkaVersion = '1.9.20'
activityComposeVersion = '1.8.1'
composeReorderableVersion = '0.9.6'
activityComposeVersion = '1.8.2'
composeReorderableVersion = 'e9ef693f63'
accompanistVersion = "0.34.0"
appcompatVersion = '1.6.1'
androidXAnnotationVersion = '1.7.0'
androidXAnnotationVersion = '1.7.1'
fragmentVersion = "1.6.2"
exoplayerVersion = "2.19.1"
wireVersion = "4.5.2"
wireVersion = "4.9.8"
glideVersion = "4.14.2"
mockitoKotlinVersion = "5.1.0"
mockitoKotlinVersion = "5.2.1"
junitVersion = '4.13.2'
androidJunitVersion = "1.1.4"
androidJunitVersion = "1.1.5"
runnerVersion = "1.5.0"
mockitoAndroidVersion = '4.10.0'
kotlinCoroutinesVersion = '1.6.4'
coroutineTestingVersion = '1.6.4'
mockitoAndroidVersion = '5.11.0'
kotlinCoroutinesVersion = '1.8.0'
coroutineTestingVersion = '1.8.0'
androidxTestCoreVersion = '1.5.0'
androidxCoreTestingVersion = '2.2.0'
androidxSecurityCryptoVersion = '1.0.0'
@ -37,37 +37,37 @@ recyclerviewVersion = '1.3.2'
cardviewVersion = '1.0.0'
emojiCompatVersion = '1.1.0'
viewPager2Version = '1.0.0'
lifecycleVersion = '2.6.2'
lifecycleRuntimeComposeVersion = '2.7.0-rc01'
navigationVersion = '2.7.5'
navigationComposeVersion = '2.7.5'
lifecycleVersion = '2.7.0'
lifecycleRuntimeComposeVersion = '2.7.0'
navigationVersion = '2.7.7'
navigationComposeVersion = '2.7.7'
shimmerLayoutVersion = '0.5.0'
photoViewVersion = '2.3.0'
daggerVersion = '2.45'
daggerVersion = '2.51'
javaxAnnotationsVersion = '1.0'
javaxInjectVersion = '1'
gsonVersion = '2.10'
gsonVersion = '2.10.1'
betterLinkMethodVersion = '2.2.0'
picktVersion = '2.0.2'
zxingVersion = '4.1.0'
picktVersion = '2.0.5'
zxingVersion = '4.3.0'
urlcleanerVersion = '0.4.0'
katexVersion = '1.0.2'
robolectricLatestVersion = '4.10.3'
robolectricLatestVersion = '4.11.1'
kluentVersion = '1.14'
timberJunitVersion = '1.0.1'
turbineVersion = '0.12.1'
liveDataTestingVersion = '1.2.0'
turbineVersion = '1.1.0'
liveDataTestingVersion = '1.3.0'
espressoVersion = '3.5.1'
disableAnimationVersion = '2.0.0'
leakCanaryVersion = '2.12'
timberVersion = '5.0.1'
protobufJavaVersion = '3.9.2'
protocVersion = '3.9.0'
roomVersion = '2.5.2'
roomVersion = '2.6.1'
dataStoreVersion = '1.0.0'
amplitudeVersion = '2.36.1'
coilComposeVersion = '2.2.2'
sentryVersion = '6.0.0'
amplitudeVersion = '3.35.1'
coilComposeVersion = '2.6.0'
sentryVersion = '7.6.0'
[libraries]
middleware = { module = "io.anyproto:anytype-heart-android", version.ref = "middlewareVersion" }
@ -85,12 +85,12 @@ composeAccompanistPermissions = { module = "com.google.accompanist:accompanist-p
composeAccompanistPagerIndicators = { module = "com.google.accompanist:accompanist-pager-indicators", version.ref = "accompanistVersion" }
composeAccompanistThemeAdapter = { module = "com.google.accompanist:accompanist-themeadapter-material", version.ref = "accompanistVersion" }
composeAccompanistNavigation = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanistVersion" }
composeReorderable = { module = "org.burnoutcrew.composereorderable:reorderable", version.ref = "composeReorderableVersion" }
composeReorderable = { module = "com.github.fat-fellow.ComposeReorderable:reorderable", version.ref = "composeReorderableVersion" }
composeConstraintLayout = { module = "androidx.constraintlayout:constraintlayout-compose", version.ref = "composeConstraintLayoutVersion" }
kotlinxSerializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.4.1" }
kotlinxSerializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.6.3" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompatVersion" }
androidAnnotations = { module = "androidx.annotation:annotation", version.ref = "androidXAnnotationVersion" }
design = { module = "com.google.android.material:material", version = "1.7.0" }
design = { module = "com.google.android.material:material", version = "1.11.0" }
fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentVersion" }
fragmentTesting = { module = "androidx.fragment:fragment-testing", version.ref = "fragmentVersion" }
exoPlayerCore = { module = "com.google.android.exoplayer:exoplayer-core", version.ref = "exoplayerVersion" }
@ -168,12 +168,12 @@ appUpdater = { module = "com.github.PLPsiSoft:AndroidAppUpdater", version = "991
[bundles]
[plugins]
application = { id = "com.android.application", version = "8.2.0" }
library = { id = "com.android.library", version = "8.2.0" }
application = { id = "com.android.application", version = "8.3.1" }
library = { id = "com.android.library", version = "8.3.1" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaVersion" }
kserialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinVersion" }
wire = { id = "com.squareup.wire", version = "4.4.3" }
firebaseDistribution = { id = "com.google.firebase.appdistribution", version = "4.0.1" }
wire = { id = "com.squareup.wire", version = "4.9.8" }
firebaseDistribution = { id = "com.google.firebase.appdistribution", version = "4.2.0" }
kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlinVersion" }
gms = { id = "com.google.gms.google-services", version = "4.4.0" }
gms = { id = "com.google.gms.google-services", version = "4.4.1" }

Binary file not shown.

View file

@ -1,6 +1,7 @@
#Thu Dec 14 17:20:55 CET 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

41
gradlew vendored
View file

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -80,13 +80,11 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
@ -205,6 +214,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

15
gradlew.bat vendored
View file

@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

View file

@ -16,14 +16,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.emojifier'
}

View file

@ -7,14 +7,6 @@ android {
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.library_page_icon_picker_widget'
}

View file

@ -20,13 +20,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.library_syntax_highlighter'
}

View file

@ -9,13 +9,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.localization'
}

View file

@ -26,13 +26,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.middleware'
}

View file

@ -14,14 +14,6 @@ android {
composeOptions {
kotlinCompilerExtensionVersion libs.versions.composeKotlinCompilerVersion.get()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.peyments'
}

View file

@ -37,13 +37,6 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.persistence'
}

View file

@ -19,14 +19,6 @@ android {
buildConfigField "boolean", "ENABLE_WIDGETS", "false"
buildConfigField "boolean", "ENABLE_VIEWS_MENU", "true"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.presentation'
}

View file

@ -50,6 +50,7 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
objectCollection = MockCollection(context = root, space = defaultSpace)
viewModel = givenViewModel()
stubNetworkMode()
}
@After

View file

@ -31,6 +31,7 @@ class CollectionDataViewUpdateTest : ObjectSetViewModelTestSetup() {
viewModel = givenViewModel()
objectCollection = MockCollection(context = root, space = defaultSpace)
stubGetDefaultPageType()
stubNetworkMode()
}
@After

View file

@ -1,6 +1,6 @@
package com.anytypeio.anytype.presentation.collections
import app.cash.turbine.testIn
import app.cash.turbine.turbineScope
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectWrapper
@ -36,6 +36,7 @@ class ObjectCreateTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
stubNetworkMode()
stubCreateDataViewObject()
}
@After
@ -122,61 +123,41 @@ class ObjectCreateTest : ObjectSetViewModelTestSetup() {
@Test
fun `Should create and open Not-Note Object when clicking on New button in Set by Type`() =
runTest {
turbineScope {
val setOfId = "setOf-id-${RandomString.make()}"
val setOfKey = ObjectTypeIds.PAGE
val setOfId = "setOf-id-${RandomString.make()}"
val setOfKey = ObjectTypeIds.PAGE
mockObjectSet = MockSet(
context = root,
space = defaultSpace,
setOfValue = setOfId,
setOfKey = setOfKey
)
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
dvFilters = mockObjectSet.filters,
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2)
)
val newObjectId = "objNewPage-${RandomString.make()}"
val result = CreateDataViewObject.Result(
objectId = newObjectId,
objectType = TypeKey(ObjectTypeIds.PAGE)
)
doReturn(Resultat.success(result)).`when`(createDataViewObject).async(
CreateDataViewObject.Params.SetByType(
type = TypeKey(setOfKey),
filters = mockObjectSet.filters,
template = null,
prefilled = emptyMap()
mockObjectSet = MockSet(
context = root,
space = defaultSpace,
setOfValue = setOfId,
setOfKey = setOfKey
)
)
doReturn(Resultat.success(Unit)).`when`(closeBlock).async(mockObjectSet.root)
// TESTING
proceedWithStartingViewModel()
val commandFlow = viewModel.commands.testIn(backgroundScope)
advanceUntilIdle()
viewModel.proceedWithDataViewObjectCreate()
advanceUntilIdle()
verifyBlocking(createDataViewObject, times(1)) {
async(
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
dvFilters = mockObjectSet.filters,
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2)
)
val newObjectId = "objNewPage-${RandomString.make()}"
val result = CreateDataViewObject.Result(
objectId = newObjectId,
objectType = TypeKey(ObjectTypeIds.PAGE),
struct = mapOf("spaceId" to "spaceId")
)
doReturn(Resultat.success(result)).`when`(createDataViewObject).async(
CreateDataViewObject.Params.SetByType(
type = TypeKey(setOfKey),
filters = mockObjectSet.filters,
@ -184,6 +165,29 @@ class ObjectCreateTest : ObjectSetViewModelTestSetup() {
prefilled = emptyMap()
)
)
doReturn(Resultat.success(Unit)).`when`(closeBlock).async(mockObjectSet.root)
// TESTING
proceedWithStartingViewModel()
val commandFlow = viewModel.commands.testIn(backgroundScope)
advanceUntilIdle()
viewModel.proceedWithDataViewObjectCreate()
advanceUntilIdle()
verifyBlocking(createDataViewObject, times(1)) {
async(
CreateDataViewObject.Params.SetByType(
type = TypeKey(setOfKey),
filters = mockObjectSet.filters,
template = null,
prefilled = emptyMap()
)
)
}
commandFlow.cancelAndIgnoreRemainingEvents()
}
}
@ -225,6 +229,7 @@ class ObjectCreateTest : ObjectSetViewModelTestSetup() {
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubCreateDataViewObject()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.detailsSetByRelation(relationSetBy)
@ -279,85 +284,87 @@ class ObjectCreateTest : ObjectSetViewModelTestSetup() {
}
@Test
fun `Should create new Object and not close Set when clicking on New button in Collection`() = runTest {
fun `Should create new Object and not close Set when clicking on New button in Collection`() =
runTest {
val objectCollection = MockCollection(context = root, space = defaultSpace)
val objectCollection = MockCollection(context = root, space = defaultSpace)
// SETUP
stubSpaceManager(objectCollection.spaceId)
stubStoreOfRelations(objectCollection)
stubSubscriptionResults(
subscription = objectCollection.subscriptionId,
collection = root,
spaceId = objectCollection.spaceId,
storeOfRelations = storeOfRelations,
keys = objectCollection.dvKeys,
objects = listOf(objectCollection.obj1, objectCollection.obj2),
dvSorts = objectCollection.sorts
)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(
objectCollection.header,
objectCollection.title,
objectCollection.dataView
),
details = objectCollection.details
)
val pageTypeId = ObjectState.VIEW_DEFAULT_OBJECT_TYPE
val pageTypeMap = mapOf(
Relations.ID to MockDataFactory.randomString(),
Relations.UNIQUE_KEY to pageTypeId,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE,
Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble(),
Relations.LAYOUT to ObjectType.Layout.OBJECT_TYPE.code.toDouble(),
Relations.NAME to MockDataFactory.randomString(),
Relations.DEFAULT_TEMPLATE_ID to null
)
with(storeOfObjectTypes) {
set(pageTypeId, pageTypeMap)
}
val newObjectId = "objNew-${RandomString.make()}"
val result = CreateDataViewObject.Result(
objectId = newObjectId,
objectType = TypeKey(pageTypeId),
struct = null
)
doReturn(Resultat.success(result)).`when`(createDataViewObject).async(
CreateDataViewObject.Params.Collection(
template = null,
type = TypeKey(pageTypeId),
filters = emptyList(),
prefilled = emptyMap()
// SETUP
stubSpaceManager(objectCollection.spaceId)
stubStoreOfRelations(objectCollection)
stubSubscriptionResults(
subscription = objectCollection.subscriptionId,
collection = root,
spaceId = objectCollection.spaceId,
storeOfRelations = storeOfRelations,
keys = objectCollection.dvKeys,
objects = listOf(objectCollection.obj1, objectCollection.obj2),
dvSorts = objectCollection.sorts
)
stubInterceptEvents()
stubInterceptThreadStatus()
stubAddObjectToCollection()
stubOpenObject(
doc = listOf(
objectCollection.header,
objectCollection.title,
objectCollection.dataView
),
details = objectCollection.details
)
)
doReturn(Resultat.success(Unit)).`when`(closeBlock).async(objectCollection.root)
// TESTING
proceedWithStartingViewModel()
val pageTypeId = ObjectState.VIEW_DEFAULT_OBJECT_TYPE
val pageTypeMap = mapOf(
Relations.ID to MockDataFactory.randomString(),
Relations.UNIQUE_KEY to pageTypeId,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE,
Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble(),
Relations.LAYOUT to ObjectType.Layout.OBJECT_TYPE.code.toDouble(),
Relations.NAME to MockDataFactory.randomString(),
Relations.DEFAULT_TEMPLATE_ID to null
)
with(storeOfObjectTypes) {
set(pageTypeId, pageTypeMap)
}
advanceUntilIdle()
viewModel.proceedWithDataViewObjectCreate()
advanceUntilIdle()
verifyBlocking(createDataViewObject, times(1)) {
async(
val newObjectId = "objNew-${RandomString.make()}"
val result = CreateDataViewObject.Result(
objectId = newObjectId,
objectType = TypeKey(pageTypeId),
struct = mapOf("spaceId" to "spaceId")
)
doReturn(Resultat.success(result)).`when`(createDataViewObject).async(
CreateDataViewObject.Params.Collection(
type = TypeKey(pageTypeId),
template = null,
type = TypeKey(pageTypeId),
filters = emptyList(),
prefilled = emptyMap()
)
)
}
doReturn(Resultat.success(Unit)).`when`(closeBlock).async(objectCollection.root)
verifyNoInteractions(closeBlock)
}
// TESTING
proceedWithStartingViewModel()
advanceUntilIdle()
viewModel.proceedWithDataViewObjectCreate()
advanceUntilIdle()
verifyBlocking(createDataViewObject, times(1)) {
async(
CreateDataViewObject.Params.Collection(
type = TypeKey(pageTypeId),
template = null,
filters = emptyList(),
prefilled = emptyMap()
)
)
}
verifyNoInteractions(closeBlock)
}
private fun proceedWithStartingViewModel() {
viewModel.onStart(ctx = root, space = defaultSpace)

View file

@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.collections
import app.cash.turbine.test
import app.cash.turbine.testIn
import app.cash.turbine.turbineScope
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
@ -41,6 +42,7 @@ class ObjectStateSetViewTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
mockObjectSet = MockSet(context = root, space = defaultSpace)
stubNetworkMode()
}
@After
@ -50,404 +52,418 @@ class ObjectStateSetViewTest : ObjectSetViewModelTestSetup() {
@Test
fun `displaying error state when object with layout other than set or collection`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
turbineScope {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
val objectDetails = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble()
val objectDetails = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble()
)
)
)
)
)
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title),
details = objectDetails
)
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title),
details = objectDetails
)
// TESTING
proceedWithStartingViewModel()
// TESTING
proceedWithStartingViewModel()
// ASSERT COLLECTION OBJECT STATE
stateReducer.state.test {
val first = awaitItem()
assertIs<ObjectState.Init>(first)
expectNoEvents()
}
// ASSERT COLLECTION OBJECT STATE
stateReducer.state.test {
val first = awaitItem()
assertIs<ObjectState.Init>(first)
expectNoEvents()
}
// ASSERT DATA VIEW STATE
viewModel.currentViewer.test {
val first = awaitItem()
assertIs<DataViewViewState.Init>(first)
// ASSERT DATA VIEW STATE
viewModel.currentViewer.test {
val first = awaitItem()
assertIs<DataViewViewState.Init>(first)
val second = awaitItem()
assertIs<DataViewViewState.Error>(second)
val second = awaitItem()
assertIs<DataViewViewState.Error>(second)
assertEquals(expected = "Wrong layout, couldn't open object", actual = second.msg)
expectNoEvents()
assertEquals(expected = "Wrong layout, couldn't open object", actual = second.msg)
expectNoEvents()
}
}
}
@Test
fun `displaying set init state when object with SET layout and no DataView`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
turbineScope {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title),
details = mockObjectSet.details
)
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title),
details = mockObjectSet.details
)
// TESTING
proceedWithStartingViewModel()
// TESTING
proceedWithStartingViewModel()
// ASSERT SET OBJECT STATE
stateReducer.state.test {
val first = awaitItem()
assertIs<ObjectState.Init>(first)
expectNoEvents()
}
// ASSERT SET OBJECT STATE
stateReducer.state.test {
val first = awaitItem()
assertIs<ObjectState.Init>(first)
expectNoEvents()
}
// ASSERT DATA VIEW STATE
viewModel.currentViewer.test {
val first = awaitItem()
assertIs<DataViewViewState.Init>(first)
expectNoEvents()
// ASSERT DATA VIEW STATE
viewModel.currentViewer.test {
val first = awaitItem()
assertIs<DataViewViewState.Init>(first)
expectNoEvents()
}
}
}
@Test
fun `displaying set no query state when object with DataView and empty setOf`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.detailsEmptySetOf
)
// TESTING
proceedWithStartingViewModel()
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoQuery>(viewerFlow.awaitItem())
}
@Test
fun `displaying set no view state when object with DataView and nullable view`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataViewNoViews),
details = mockObjectSet.details
)
// TESTING
proceedWithStartingViewModel()
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoView>(viewerFlow.awaitItem())
}
@Test
fun `displaying set with items state when object set with two records`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2),
dvFilters = mockObjectSet.filters
)
// TESTING
proceedWithStartingViewModel()
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.Default>(viewerFlow.awaitItem())
}
@Test
fun `displaying set with no items when opening object set with no records`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
dvFilters = mockObjectSet.filters
)
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<DataViewViewState.Set.NoItems>(viewerFlow.awaitItem())
}
@Test
fun `Displaying Object Sets with Non-Deleted Types Only`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
val typeDeleted1 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.IS_DELETED to true
turbineScope {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.detailsEmptySetOf
)
)
val type2 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE
)
)
val typeDeleted3 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
)
)
val detailsDeletedSetOf = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(),
Relations.SET_OF to listOf(typeDeleted1.id, type2.id, typeDeleted3.id)
)
),
typeDeleted1.id to Block.Fields(
mapOf(
Relations.ID to typeDeleted1.id,
Relations.IS_DELETED to true
)
),
type2.id to Block.Fields(
mapOf(
Relations.ID to type2.id,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE
)
)
)
)
// TESTING
proceedWithStartingViewModel()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = detailsDeletedSetOf
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(type2.id),
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2),
dvFilters = mockObjectSet.filters
)
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.Default>(viewerFlow.awaitItem())
stateFlow.ensureAllEventsConsumed()
viewerFlow.ensureAllEventsConsumed()
advanceUntilIdle()
verifyBlocking(repo, times(1)) {
searchObjectsWithSubscription(
eq(mockObjectSet.subscriptionId),
eq(listOf()),
eq(
mockObjectSet.filters + ObjectSearchConstants.defaultDataViewFilters(
spaces = listOf(spaceConfig.space, spaceConfig.techSpace)
)
),
eq(ObjectSearchConstants.defaultDataViewKeys + mockObjectSet.dvKeys),
eq(listOf(type2.id)),
eq(0L),
eq(ObjectSetConfig.DEFAULT_LIMIT),
eq(null),
eq(null),
eq(null),
eq(null),
eq(null)
)
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoQuery>(viewerFlow.awaitItem())
}
}
@Test
fun `Displaying Object Set with No Query State When All Types are Deleted`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
val typeDeleted1 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.IS_DELETED to true
)
)
val typeDeleted3 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
)
)
val detailsDeletedSetOf = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(),
Relations.SET_OF to listOf(typeDeleted1.id, typeDeleted3.id)
)
fun `displaying set no view state when object with DataView and nullable view`() = runTest {
turbineScope {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(
mockObjectSet.header,
mockObjectSet.title,
mockObjectSet.dataViewNoViews
),
typeDeleted1.id to Block.Fields(
mapOf(
Relations.ID to typeDeleted1.id,
Relations.IS_DELETED to true
details = mockObjectSet.details
)
// TESTING
proceedWithStartingViewModel()
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoView>(viewerFlow.awaitItem())
}
@Test
fun `displaying set with items state when object set with two records`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2),
dvFilters = mockObjectSet.filters
)
// TESTING
proceedWithStartingViewModel()
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.Default>(viewerFlow.awaitItem())
}
@Test
fun `displaying set with no items when opening object set with no records`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(mockObjectSet.setOf),
dvFilters = mockObjectSet.filters
)
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<DataViewViewState.Set.NoItems>(viewerFlow.awaitItem())
}
@Test
fun `Displaying Object Sets with Non-Deleted Types Only`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
val typeDeleted1 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.IS_DELETED to true
)
)
val type2 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE
)
)
val typeDeleted3 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
)
)
val detailsDeletedSetOf = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(),
Relations.SET_OF to listOf(typeDeleted1.id, type2.id, typeDeleted3.id)
)
),
typeDeleted1.id to Block.Fields(
mapOf(
Relations.ID to typeDeleted1.id,
Relations.IS_DELETED to true
)
),
type2.id to Block.Fields(
mapOf(
Relations.ID to type2.id,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE
)
)
)
)
)
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = detailsDeletedSetOf
)
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = detailsDeletedSetOf
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(type2.id),
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2),
dvFilters = mockObjectSet.filters
)
// TESTING
proceedWithStartingViewModel()
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoQuery>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.Default>(viewerFlow.awaitItem())
stateFlow.ensureAllEventsConsumed()
viewerFlow.ensureAllEventsConsumed()
}
stateFlow.ensureAllEventsConsumed()
viewerFlow.ensureAllEventsConsumed()
@Test
fun `displaying set with templates present when opening object set of pages with templates`() = runTest {
// SETUP
advanceUntilIdle()
verifyBlocking(repo, times(1)) {
searchObjectsWithSubscription(
eq(mockObjectSet.subscriptionId),
eq(listOf()),
eq(
mockObjectSet.filters + ObjectSearchConstants.defaultDataViewFilters(
spaces = listOf(spaceConfig.space, spaceConfig.techSpace)
)
),
eq(ObjectSearchConstants.defaultDataViewKeys + mockObjectSet.dvKeys),
eq(listOf(type2.id)),
eq(0L),
eq(ObjectSetConfig.DEFAULT_LIMIT),
eq(null),
eq(null),
eq(null),
eq(null),
eq(null)
)
}
}
mockObjectSet = MockSet(context = root, setOfValue = ObjectTypeIds.PAGE, space = defaultSpace)
val pageTypeMap = mapOf(
Relations.ID to ObjectTypeIds.PAGE,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE,
Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble(),
Relations.NAME to MockDataFactory.randomString()
)
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(ObjectTypeIds.PAGE),
dvFilters = mockObjectSet.filters
)
stubStoreOfObjectTypes(ObjectTypeIds.PAGE, pageTypeMap)
stubTemplatesForTemplatesContainer(
type = ObjectTypeIds.PAGE,
templates = listOf(StubObject(objectType = ObjectTypeIds.PAGE))
)
@Test
fun `Displaying Object Set with No Query State When All Types are Deleted`() = runTest {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
// TESTING
proceedWithStartingViewModel()
val typeDeleted1 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
Relations.IS_DELETED to true
)
)
val typeDeleted3 = ObjectWrapper.Type(
mapOf(
Relations.ID to RandomString.make(),
)
)
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
val detailsDeletedSetOf = Block.Details(
details = mapOf(
root to Block.Fields(
mapOf(
Relations.ID to root,
Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(),
Relations.SET_OF to listOf(typeDeleted1.id, typeDeleted3.id)
)
),
typeDeleted1.id to Block.Fields(
mapOf(
Relations.ID to typeDeleted1.id,
Relations.IS_DELETED to true
)
)
)
)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = detailsDeletedSetOf
)
val item = viewerFlow.awaitItem()
assertIs<DataViewViewState.Set.NoItems>(item)
assertTrue(item.isCreateObjectAllowed)
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Set.NoQuery>(viewerFlow.awaitItem())
stateFlow.ensureAllEventsConsumed()
viewerFlow.ensureAllEventsConsumed()
}
@Test
fun `displaying set with templates present when opening object set of pages with templates`() =
runTest {
// SETUP
mockObjectSet =
MockSet(context = root, setOfValue = ObjectTypeIds.PAGE, space = defaultSpace)
val pageTypeMap = mapOf(
Relations.ID to ObjectTypeIds.PAGE,
Relations.TYPE to ObjectTypeIds.OBJECT_TYPE,
Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble(),
Relations.NAME to MockDataFactory.randomString()
)
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
details = mockObjectSet.details
)
stubSubscriptionResults(
subscription = mockObjectSet.subscriptionId,
spaceId = mockObjectSet.spaceId,
storeOfRelations = storeOfRelations,
keys = mockObjectSet.dvKeys,
sources = listOf(ObjectTypeIds.PAGE),
dvFilters = mockObjectSet.filters
)
stubStoreOfObjectTypes(ObjectTypeIds.PAGE, pageTypeMap)
stubTemplatesForTemplatesContainer(
type = ObjectTypeIds.PAGE,
templates = listOf(StubObject(objectType = ObjectTypeIds.PAGE))
)
// TESTING
proceedWithStartingViewModel()
// ASSERT STATES
val viewerFlow = viewModel.currentViewer.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// ASSERT STATES
assertIs<ObjectState.Init>(stateFlow.awaitItem())
assertIs<ObjectState.DataView.Set>(stateFlow.awaitItem())
assertIs<DataViewViewState.Init>(viewerFlow.awaitItem())
val item = viewerFlow.awaitItem()
assertIs<DataViewViewState.Set.NoItems>(item)
assertTrue(item.isCreateObjectAllowed)
}
}
private fun proceedWithStartingViewModel() {

View file

@ -14,6 +14,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
@ -22,6 +23,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@OptIn(ExperimentalCoroutinesApi::class)
@Config(sdk = [Build.VERSION_CODES.P])
@RunWith(RobolectricTestRunner::class)
class BlockReadModeTest : EditorViewModelTest() {

View file

@ -48,6 +48,9 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
@Test

View file

@ -132,15 +132,22 @@ import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@ -350,7 +357,6 @@ open class EditorViewModelTest {
private lateinit var updateDetail: UpdateDetail
@Mock
lateinit var fileLimitsEventChannel: FileLimitsEventChannel
lateinit var interceptFileLimitEvents: InterceptFileLimitEvents
@Mock
@ -401,11 +407,29 @@ open class EditorViewModelTest {
MockitoAnnotations.openMocks(this)
builder = UrlBuilder(gateway)
stubNetworkMode()
stubObserveEvents()
stubInterceptEvents()
spaceManager.stub {
onBlocking {
get()
} doReturn defaultSpace
}
stubFileLimitEvents()
stubUpdateBlocksMark()
stubOpenPage(root, emptyList())
stubUpdateText()
openPage.stub {
onBlocking {
async(any())
} doReturn Resultat.success(
Result.Success(
Payload(
context = root,
events = emptyList()
)
)
)
}
}
@Test
@ -498,21 +522,21 @@ open class EditorViewModelTest {
@Test
fun `should close page when the system back button is pressed`() {
runTest {
val root = MockDataFactory.randomUuid()
val root = MockDataFactory.randomUuid()
stubOpenPage(root)
stubInterceptEvents()
stubClosePage(null, null)
stubOpenPage(root)
stubInterceptEvents()
givenViewModel()
givenViewModel()
vm.onStart(id = root, space = defaultSpace)
vm.onStart(id = root, space = defaultSpace)
verifyNoInteractions(closePage)
verifyNoInteractions(closePage)
vm.onSystemBackPressed(editorHasChildrenScreens = false)
vm.onSystemBackPressed(editorHasChildrenScreens = false)
runBlockingTest {
verify(closePage, times(1)).async(any())
}
}
@ -534,29 +558,6 @@ open class EditorViewModelTest {
.assertValue { value -> value.peekContent() == AppNavigation.Command.Exit }
}
@Test
fun `should not emit any navigation command if there is an error while closing the page`() {
val root = MockDataFactory.randomUuid()
val error = Exception("Error while closing this page")
stubOpenPage(root)
stubClosePage(error)
stubInterceptEvents()
givenViewModel()
vm.onStart(id = root, space = defaultSpace)
val testObserver = vm.navigation.test()
verifyNoInteractions(closePage)
vm.onSystemBackPressed(editorHasChildrenScreens = false)
testObserver.assertNoValue()
}
@Test
fun `should update block when its text changes`() {
@ -2815,7 +2816,6 @@ open class EditorViewModelTest {
}
stubObserveEvents(flow)
stubOpenPage(context = root)
stubClosePage()
givenViewModel()
@ -3650,11 +3650,14 @@ open class EditorViewModelTest {
}
private fun stubClosePage(
exception: Exception? = null
exception: Exception? = null,
context: Id? = root,
) {
closePage.stub {
onBlocking { async(root) } doReturn Resultat.success(Unit)
onBlocking { if (context == null) async(any()) else async(root) } doReturn Resultat.success(
Unit
)
}
exception?.let {
@ -3678,6 +3681,12 @@ open class EditorViewModelTest {
}
}
fun stubFileLimitEvents() {
interceptFileLimitEvents.stub {
onBlocking { run(Unit) } doReturn emptyFlow()
}
}
fun stubOpenPage(
context: Id = MockDataFactory.randomString(),
events: List<Event> = emptyList()
@ -3702,6 +3711,22 @@ open class EditorViewModelTest {
}
}
private fun stubUpdateBlocksMark() {
updateBlocksMark.stub {
onBlocking {
invoke(any())
} doReturn Either.Right(Payload("", emptyList()))
}
}
private fun stubUpdateText() {
updateText.stub {
onBlocking {
invoke(any())
} doReturn Either.Right(Unit)
}
}
fun stubObserveEvents(
flow: Flow<List<Event>> = flowOf(),
stubInterceptThreadStatus: Boolean = true
@ -3729,12 +3754,6 @@ open class EditorViewModelTest {
if (stubInterceptThreadStatus) stubInterceptThreadStatus()
}
private fun stubUpdateText() {
updateText.stub {
onBlocking { invoke(any()) } doReturn Either.Right(Unit)
}
}
private fun stubReplaceBlock(root: String) {
replaceBlock.stub {
onBlocking { invoke(any()) } doReturn Either.Right(
@ -3776,7 +3795,12 @@ open class EditorViewModelTest {
private fun givenSharedFile() {
documentFileShareDownloader.stub {
onBlocking { async(any()) } doReturn Resultat.success(MiddlewareShareDownloader.Response(Uri.EMPTY, ""))
onBlocking { async(any()) } doReturn Resultat.success(
MiddlewareShareDownloader.Response(
Uri.EMPTY,
""
)
)
}
}
@ -3832,7 +3856,7 @@ open class EditorViewModelTest {
downloadUnsplashImage = DownloadUnsplashImage(unsplashRepo)
clearBlockContent = ClearBlockContent(repo)
clearBlockStyle = ClearBlockStyle(repo)
interceptFileLimitEvents = InterceptFileLimitEvents(fileLimitsEventChannel, dispatchers)
interceptFileLimitEvents = interceptFileLimitEvents
setObjectInternalFlags = SetObjectInternalFlags(repo, dispatchers)
getObjectTypes = GetObjectTypes(repo, dispatchers)

View file

@ -6,6 +6,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -18,6 +19,7 @@ class EditorBackButtonTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -25,6 +27,10 @@ class EditorBackButtonTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubClosePage()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
@Test

View file

@ -32,6 +32,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -46,6 +47,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -57,6 +59,10 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
stubClosePage()
}
@Test
@ -697,6 +703,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() {
stubOpenDocument(document = document)
stubUpdateTextStyle()
stubGetObjectTypes(emptyList())
val vm = buildViewModel()
@ -832,6 +839,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() {
stubOpenDocument(document = document)
stubUpdateTextStyle()
stubGetObjectTypes(emptyList())
val vm = buildViewModel()
@ -1133,6 +1141,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() {
stubOpenDocument(document = document)
stubUpdateText()
stubUpdateTextStyle()
stubGetObjectTypes(emptyList())
val vm = buildViewModel()

View file

@ -30,6 +30,9 @@ class EditorBlockActionsTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubFileLimitEvents()
stubGetNetworkMode()
stubInterceptEvents()
}
@Test

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.domain.block.interactor.UpdateCheckbox
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -25,12 +26,17 @@ class EditorCheckboxTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
@Test

View file

@ -11,6 +11,7 @@ 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.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -25,6 +26,7 @@ class EditorCreateBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -33,6 +35,7 @@ class EditorCreateBlockTest : EditorPresentationTestSetup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
val title = StubTitle()

View file

@ -15,6 +15,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -27,6 +28,7 @@ class EditorDuplicateTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -45,6 +47,9 @@ class EditorDuplicateTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubDuplicateBlock("", emptyList())
}
@Test

View file

@ -16,6 +16,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -50,6 +51,7 @@ class EditorEmptySpaceInteractionTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -58,6 +60,7 @@ class EditorEmptySpaceInteractionTest : EditorPresentationTestSetup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -6,6 +6,7 @@ import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Before
@ -21,6 +22,7 @@ class EditorErrorMessageTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -28,6 +30,9 @@ class EditorErrorMessageTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
@Test

View file

@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -18,12 +19,17 @@ class EditorEventSubscriptionTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubFileLimitEvents()
stubGetNetworkMode()
stubInterceptEvents()
}
@Test

View file

@ -41,6 +41,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -48,6 +49,8 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubFileLimitEvents()
stubGetNetworkMode()
}
@After

View file

@ -19,6 +19,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -31,6 +32,7 @@ class EditorFocusTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -58,6 +60,9 @@ class EditorFocusTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
@Test

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.presentation.editor.render.parseThemeBackgroundColo
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import org.junit.Before
@ -21,6 +22,7 @@ class EditorGranularChangeTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -28,6 +30,8 @@ class EditorGranularChangeTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -35,6 +35,8 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test
@ -44,6 +46,7 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() {
val page = StubSmartBlock(id = root, children = listOf(header.id))
val document = listOf(page, header, title)
stubInterceptEvents()
stubGetObjectTypes(emptyList())
val detailsList = Block.Details(
details = mapOf(

View file

@ -10,6 +10,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -20,6 +21,7 @@ class EditorLatexBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -27,6 +29,9 @@ class EditorLatexBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubInterceptEvents()
}
val title = Block(

View file

@ -14,6 +14,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -28,6 +29,7 @@ class EditorListBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -46,6 +48,8 @@ class EditorListBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -20,6 +20,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -31,6 +32,7 @@ class EditorLockPageTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -50,6 +52,7 @@ class EditorLockPageTest : EditorPresentationTestSetup() {
MockitoAnnotations.openMocks(this)
stubGetNetworkMode()
stubSpaceManager()
stubFileLimitEvents()
}
@Test

View file

@ -29,6 +29,7 @@ class EditorMarkupObjectTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -44,6 +45,8 @@ class EditorMarkupObjectTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@After

View file

@ -48,6 +48,7 @@ class EditorMentionTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -86,6 +87,8 @@ class EditorMentionTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -11,6 +11,7 @@ import com.anytypeio.anytype.presentation.MockTypicalDocumentFactory.profile
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -22,12 +23,15 @@ class EditorMenuTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -12,6 +12,7 @@ import com.anytypeio.anytype.presentation.editor.EditorViewModel
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -26,6 +27,7 @@ class EditorMergeTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -33,6 +35,8 @@ class EditorMergeTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test
@ -306,6 +310,7 @@ class EditorMergeTest : EditorPresentationTestSetup() {
}
}
@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun `should not merge text block with the previous block if this previous block is not a text block`() {
@ -342,6 +347,7 @@ class EditorMergeTest : EditorPresentationTestSetup() {
stubInterceptEvents()
stubUpdateText()
stubMergeBlocks(root)
stubUnlinkBlocks()
val vm = buildViewModel()

View file

@ -32,6 +32,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -49,6 +50,7 @@ class EditorMultiSelectModeTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -67,6 +69,10 @@ class EditorMultiSelectModeTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubUpdateText()
stubCopy()
}
@Test

View file

@ -18,6 +18,7 @@ import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
@ -39,6 +40,7 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -46,8 +48,11 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -12,6 +12,7 @@ import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
import org.junit.Before
@ -32,6 +33,7 @@ class EditorObjectTypeChangeWidgetTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -39,8 +41,11 @@ class EditorObjectTypeChangeWidgetTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.RelationLink
import com.anytypeio.anytype.core_models.Response
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.primitives.TypeId
import com.anytypeio.anytype.core_models.primitives.TypeKey
@ -118,8 +119,10 @@ import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf
import org.mockito.Mock
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.notNull
import org.mockito.kotlin.stub
open class EditorPresentationTestSetup {
@ -498,13 +501,15 @@ open class EditorPresentationTestSetup {
spaceId: SpaceId = SpaceId(defaultSpace)
) {
openPage.stub {
onBlocking { async(
OpenPage.Params(
obj = root,
saveAsLastOpened = true,
space = spaceId
onBlocking {
async(
OpenPage.Params(
obj = root,
saveAsLastOpened = true,
space = spaceId
)
)
) } doReturn Resultat.success(
} doReturn Resultat.success(
Result.Success(
Payload(
context = root,
@ -582,11 +587,13 @@ open class EditorPresentationTestSetup {
}
fun stubUnlinkBlocks(
params: UnlinkBlocks.Params = any(),
params: UnlinkBlocks.Params? = null,
events: List<Event> = emptyList()
) {
unlinkBlocks.stub {
onBlocking { invoke(params) } doReturn Either.Right(
onBlocking {
if (params == null) invoke(any()) else invoke(params)
} doReturn Either.Right(
Payload(
context = root,
events = events
@ -643,6 +650,26 @@ open class EditorPresentationTestSetup {
}
}
fun stubCopy() {
copy.stub {
onBlocking { invoke(any()) } doReturn Either.Right(Unit)
}
}
fun stubPaste() {
paste.stub {
onBlocking { invoke(any()) } doReturn Either.Right(
Response.Clipboard.Paste(
0,
true,
emptyList(),
Payload("", emptyList())
)
)
}
}
fun stubReplaceBlock() {
replaceBlock.stub {
onBlocking { invoke(any()) } doReturn Either.Right(

View file

@ -13,6 +13,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -23,6 +24,7 @@ class EditorQuickStartingScrollAndMoveTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -30,6 +32,8 @@ class EditorQuickStartingScrollAndMoveTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
val title = Block(

View file

@ -16,6 +16,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -27,6 +28,7 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -45,6 +47,8 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -17,6 +17,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Before
@ -33,6 +34,7 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -60,6 +62,8 @@ class EditorScrollAndMoveTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -18,6 +18,7 @@ import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -32,23 +33,23 @@ class EditorSlashWidgetActionsTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
// @get:Rule
// val timberTestRule: TimberTestRule = TimberTestRule.builder()
// .minPriority(Log.DEBUG)
// .showThread(true)
// .showTimestamp(false)
// .onlyLogWhenTestFails(true)
// .build()
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubUpdateText()
stubDuplicateBlock("", emptyList())
stubCopy()
stubPaste()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(TEXT_CHANGES_DEBOUNCE_DURATION)
@ -65,6 +66,8 @@ class EditorSlashWidgetActionsTest : EditorPresentationTestSetup() {
stubUpdateText()
stubSearchObjects()
stubOpenDocument(document = doc)
stubUnlinkBlocks()
val vm = buildViewModel()
vm.onStart(id = root, space = defaultSpace)
@ -102,6 +105,7 @@ class EditorSlashWidgetActionsTest : EditorPresentationTestSetup() {
stubUpdateText()
stubSearchObjects()
stubOpenDocument(document = doc)
stubUnlinkBlocks()
val vm = buildViewModel()
vm.onStart(id = root, space = defaultSpace)
@ -259,6 +263,7 @@ class EditorSlashWidgetActionsTest : EditorPresentationTestSetup() {
stubInterceptEvents()
stubOpenDocument(document = doc)
val vm = buildViewModel()
vm.onStart(id = root, space = defaultSpace)
@ -295,6 +300,8 @@ class EditorSlashWidgetActionsTest : EditorPresentationTestSetup() {
stubUpdateText()
stubSearchObjects()
stubOpenDocument(document = doc)
stubCopy()
val vm = buildViewModel()
vm.onStart(id = root, space = defaultSpace)

View file

@ -37,6 +37,8 @@ class EditorSlashWidgetClicksTest: EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
/**

View file

@ -18,6 +18,7 @@ import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -36,6 +37,7 @@ class EditorSlashWidgetColorTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -43,8 +45,12 @@ class EditorSlashWidgetColorTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubUpdateText()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -11,6 +11,7 @@ import com.anytypeio.anytype.presentation.editor.editor.slash.SlashEvent
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.ExperimentalCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -29,6 +30,7 @@ class EditorSlashWidgetCutFilterTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -36,8 +38,12 @@ class EditorSlashWidgetCutFilterTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubGetObjectTypes(emptyList())
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -27,6 +27,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -42,6 +43,7 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -49,6 +51,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
/**
@ -2071,6 +2075,7 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() {
stubInterceptEvents()
stubSearchObjects()
stubOpenDocument(doc, customDetails)
stubGetObjectTypes(listOf())
val vm = buildViewModel()
vm.onStart(id = root, space = defaultSpace)

View file

@ -16,6 +16,7 @@ import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
import org.junit.Before
@ -30,6 +31,7 @@ class EditorSlashWidgetMarksTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -45,6 +47,8 @@ class EditorSlashWidgetMarksTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@After

View file

@ -18,6 +18,7 @@ import com.anytypeio.anytype.presentation.editor.editor.slash.SlashItem
import com.anytypeio.anytype.presentation.objects.ObjectTypeView
import com.anytypeio.anytype.presentation.objects.getProperName
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -31,6 +32,7 @@ class EditorSlashWidgetObjectTypeTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -40,8 +42,12 @@ class EditorSlashWidgetObjectTypeTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager(space = space)
stubGetNetworkMode()
stubFileLimitEvents()
stubClosePage()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -22,6 +22,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
@ -37,6 +38,7 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -52,6 +54,8 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@After
@ -391,6 +395,7 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() {
stubUpdateText()
stubCreateBlock(root = root)
stubSearchObjects()
stubCopy()
stubOpenDocument(
document = doc,
details = customDetails

View file

@ -5,20 +5,22 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.presentation.MockTypicalDocumentFactory
import com.anytypeio.anytype.presentation.editor.editor.slash.SlashEvent
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
class EditorSlashWidgetShowHideTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -33,6 +35,9 @@ class EditorSlashWidgetShowHideTest : EditorPresentationTestSetup() {
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -14,6 +14,7 @@ import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
import org.junit.Before
@ -28,6 +29,7 @@ class EditorSlashWidgetStyleTypeTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -42,8 +44,12 @@ class EditorSlashWidgetStyleTypeTest : EditorPresentationTestSetup() {
@Before
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -15,6 +15,7 @@ import com.anytypeio.anytype.presentation.editor.EditorViewModel
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
import org.junit.Before
@ -31,6 +32,7 @@ class EditorSplitTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -46,6 +48,8 @@ class EditorSplitTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@After

View file

@ -4,6 +4,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -14,6 +15,7 @@ class EditorStartupTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -21,6 +23,8 @@ class EditorStartupTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@Test

View file

@ -13,6 +13,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import net.lachlanmckee.timberjunit.TimberTestRule
import org.junit.After
import org.junit.Before
@ -25,6 +26,7 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -40,8 +42,11 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@OptIn(ExperimentalCoroutinesApi::class)
@After
fun after() {
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Before
import org.junit.Rule
@ -24,6 +25,7 @@ class EditorTextUpdateTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -31,6 +33,8 @@ class EditorTextUpdateTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
val title = Block(

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.domain.block.interactor.CreateBlock
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -23,6 +24,7 @@ class EditorTitleAddBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -30,6 +32,9 @@ class EditorTitleAddBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
stubCreateBlock(root)
}
val title = Block(

View file

@ -16,6 +16,7 @@ import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
@ -36,6 +37,7 @@ class EditorTitleTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -51,6 +53,12 @@ class EditorTitleTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubInterceptEvents()
stubFileLimitEvents()
stubCopy()
stubSplitBlock()
stubCreateBlock(root)
}
@After

View file

@ -21,6 +21,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
@ -34,6 +35,7 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -41,6 +43,8 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
private var tableId = MockDataFactory.randomUuid()

View file

@ -31,6 +31,7 @@ import com.anytypeio.anytype.presentation.util.TXT
import com.anytypeio.anytype.test_utils.MockDataFactory
import com.jraska.livedata.test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
@ -47,6 +48,7 @@ class EditorTableMoveRowsColumnsTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -54,6 +56,8 @@ class EditorTableMoveRowsColumnsTest : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
private var tableId = MockDataFactory.randomUuid()

View file

@ -17,16 +17,18 @@ import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
class EditorTableRowsColumnsDelete : EditorPresentationTestSetup() {
class EditorTableRowsColumnsDeleteTest : EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -34,6 +36,8 @@ class EditorTableRowsColumnsDelete : EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
private var tableId = MockDataFactory.randomUuid()

View file

@ -26,6 +26,7 @@ class EditorTemplateTest: EditorPresentationTestSetup() {
@get:Rule
val rule = InstantTaskExecutorRule()
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutineTestRule = CoroutinesTestRule()
@ -33,6 +34,8 @@ class EditorTemplateTest: EditorPresentationTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
stubSpaceManager()
stubGetNetworkMode()
stubFileLimitEvents()
}
@OptIn(ExperimentalCoroutinesApi::class)

View file

@ -82,6 +82,7 @@ import com.anytypeio.anytype.presentation.widgets.WidgetView
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
@ -92,6 +93,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.BDDMockito.given
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
@ -200,7 +202,6 @@ class HomeScreenViewModelTest {
@Mock
lateinit var getPinnedObjectTypes: GetPinnedObjectTypes
@Mock
lateinit var userPermissionProvider: UserPermissionProvider
private val objectPayloadDispatcher = Dispatcher.Default<Payload>()
@ -210,6 +211,7 @@ class HomeScreenViewModelTest {
lateinit var vm: HomeScreenViewModel
@OptIn(ExperimentalCoroutinesApi::class)
private val appCoroutineDispatchers = AppCoroutineDispatchers(
io = coroutineTestRule.dispatcher,
main = coroutineTestRule.dispatcher,
@ -233,6 +235,8 @@ class HomeScreenViewModelTest {
MockitoAnnotations.openMocks(this)
urlBuilder = UrlBuilder(gateway)
stubSpaceManager()
userPermissionProvider = UserPermissionProviderStub()
stubGetPinnedObjectTypes()
}
@Test
@ -1193,16 +1197,7 @@ class HomeScreenViewModelTest {
)
)
deleteWidget.stub {
onBlocking {
stream(
DeleteWidget.Params(
ctx = WIDGET_OBJECT_ID,
targets = listOf(widgetBlock.id)
)
)
} doReturn flowOf(Resultat.Success(givenPayload))
}
stubDeleteWidget(widgetBlock, givenPayload)
val vm = buildViewModel()
@ -1295,6 +1290,7 @@ class HomeScreenViewModelTest {
stubGetWidgetSession()
stubSpaceManager()
stubSpaceWidgetContainer(defaultSpaceWidgetView)
stubDeleteWidget(widgetBlock, givenPayload)
val vm = buildViewModel()
@ -1503,6 +1499,12 @@ class HomeScreenViewModelTest {
stubWidgetActiveView(favoriteWidgetBlock)
stubSpaceManager()
stubSpaceWidgetContainer(defaultSpaceWidgetView)
given(objectWatcher.watch(any())).willReturn(flowOf())
given(storelessSubscriptionContainer.subscribe(any<StoreSearchParams>())).willReturn(flowOf())
given(storelessSubscriptionContainer.subscribe(any<StoreSearchByIdsParams>())).willReturn(
flowOf()
)
stubCloseObject()
val vm = buildViewModel()
@ -2490,7 +2492,8 @@ class HomeScreenViewModelTest {
filters = buildList {
addAll(
ObjectSearchConstants.defaultDataViewFilters(
spaces = listOf(defaultSpaceConfig.space, defaultSpaceConfig.techSpace))
spaces = listOf(defaultSpaceConfig.space, defaultSpaceConfig.techSpace)
)
)
add(
DVFilter(
@ -2827,12 +2830,38 @@ class HomeScreenViewModelTest {
}
}
private fun stubGetPinnedObjectTypes() {
getPinnedObjectTypes.stub {
onBlocking {
flow(any())
} doReturn flowOf()
}
}
private fun stubDeleteWidget(
widgetBlock: Block,
givenPayload: Payload
) {
deleteWidget.stub {
onBlocking {
stream(
DeleteWidget.Params(
ctx = WIDGET_OBJECT_ID,
targets = listOf(widgetBlock.id)
)
)
} doReturn flowOf(Resultat.Success(givenPayload))
}
}
private fun stubUserPermission(
permission: SpaceMemberPermissions = SpaceMemberPermissions.OWNER
) {
userPermissionProvider.stub {
on { observe(space = SpaceId(defaultSpaceConfig.space)) } doReturn flowOf(permission)
}
(userPermissionProvider as UserPermissionProviderStub).stubObserve(
SpaceId(
defaultSpaceConfig.space
), permission
)
}
private fun buildViewModel() = HomeScreenViewModel(

View file

@ -0,0 +1,24 @@
package com.anytypeio.anytype.presentation.home
import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
class UserPermissionProviderStub : UserPermissionProvider {
private var permission: SpaceMemberPermissions? = null
private var spaceId: SpaceId? = null
override fun start() {}
override fun stop() {}
override fun get(space: SpaceId): SpaceMemberPermissions? = null
override fun observe(space: SpaceId): Flow<SpaceMemberPermissions?> = flowOf(permission)
fun stubObserve(spaceId: SpaceId, permission: SpaceMemberPermissions) {
this.spaceId = spaceId
this.permission = permission
}
}

View file

@ -135,6 +135,7 @@ open class LinkToObjectOrWebViewModelTest {
@Test
fun `should return selected range error state when selection range start is equal end`() = runTest {
spaceManager.set(spaceId)
val target = MockDataFactory.randomString()
@ -146,6 +147,7 @@ open class LinkToObjectOrWebViewModelTest {
runBlocking { store.document.update(listOf(block)) }
val vm = givenViewModel()
stubSearchObjects(params = vm.getSearchObjectsParams(ctx))
vm.onStart(
blockId = target,

View file

@ -62,6 +62,7 @@ class ViewerDefaultObjectTypeTest : ObjectSetViewModelTestSetup() {
fun setup() {
closable = MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
stubNetworkMode()
}
@After

View file

@ -38,6 +38,7 @@ class ObjectSetCellTest : ObjectSetViewModelTestSetup() {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubNetworkMode()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.presentation.sets.main
import app.cash.turbine.testIn
import app.cash.turbine.turbineScope
import com.anytypeio.anytype.core_models.Event
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.presentation.collections.MockSet
@ -42,9 +43,12 @@ class ObjectSetConvertToCollectionTest : ObjectSetViewModelTestSetup() {
@Test
fun `should start collection subscription after changing from set to collection`() = runTest {
turbineScope {
// SETUP
stubSpaceManager(defaultSpace)
stubInterceptEvents()
stubNetworkMode()
stubObjectToCollection()
stubInterceptThreadStatus()
stubOpenObject(
doc = listOf(mockObjectSet.header, mockObjectSet.title, mockObjectSet.dataView),
@ -60,57 +64,58 @@ class ObjectSetConvertToCollectionTest : ObjectSetViewModelTestSetup() {
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2)
)
val stateFlow = stateReducer.state.testIn(backgroundScope)
val stateFlow = stateReducer.state.testIn(backgroundScope)
// TESTING
// TESTING
proceedWithStartingViewModel()
val firstState = stateFlow.awaitItem()
assertIs<ObjectState.Init>(firstState)
val firstState = stateFlow.awaitItem()
assertIs<ObjectState.Init>(firstState)
val secondState = stateFlow.awaitItem()
assertIs<ObjectState.DataView.Set>(secondState)
val secondState = stateFlow.awaitItem()
assertIs<ObjectState.DataView.Set>(secondState)
viewModel.proceedWithConvertingToCollection()
viewModel.proceedWithConvertingToCollection()
val eventSetIsCollection = Event.Command.DataView.SetIsCollection(
context = root,
dv = mockObjectSet.dataView.id,
isCollection = true
)
dispatcher.send(
Payload(
val eventSetIsCollection = Event.Command.DataView.SetIsCollection(
context = root,
events = listOf(eventSetIsCollection)
dv = mockObjectSet.dataView.id,
isCollection = true
)
)
val thirdState = stateFlow.awaitItem()
assertIs<ObjectState.DataView.Collection>(thirdState)
advanceUntilIdle()
verifyBlocking(repo, times(1)) {
searchObjectsWithSubscription(
eq(mockObjectSet.subscriptionId),
eq(listOf()),
eq(
mockObjectSet.filters + ObjectSearchConstants.defaultDataViewFilters(
listOf(spaceConfig.space, spaceConfig.techSpace)
)
),
eq(ObjectSearchConstants.defaultDataViewKeys + mockObjectSet.dvKeys),
eq(listOf()),
eq(0L),
eq(ObjectSetConfig.DEFAULT_LIMIT),
eq(null),
eq(null),
eq(null),
eq(null),
eq(mockObjectSet.root)
dispatcher.send(
Payload(
context = root,
events = listOf(eventSetIsCollection)
)
)
val thirdState = stateFlow.awaitItem()
assertIs<ObjectState.DataView.Collection>(thirdState)
advanceUntilIdle()
verifyBlocking(repo, times(1)) {
searchObjectsWithSubscription(
eq(mockObjectSet.subscriptionId),
eq(listOf()),
eq(
mockObjectSet.filters + ObjectSearchConstants.defaultDataViewFilters(
listOf(spaceConfig.space, spaceConfig.techSpace)
)
),
eq(ObjectSearchConstants.defaultDataViewKeys + mockObjectSet.dvKeys),
eq(listOf()),
eq(0L),
eq(ObjectSetConfig.DEFAULT_LIMIT),
eq(null),
eq(null),
eq(null),
eq(null),
eq(mockObjectSet.root)
)
}
}
}

View file

@ -8,6 +8,7 @@ import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.restrictions.DataViewRestriction
import com.anytypeio.anytype.core_models.restrictions.DataViewRestrictions
import com.anytypeio.anytype.domain.base.Resultat
import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject
import com.anytypeio.anytype.presentation.collections.MockCollection
import com.anytypeio.anytype.presentation.collections.MockSet
@ -25,6 +26,7 @@ import org.junit.Before
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
@ -42,7 +44,8 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
fun setup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
mockObjectSet = MockSet(context = root, setOfValue = setOfId, setOfKey = setOfKey, space = defaultSpace)
mockObjectSet =
MockSet(context = root, setOfValue = setOfId, setOfKey = setOfKey, space = defaultSpace)
mockObjectCollection = MockCollection(context = root, space = defaultSpace)
stubNetworkMode()
}
@ -71,14 +74,24 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() {
dvFilters = mockObjectSet.filters,
objects = listOf(mockObjectSet.obj1, mockObjectSet.obj2)
)
doReturn(Unit).`when`(createDataViewObject).async(
CreateDataViewObject.Params.SetByType(
type = TypeKey(setOfKey),
filters = mockObjectSet.filters,
template = null,
prefilled = mapOf(),
createDataViewObject.stub {
onBlocking {
async(
CreateDataViewObject.Params.SetByType(
type = TypeKey(setOfKey),
filters = mockObjectSet.filters,
template = null,
prefilled = mapOf(),
)
)
} doReturn Resultat.success(
CreateDataViewObject.Result(
"",
TypeKey(""),
mapOf("spaceId" to "spaceId")
)
)
)
}
// TESTING
proceedWithStartingViewModel()

View file

@ -23,6 +23,7 @@ class ObjectSetHeaderTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
mockObjectSet = MockSet(context = root, space = defaultSpace)
stubNetworkMode()
}
@After

View file

@ -24,6 +24,7 @@ class ObjectSetInitializationTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
mockObjectSet = MockSet(context = root, space = defaultSpace)
stubNetworkMode()
}
@After

View file

@ -193,7 +193,7 @@ class ObjectSetNavigationTest : ObjectSetViewModelTestSetup() {
dvFilters = mockObjectSet.filters
)
doReturn(Unit).`when`(closeBlock).async(mockObjectSet.root)
stubCloseBlock()
// TESTING
proceedWithStartingViewModel()

View file

@ -26,6 +26,7 @@ class ObjectSetRestrictionsTest : ObjectSetViewModelTestSetup() {
MockitoAnnotations.openMocks(this)
viewModel = givenViewModel()
mockObjectSet = MockSet(context = root, space = defaultSpace)
givenNetworkNodeMocked()
}
@After

View file

@ -83,13 +83,18 @@ import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import net.bytebuddy.utility.RandomString
import org.junit.Before
import org.junit.Rule
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.junit.MockitoJUnit
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.given
import org.mockito.kotlin.mock
import org.mockito.kotlin.stub
@OptIn(ExperimentalCoroutinesApi::class)
open class ObjectSetViewModelTestSetup {
val root: Id = "context-${RandomString.make()}"
@ -328,6 +333,22 @@ open class ObjectSetViewModelTestSetup {
}
}
fun stubAddObjectToCollection() {
addObjectToCollection.stub {
onBlocking {
async(any())
} doReturn Resultat.success(Payload("", emptyList()))
}
}
fun stubCloseBlock() {
closeBlock.stub {
onBlocking {
async(any())
} doReturn Resultat.success(Unit)
}
}
suspend fun stubSpaceManager(space: Id) {
repo.stub {
onBlocking { getSpaceConfig(space) } doReturn spaceConfig
@ -445,7 +466,7 @@ open class ObjectSetViewModelTestSetup {
CreateDataViewObject.Result(
objectId = objectId,
objectType = TypeKey(objectType),
struct = null
struct = mapOf<Id, Any?>("spaceId" to "spaceId")
)
)
)
@ -457,4 +478,18 @@ open class ObjectSetViewModelTestSetup {
onBlocking { run(Unit) } doReturn NetworkModeConfig()
}
}
fun stubObjectToCollection() {
objectToCollection.stub {
onBlocking { async(any()) } doReturn Resultat.success(Unit)
}
}
fun givenNetworkNodeMocked() {
getNetworkMode.stub {
onBlocking {
run(any())
} doReturn NetworkModeConfig()
}
}
}

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.presentation.sets.main
import app.cash.turbine.test
import app.cash.turbine.turbineScope
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject
import com.anytypeio.anytype.presentation.collections.MockSet
@ -47,6 +48,7 @@ class SetByRelationTest : ObjectSetViewModelTestSetup() {
// SETUP
stubSpaceManager(mockObjectSet.spaceId)
stubInterceptEvents()
stubCreateDataViewObject()
stubInterceptThreadStatus()
stubStoreOfRelations(mockObjectSet)
stubOpenObject(

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.presentation.templates
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.NetworkModeConfig
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.Relations
@ -29,6 +30,9 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
@ -75,7 +79,9 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() {
@Before
fun setup() {
closable = MockitoAnnotations.openMocks(this)
givenNetworkNodeMocked()
viewModel = givenViewModel()
stubAddObjectToCollection()
}
@After

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.presentation.templates
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.NetworkModeConfig
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.Relations
@ -24,8 +25,13 @@ import kotlinx.coroutines.test.runTest
import net.bytebuddy.utility.RandomString
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.mockito.junit.MockitoJUnit
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import org.mockito.kotlin.times
import org.mockito.kotlin.verifyBlocking
@ -59,6 +65,11 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() {
@Before
fun setup() {
closable = MockitoAnnotations.openMocks(this)
getNetworkMode.stub {
onBlocking {
run(any())
} doReturn NetworkModeConfig()
}
viewModel = givenViewModel()
}

View file

@ -4,7 +4,7 @@ import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
@OptIn(ExperimentalCoroutinesApi::class)
val dispatchers = AppCoroutineDispatchers(
io = StandardTestDispatcher(),
main = StandardTestDispatcher(),

View file

@ -14,12 +14,5 @@ wire {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.protocol'
}

View file

@ -29,15 +29,6 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
buildFeatures {
viewBinding true
compose true

View file

@ -8,6 +8,10 @@ pluginManagement {
}
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
dependencyResolutionManagement {
/**
* Create github.properties in root project folder file

View file

@ -15,12 +15,5 @@ dependencies {
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.test_utils'
}

View file

@ -15,13 +15,6 @@ android {
kotlinCompilerExtensionVersion libs.versions.composeKotlinCompilerVersion.get()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(17)
}
namespace 'com.anytypeio.anytype.ui_settings'
}