Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Apr 22, 2021
1 parent 032e89f commit 46a7c87
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.io.File

class SplashScreenViewModel(
private val generalSettings: Settings,
private val metaSettings: Settings,
private val projectsRepository: ProjectsRepository,
private val projectImporter: ProjectImporter,
private val appStateProvider: AppStateProvider
Expand Down Expand Up @@ -43,13 +42,12 @@ class SplashScreenViewModel(

open class Factory constructor(
private val generalSettings: Settings,
private val metaSettings: Settings,
private val projectsRepository: ProjectsRepository,
private val projectImporter: ProjectImporter,
private val appStateProvider: AppStateProvider
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return SplashScreenViewModel(generalSettings, metaSettings, projectsRepository, projectImporter, appStateProvider) as T
return SplashScreenViewModel(generalSettings, projectsRepository, projectImporter, appStateProvider) as T
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public InstancesRepositoryProvider providesInstancesRepositoryProvider() {

@Provides
public SplashScreenViewModel.Factory providesSplashScreenViewModel(SettingsProvider settingsProvider, ProjectsRepository projectsRepository, ProjectImporter projectImporter, AppStateProvider appStateProvider) {
return new SplashScreenViewModel.Factory(settingsProvider.getGeneralSettings(), settingsProvider.getMetaSettings(), projectsRepository, projectImporter, appStateProvider);
return new SplashScreenViewModel.Factory(settingsProvider.getGeneralSettings(), projectsRepository, projectImporter, appStateProvider);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.preference.PreferenceManager
import org.odk.collect.android.preferences.keys.AdminKeys
import org.odk.collect.android.preferences.keys.GeneralKeys
import org.odk.collect.android.preferences.keys.MetaKeys.CURRENT_PROJECT_ID
import org.odk.collect.shared.Settings
import org.odk.collect.android.projects.ProjectImporter.Companion.DEMO_PROJECT_ID
import org.odk.collect.projects.NOT_SPECIFIED_UUID
import org.odk.collect.shared.Settings

class SettingsProvider(private val context: Context) {
fun getMetaSettings() = settings.getOrPut(META_SETTINGS_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ProjectImporter(
fun importDemoProject() {
val project = Project("Demo project", "D", "#3e9fcc", DEMO_PROJECT_ID)
projectsRepository.add(project)
metaSettings.save(MetaKeys.CURRENT_PROJECT_ID, "")
metaSettings.save(MetaKeys.CURRENT_PROJECT_ID, DEMO_PROJECT_ID)
}

// Now it does the same like importDemoProject() but it should be changed later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.assertThat
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.CoreMatchers.nullValue
import org.hamcrest.Matchers.notNullValue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.odk.collect.android.rules.MainCoroutineScopeRule
import org.mockito.Mockito.spy
import org.odk.collect.android.R
import org.odk.collect.android.activities.viewmodels.SplashScreenViewModel
import org.odk.collect.android.fragments.dialogs.FirstLaunchDialog
import org.odk.collect.android.injection.config.AppDependencyModule
import org.odk.collect.android.preferences.source.SettingsProvider
import org.odk.collect.android.projects.ProjectImporter
import org.odk.collect.android.rules.MainCoroutineScopeRule
import org.odk.collect.android.support.RobolectricHelpers
import org.odk.collect.projects.ProjectsRepository
import org.odk.collect.android.utilities.AppStateProvider
import org.odk.collect.projects.ProjectsRepository

@RunWith(AndroidJUnit4::class)
class SplashScreenActivityTest {
Expand All @@ -45,7 +43,7 @@ class SplashScreenActivityTest {

RobolectricHelpers.overrideAppDependencyModule(object : AppDependencyModule() {
override fun providesSplashScreenViewModel(settingsProvider: SettingsProvider, projectsRepository: ProjectsRepository, projectImporter: ProjectImporter, appStateProvider: AppStateProvider): SplashScreenViewModel.Factory {
return object : SplashScreenViewModel.Factory(settingsProvider.getGeneralSettings(), settingsProvider.getMetaSettings(), projectsRepository, projectImporter, appStateProvider) {
return object : SplashScreenViewModel.Factory(settingsProvider.getGeneralSettings(), projectsRepository, projectImporter, appStateProvider) {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return splashScreenViewModel as T
}
Expand Down Expand Up @@ -110,7 +108,6 @@ class SplashScreenActivityTest {
}
}

@ExperimentalCoroutinesApi
@Test
fun `The main menu should be displayed automatically after 2s if the Splash screen is enabled and the app is not newly installed`() = coroutineScope.runBlockingTest {
doReturn(false).`when`(splashScreenViewModel).isFirstLaunch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import org.mockito.Mockito.verifyNoInteractions
import org.odk.collect.android.preferences.keys.GeneralKeys
import org.odk.collect.android.preferences.source.SharedPreferencesSettings
import org.odk.collect.android.projects.ProjectImporter
import org.odk.collect.android.projects.ProjectsRepository
import org.odk.collect.android.utilities.AppStateProvider
import org.odk.collect.projects.ProjectsRepository

class SplashScreenViewModelTest {
private lateinit var generalSettings: SharedPreferencesSettings
private lateinit var metaSettings: SharedPreferencesSettings
private lateinit var projectsRepository: ProjectsRepository
private lateinit var projectImporter: ProjectImporter
private lateinit var appStateProvider: AppStateProvider
Expand All @@ -25,11 +24,10 @@ class SplashScreenViewModelTest {
@Before
fun setup() {
generalSettings = mock(SharedPreferencesSettings::class.java)
metaSettings = mock(SharedPreferencesSettings::class.java)
projectsRepository = mock(ProjectsRepository::class.java)
projectImporter = mock(ProjectImporter::class.java)
appStateProvider = mock(AppStateProvider::class.java)
splashScreenViewModel = SplashScreenViewModel(generalSettings, metaSettings, projectsRepository, projectImporter, appStateProvider)
splashScreenViewModel = SplashScreenViewModel(generalSettings, projectsRepository, projectImporter, appStateProvider)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.hamcrest.Matchers.isEmptyString
import org.hamcrest.Matchers.not
import org.junit.Before
import org.junit.Test
import org.odk.collect.android.projects.ProjectImporter.Companion.DEMO_PROJECT_ID

abstract class ProjectsRepositoryTest {
private val projectX = Project("ProjectX", "X", "#FF0000")
Expand Down Expand Up @@ -54,8 +53,8 @@ abstract class ProjectsRepositoryTest {

@Test
fun `add() should not add uuid if specified`() {
projectsRepository.add(projectX.copy(uuid = DEMO_PROJECT_ID))
assertThat(projectsRepository.get(""), `is`(projectX.copy(uuid = DEMO_PROJECT_ID)))
projectsRepository.add(projectX.copy(uuid = ""))
assertThat(projectsRepository.get(""), `is`(projectX.copy(uuid = "")))
}

@Test
Expand Down

0 comments on commit 46a7c87

Please sign in to comment.