Skip to content

Commit 170b5c1

Browse files
committed
fixed test
1 parent 1c532e8 commit 170b5c1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Simplenote/src/test/java/com/automattic/simplenote/viewmodels/CollaboratorsViewModelTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,26 @@ class CollaboratorsViewModelTest {
144144

145145
@Test
146146
fun collaboratorAddedAfterStoppedListeningChangesShouldNotUpdateUiState() = runTest {
147+
// Load collaborators and capture initial state
147148
viewModel.loadCollaborators(noteId)
149+
val initialState = viewModel.uiState.value
150+
151+
// Mock the flow to not emit anything initially
152+
whenever(mockCollaboratorsRepository.collaboratorsChanged(noteId)).thenReturn(flow { /* no emission */ })
153+
154+
// Start and then stop listening to changes
148155
viewModel.startListeningChanges()
149156
viewModel.stopListeningChanges()
150157

158+
// Now mock the flow to emit changes and mock getCollaborators to return a different list
159+
// This simulates collaborators being added after we stopped listening
151160
whenever(mockCollaboratorsRepository.collaboratorsChanged(noteId)).thenReturn(flow { emit(true) })
152-
val expectedList = listOf("[email protected]", "[email protected]")
161+
153162
whenever(mockCollaboratorsRepository.getCollaborators(noteId))
154-
.thenReturn(CollaboratorsActionResult.CollaboratorsList(expectedList))
163+
.thenReturn(CollaboratorsActionResult.CollaboratorsList(newList))
155164

156-
assertEquals(UiState.CollaboratorsList(expectedList), viewModel.uiState.value)
165+
// Since we stopped listening, the UI state should remain the same as the initial state
166+
assertEquals(initialState, viewModel.uiState.value)
157167
}
158168

159169
@Test

0 commit comments

Comments
 (0)