@@ -10,6 +10,13 @@ package com.nextcloud.talk.contacts
1010import com.nextcloud.talk.contacts.apiService.FakeItem
1111import com.nextcloud.talk.contacts.repository.FakeRepositoryError
1212import com.nextcloud.talk.contacts.repository.FakeRepositorySuccess
13+ import com.nextcloud.talk.data.user.UsersDao
14+ import com.nextcloud.talk.data.user.UsersRepository
15+ import com.nextcloud.talk.data.user.UsersRepositoryImpl
16+ import com.nextcloud.talk.users.UserManager
17+ import com.nextcloud.talk.utils.database.user.CurrentUserProviderOld
18+ import com.nextcloud.talk.utils.database.user.CurrentUserProviderOldImpl
19+ import com.nextcloud.talk.utils.preview.DummyUserDaoImpl
1320import kotlinx.coroutines.Dispatchers
1421import kotlinx.coroutines.ExperimentalCoroutinesApi
1522import kotlinx.coroutines.test.TestDispatcher
@@ -28,6 +35,18 @@ class ContactsViewModelTest {
2835
2936 val dispatcher: TestDispatcher = UnconfinedTestDispatcher ()
3037
38+ val usersDao: UsersDao
39+ get() = DummyUserDaoImpl ()
40+
41+ val userRepository: UsersRepository
42+ get() = UsersRepositoryImpl (usersDao)
43+
44+ val userManager: UserManager
45+ get() = UserManager (userRepository)
46+
47+ val userProvider: CurrentUserProviderOld
48+ get() = CurrentUserProviderOldImpl (userManager)
49+
3150 @Before
3251 fun setup () {
3352 Dispatchers .setMain(dispatcher)
@@ -40,25 +59,25 @@ class ContactsViewModelTest {
4059
4160 @Before
4261 fun setUp () {
43- viewModel = ContactsViewModel (repository)
62+ viewModel = ContactsViewModel (repository, userProvider )
4463 }
4564
4665 @Test
4766 fun `fetch contacts` () =
4867 runTest {
49- viewModel = ContactsViewModel (repository)
68+ viewModel = ContactsViewModel (repository, userProvider )
5069 viewModel.getContactsFromSearchParams()
51- assert (viewModel.contactsViewState.value is ContactsUiState .Success )
52- val successState = viewModel.contactsViewState.value as ContactsUiState .Success
70+ assert (viewModel.contactsViewState.value is ContactsViewModel . ContactsUiState .Success )
71+ val successState = viewModel.contactsViewState.value as ContactsViewModel . ContactsUiState .Success
5372 assert (successState.contacts == FakeItem .contacts)
5473 }
5574
5675 @Test
5776 fun `test error contacts state` () =
5877 runTest {
59- viewModel = ContactsViewModel (FakeRepositoryError ())
60- assert (viewModel.contactsViewState.value is ContactsUiState .Error )
61- val errorState = viewModel.contactsViewState.value as ContactsUiState .Error
78+ viewModel = ContactsViewModel (FakeRepositoryError (), userProvider )
79+ assert (viewModel.contactsViewState.value is ContactsViewModel . ContactsUiState .Error )
80+ val errorState = viewModel.contactsViewState.value as ContactsViewModel . ContactsUiState .Error
6281 assert (errorState.message == " unable to fetch contacts" )
6382 }
6483
@@ -88,25 +107,25 @@ class ContactsViewModelTest {
88107 @Test
89108 fun `initial room state is none` () =
90109 runTest {
91- assert (viewModel.roomViewState.value is RoomUiState .None )
110+ assert (viewModel.roomViewState.value is ContactsViewModel . RoomUiState .None )
92111 }
93112
94113 @Test
95114 fun `test success room state` () =
96115 runTest {
97116 viewModel.createRoom(" 1" , " users" , " s@gmail.com" , null )
98- assert (viewModel.roomViewState.value is RoomUiState .Success )
99- val successState = viewModel.roomViewState.value as RoomUiState .Success
117+ assert (viewModel.roomViewState.value is ContactsViewModel . RoomUiState .Success )
118+ val successState = viewModel.roomViewState.value as ContactsViewModel . RoomUiState .Success
100119 assert (successState.conversation == FakeItem .roomOverall.ocs!! .data)
101120 }
102121
103122 @Test
104123 fun `test failure room state` () =
105124 runTest {
106- viewModel = ContactsViewModel (FakeRepositoryError ())
125+ viewModel = ContactsViewModel (FakeRepositoryError (), userProvider )
107126 viewModel.createRoom(" 1" , " users" , " s@gmail.com" , null )
108- assert (viewModel.roomViewState.value is RoomUiState .Error )
109- val errorState = viewModel.roomViewState.value as RoomUiState .Error
127+ assert (viewModel.roomViewState.value is ContactsViewModel . RoomUiState .Error )
128+ val errorState = viewModel.roomViewState.value as ContactsViewModel . RoomUiState .Error
110129 assert (errorState.message == " unable to create room" )
111130 }
112131
0 commit comments