@@ -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- 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