From a9c0a39347d0545f8ff3830abe9bb0749b46d93b Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Sat, 14 Nov 2026 04:10:05 +0100 Subject: [PATCH 1/2] Tell what changed in a page since the last visit On opening a page, a banner names who changed it since the account last looked and where; it opens the changes hunk by hunk, and a hunk goes to its place in the page. The server keeps the seen mark, set with the token of the shown answer and again on leaving, so the own edits are no news later. Co-Authored-By: Claude Opus 5.5 --- .../feature/editor/ui/CodeEditorViewModel.kt | 39 +++++ .../editor/ui/compose/CodeEditorScreen.kt | 7 + .../ui/compose/CodeEditorScreenContent.kt | 8 + .../history/domain/SeenChangesUseCase.kt | 65 +++++++ .../history/ui/compose/ChangesSinceSeen.kt | 162 ++++++++++++++++++ app/src/main/res/values/strings.xml | 3 + .../history/domain/SeenChangesUseCaseTest.kt | 107 ++++++++++++ .../ui/compose/ChangesSinceSeenTest.kt | 53 ++++++ .../mkdocsrestclient/DummyMkDocsRestClient.kt | 8 + .../mkdocsrestclient/history/ChangesModels.kt | 63 +++++++ .../mkdocsrestclient/history/HistoryApi.kt | 24 +++ .../history/ChangesModelsTest.kt | 44 +++++ 12 files changed, 583 insertions(+) create mode 100644 app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt create mode 100644 app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeen.kt create mode 100644 app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt create mode 100644 app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeenTest.kt create mode 100644 rest/src/main/java/de/markusressel/mkdocsrestclient/history/ChangesModels.kt create mode 100644 rest/src/test/java/de/markusressel/mkdocsrestclient/history/ChangesModelsTest.kt diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt index ce61e8fa..8d780c7e 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt @@ -1,5 +1,10 @@ package de.markusressel.mkdocseditor.feature.editor.ui +import de.markusressel.mkdocseditor.feature.history.domain.SeenChangesUseCase +import de.markusressel.mkdocseditor.feature.history.domain.changeLocation +import de.markusressel.mkdocsrestclient.history.DiffHunkModel +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.flow.transformWhile import de.markusressel.mkdocseditor.feature.editor.domain.ChangeLocation import de.markusressel.mkdocsrestclient.dashboard.PinScope @@ -133,6 +138,7 @@ internal class CodeEditorViewModel @Inject constructor( private val qrCodesSupport: QrCodesSupport, private val pendingQrKey: PendingQrKey, private val resolveQrCode: ResolveQrCodeUseCase, + private val seenChanges: SeenChangesUseCase, savedStateHandle: SavedStateHandle, clientInstanceId: ClientInstanceId, moveItemUseCase: MoveItemUseCase, @@ -501,6 +507,12 @@ internal class CodeEditorViewModel @Inject constructor( launch { when (event) { is UiEvent.DismissDialog -> dismissCurrentDialog() + is UiEvent.ChangesSinceSeenClicked -> uiState.value.changesSinceSeen?.let { showDialog(DialogState.ChangesSinceSeen(it)) } + is UiEvent.ChangesSinceSeenDismissed -> _uiState.update { it.copy(changesSinceSeen = null) } + is UiEvent.ChangeHunkClicked -> { + dismissCurrentDialog() + jumpToChange(event.hunk.changeLocation()) + } is UiEvent.ItemActionClicked -> itemActions.onActionClicked( event.item, event.action, openElsewhere = uiState.value.remotePeers.isNotEmpty(), ) @@ -840,6 +852,20 @@ internal class CodeEditorViewModel @Inject constructor( */ fun setCurrentDocumentId(documentId: String?) { session.setDocument(documentId) + if (documentId != null && seenChangesAsked != documentId) { + seenChangesAsked = documentId + launch { _uiState.update { it.copy(changesSinceSeen = seenChanges.open(documentId)) } } + } + } + + /** the document whose changes since the last visit were asked for, once per editor */ + private var seenChangesAsked: String? = null + + /** the page as it is now counts as seen when the user leaves it, see [SeenChangesUseCase.leave] */ + private fun leavePage() { + val documentId = uiState.value.documentId ?: seenChangesAsked ?: return + // also after the editor is closed: it is a short request, and without it the own edits come back as news + launch(NonCancellable) { seenChanges.leave(documentId) } } /** @@ -976,9 +1002,11 @@ internal class CodeEditorViewModel @Inject constructor( */ internal fun onStop() { session.persist() + leavePage() } override fun onCleared() { + leavePage() session.close() super.onCleared() } @@ -1218,6 +1246,9 @@ internal class CodeEditorViewModel @Inject constructor( /** whether the server has QR codes, see [QrCodesSupport] */ val qrCodesAvailable: Boolean = false, + + /** what others changed since the user last looked at the page, null if nothing; see [SeenChangesUseCase] */ + val changesSinceSeen: DocumentChangesModel? = null, ) { val editorShown: Boolean get() = editModeActive || editModeOpening || readOnlyEditorShown @@ -1230,6 +1261,11 @@ internal class CodeEditorViewModel @Inject constructor( sealed class UiEvent { data object DismissDialog : UiEvent() + /** the banner about the changes since the last visit */ + data object ChangesSinceSeenClicked : UiEvent() + data object ChangesSinceSeenDismissed : UiEvent() + data class ChangeHunkClicked(val hunk: DiffHunkModel) : UiEvent() + data class ItemActionClicked(val item: WikiItem, val action: ItemAction) : UiEvent() data class ItemMovePreviewRequested(val parentId: String?, val name: String?) : UiEvent() data object ItemMoveBackClicked : UiEvent() @@ -1344,6 +1380,9 @@ internal class CodeEditorViewModel @Inject constructor( /** the view settings of the editor, as a sheet below it */ data object ViewSettings : DialogState + /** what changed since the last visit, hunk by hunk */ + data class ChangesSinceSeen(val changes: DocumentChangesModel) : DialogState + /** * The QR codes of the page, and adding or removing them * diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreen.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreen.kt index 61e72236..4d5a2568 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreen.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreen.kt @@ -31,6 +31,7 @@ import de.markusressel.mkdocseditor.feature.editor.ui.compose.picker.ResourcePic import androidx.compose.ui.res.stringResource import de.markusressel.mkdocseditor.R import de.markusressel.mkdocseditor.feature.qr.domain.QrLink +import de.markusressel.mkdocseditor.feature.history.ui.compose.ChangesSinceSeenSheet import de.markusressel.mkdocseditor.feature.history.ui.compose.HistoryScreen import de.markusressel.mkdocseditor.feature.qr.ui.compose.PageQrCodesDialog @@ -191,6 +192,12 @@ internal data class CodeEditorScreen( // in the content, which knows whether a split is open is CodeEditorViewModel.DialogState.ViewSettings -> Unit + is CodeEditorViewModel.DialogState.ChangesSinceSeen -> ChangesSinceSeenSheet( + changes = dialogState.changes, + onHunkClicked = { viewModel.onUiEvent(CodeEditorViewModel.UiEvent.ChangeHunkClicked(it)) }, + onDismiss = { viewModel.onUiEvent(CodeEditorViewModel.UiEvent.DismissDialog) }, + ) + is CodeEditorViewModel.DialogState.PageReferencesPanel -> if (tree != null && documentId != null) { PageReferencesDialog( tree = tree!!, diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreenContent.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreenContent.kt index 74bb4ec8..a3366065 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreenContent.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/compose/CodeEditorScreenContent.kt @@ -1,5 +1,6 @@ package de.markusressel.mkdocseditor.feature.editor.ui.compose +import de.markusressel.mkdocseditor.feature.history.ui.compose.ChangesSinceSeenBanner import de.markusressel.mkdocseditor.feature.editor.domain.AuthorRuns import de.markusressel.mkdocseditor.feature.editor.domain.visibleSourceLines import androidx.compose.animation.AnimatedVisibility @@ -228,6 +229,13 @@ internal fun CodeEditorScreenContent( ) { Column(modifier = Modifier.fillMaxSize()) { EditorBanners(uiState) + uiState.changesSinceSeen?.let { changes -> + ChangesSinceSeenBanner( + changes = changes, + onClick = { onUiEvent(CodeEditorViewModel.UiEvent.ChangesSinceSeenClicked) }, + onDismiss = { onUiEvent(CodeEditorViewModel.UiEvent.ChangesSinceSeenDismissed) }, + ) + } EditorPanes( modifier = Modifier.weight(1f), diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt new file mode 100644 index 00000000..dc1bb75d --- /dev/null +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt @@ -0,0 +1,65 @@ +package de.markusressel.mkdocseditor.feature.history.domain + +import com.github.kittinunf.result.Result +import de.markusressel.mkdocseditor.auth.domain.AuthRepository +import de.markusressel.mkdocseditor.feature.auth.common.data.AuthBackends +import de.markusressel.mkdocsrestclient.IMkDocsRestClient +import de.markusressel.mkdocsrestclient.history.ChangeAuthorModel +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel +import de.markusressel.mkdocsrestclient.reference.isUnsupportedEndpoint +import timber.log.Timber +import javax.inject.Inject + +/** + * What changed in a page since the account last looked at it (`GET /document/{id}/changes/`), and marking it as seen. + * The server keeps the mark, so all devices and the web client agree. A server without it tells nothing. + */ +internal class SeenChangesUseCase @Inject constructor( + private val restClient: IMkDocsRestClient, + private val backends: AuthBackends, + private val authRepository: AuthRepository, +) { + + /** + * The changes to tell about when the page opens. The page counts as seen as soon as they are shown, with the token + * of this answer, so an edit that arrives while reading stays news. + * + * @return null if there is nothing to tell: the page was never seen, nothing changed, only the account itself + * changed it, or the server can't say + */ + suspend fun open(documentId: String): DocumentChangesModel? { + val changes = changes(documentId) ?: return null + markSeen(documentId, changes.seenToken) + if (changes.since == null || changes.hunks.isEmpty()) return null + val own = ownUsername() + return changes.takeIf { it.authors.any { author -> author.isNewsFor(own) } } + } + + /** The page as it is now counts as seen, when the account leaves it: its own edits are no news later. */ + suspend fun leave(documentId: String) { + changes(documentId)?.let { markSeen(documentId, it.seenToken) } + } + + private suspend fun changes(documentId: String): DocumentChangesModel? = + when (val result = restClient.getDocumentChanges(documentId)) { + is Result.Success -> result.value + is Result.Failure -> { + if (!result.error.isUnsupportedEndpoint()) Timber.w(result.error, "changes of %s", documentId) + null + } + } + + /** a token the document lost in the meantime (409) needs no retry: the next visit asks again */ + private suspend fun markSeen(documentId: String, seenToken: String) { + val result = restClient.putDocumentSeen(documentId, seenToken) + if (result is Result.Failure && !result.error.isUnsupportedEndpoint()) { + Timber.w(result.error, "seen of %s", documentId) + } + } + + private suspend fun ownUsername(): String? = backends.selected()?.let { authRepository.session(it.id)?.username } +} + +/** someone else changed the page, or an agent of the account itself did */ +internal fun ChangeAuthorModel.isNewsFor(ownUsername: String?): Boolean = + agents.isNotEmpty() || ownUsername == null || username != ownUsername diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeen.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeen.kt new file mode 100644 index 00000000..8c2bf786 --- /dev/null +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeen.kt @@ -0,0 +1,162 @@ +package de.markusressel.mkdocseditor.feature.history.ui.compose + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Close +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import de.markusressel.mkdocseditor.R +import de.markusressel.mkdocseditor.feature.theme.MkDocsEditorTheme +import de.markusressel.mkdocseditor.util.compose.CombinedPreview +import de.markusressel.mkdocsrestclient.history.ChangeAuthorModel +import de.markusressel.mkdocsrestclient.history.DiffHunkModel +import de.markusressel.mkdocsrestclient.history.DiffLineModel +import de.markusressel.mkdocsrestclient.history.DiffOp +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel +import de.markusressel.mkdocsrestclient.history.HistorySummaryModel +import de.markusressel.mkdocsrestclient.history.SeenMarkModel +import java.util.Date + +/** "Anna, Bob via Claude Code": each person, with the agents they changed the page with */ +@Composable +private fun authorsText(authors: List): String { + val via = stringResource(R.string.history_via) + return authors.joinToString(", ") { author -> + if (author.agents.isEmpty()) author.displayName else via.format(author.displayName, author.agents.joinToString(", ")) + } +} + +/** + * Tells on opening a page who changed it since the last visit, and where. Tapping it shows the changes. + */ +@Composable +internal fun ChangesSinceSeenBanner( + changes: DocumentChangesModel, + onClick: () -> Unit, + onDismiss: () -> Unit, +) { + val headings = changes.summary.headings + Row( + modifier = Modifier + .fillMaxWidth() + .background(MaterialTheme.colorScheme.secondaryContainer) + .clickable(onClick = onClick) + .padding(start = 12.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f).padding(vertical = 6.dp)) { + Text( + text = stringResource(R.string.changes_since_seen_banner, authorsText(changes.authors)), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSecondaryContainer, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + ) + if (headings.isNotEmpty()) { + Text( + text = headings.joinToString(", "), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSecondaryContainer, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } + IconButton(onClick = onDismiss) { + Icon( + imageVector = Icons.Default.Close, + contentDescription = stringResource(R.string.changes_since_seen_dismiss), + tint = MaterialTheme.colorScheme.onSecondaryContainer, + ) + } + } +} + +/** The changes since the last visit, hunk by hunk; a hunk goes to its place in the page */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun ChangesSinceSeenSheet( + changes: DocumentChangesModel, + onHunkClicked: (DiffHunkModel) -> Unit, + onDismiss: () -> Unit, +) { + ModalBottomSheet( + onDismissRequest = onDismiss, + sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true), + ) { + ChangesSinceSeenContent(changes, onHunkClicked) + } +} + +@Composable +internal fun ChangesSinceSeenContent( + changes: DocumentChangesModel, + onHunkClicked: (DiffHunkModel) -> Unit, +) { + Column( + modifier = Modifier + .fillMaxWidth() + .verticalScroll(rememberScrollState()) + .padding(horizontal = 16.dp) + .padding(bottom = 16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text(text = stringResource(R.string.changes_since_seen_title), style = MaterialTheme.typography.titleMedium) + Text( + text = authorsText(changes.authors) + " · +${changes.summary.linesAdded} −${changes.summary.linesRemoved}", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + changes.hunks.forEach { hunk -> Hunk(hunk, onClick = { onHunkClicked(hunk) }) } + } +} + +@CombinedPreview +@Composable +private fun ChangesSinceSeenPreview() { + val changes = DocumentChangesModel( + since = SeenMarkModel(Date(0), "a"), + seenToken = "b", + authors = listOf( + ChangeAuthorModel(displayName = "Alice", color = "#e8590c"), + ChangeAuthorModel(displayName = "Bob", color = "#2f9e44", agents = listOf("Claude Code")), + ), + hunks = listOf( + DiffHunkModel( + heading = "Setup", headingOccurrence = 1, oldStart = 1, oldLines = 2, newStart = 1, newLines = 3, + lines = listOf( + DiffLineModel(DiffOp.CONTEXT, "# Setup"), + DiffLineModel(DiffOp.REMOVED, "Some text."), + DiffLineModel(DiffOp.ADDED, "Some better text."), + DiffLineModel(DiffOp.ADDED, "## Install"), + ), + ), + ), + summary = HistorySummaryModel(2, 1, listOf("Setup", "Install")), + ) + MkDocsEditorTheme { + Column { + ChangesSinceSeenBanner(changes, onClick = {}, onDismiss = {}) + ChangesSinceSeenContent(changes, onHunkClicked = {}) + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fbdd437f..0efd5aab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -462,4 +462,7 @@ The page gets the text it had %1$s, after the change of %2$s. Everyone sees it as an edit, which can be undone. Restore Version restored + Changed by %1$s since you were here + Changes since your last visit + Hide diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt new file mode 100644 index 00000000..12c08fd1 --- /dev/null +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt @@ -0,0 +1,107 @@ +package de.markusressel.mkdocseditor.feature.history.domain + +import com.github.kittinunf.fuel.core.FuelError +import com.github.kittinunf.fuel.core.Response +import com.github.kittinunf.result.Result +import de.markusressel.mkdocseditor.auth.FakeAuthApi +import de.markusressel.mkdocseditor.auth.InMemoryTokenStore +import de.markusressel.mkdocseditor.auth.domain.AuthRepository +import de.markusressel.mkdocseditor.auth.token.AuthSession +import de.markusressel.mkdocseditor.feature.auth.FakeAuthBackends +import de.markusressel.mkdocseditor.feature.auth.backendConfig +import de.markusressel.mkdocsrestclient.DummyMkDocsRestClient +import de.markusressel.mkdocsrestclient.IMkDocsRestClient +import de.markusressel.mkdocsrestclient.history.ChangeAuthorModel +import de.markusressel.mkdocsrestclient.history.DiffHunkModel +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel +import de.markusressel.mkdocsrestclient.history.SeenMarkModel +import de.markusressel.mkdocsrestclient.history.SeenModel +import kotlinx.coroutines.test.runTest +import java.net.URL +import java.util.Date +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class SeenChangesUseCaseTest { + + private val hunk = DiffHunkModel(heading = "Setup", oldStart = 1, oldLines = 1, newStart = 1, newLines = 1) + private val alice = ChangeAuthorModel(accountId = "a1", username = "alice", displayName = "Alice") + private val carol = ChangeAuthorModel(accountId = "a3", username = "carol", displayName = "Carol") + + private var answer: Result = Result.success(changes(listOf(alice))) + private val seen = mutableListOf() + + private fun changes(authors: List, since: SeenMarkModel? = SeenMarkModel(Date(0), "old")) = + DocumentChangesModel(since = since, seenToken = "now", authors = authors, hunks = if (authors.isEmpty()) emptyList() else listOf(hunk)) + + private val client = object : IMkDocsRestClient by DummyMkDocsRestClient() { + override suspend fun getDocumentChanges(documentId: String, since: String?) = answer + + override suspend fun putDocumentSeen(documentId: String, seenToken: String): Result { + seen += seenToken + return Result.success(SeenModel(Date(), seenToken)) + } + } + + private val useCase = SeenChangesUseCase( + restClient = client, + backends = FakeAuthBackends().apply { + configs += backendConfig(1) + selectedId = 1 + }, + authRepository = AuthRepository( + InMemoryTokenStore().apply { put(1, AuthSession("t", null, "carol")) }, + { FakeAuthApi() }, + deviceName = "Pixel 8", + ), + ) + + @Test + fun `changes of someone else are told, and the page counts as seen with the token of the answer`() = runTest { + val changes = useCase.open("d1") + + assertEquals(listOf(alice), changes?.authors) + assertEquals(listOf("now"), seen) + } + + @Test + fun `the own edits are no news, those of an own agent are`() = runTest { + answer = Result.success(changes(listOf(carol))) + assertNull(useCase.open("d1")) + + answer = Result.success(changes(listOf(carol.copy(agents = listOf("Claude Code"))))) + assertEquals("Claude Code", useCase.open("d1")?.authors?.single()?.agents?.single()) + } + + @Test + fun `a page seen for the first time has no news, but is marked`() = runTest { + answer = Result.success(DocumentChangesModel(since = null, seenToken = "now")) + + assertNull(useCase.open("d1")) + assertEquals(listOf("now"), seen) + } + + @Test + fun `an unchanged page has no news`() = runTest { + answer = Result.success(changes(emptyList())) + + assertNull(useCase.open("d1")) + } + + @Test + fun `a server without the endpoint tells nothing and marks nothing`() = runTest { + answer = Result.error(FuelError.wrap(RuntimeException("404"), Response(URL("http://localhost/"), statusCode = 404))) + + assertNull(useCase.open("d1")) + useCase.leave("d1") + assertEquals(emptyList(), seen) + } + + @Test + fun `leaving the page marks it as it is now`() = runTest { + useCase.leave("d1") + + assertEquals(listOf("now"), seen) + } +} diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeenTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeenTest.kt new file mode 100644 index 00000000..c0c7fb12 --- /dev/null +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/ChangesSinceSeenTest.kt @@ -0,0 +1,53 @@ +package de.markusressel.mkdocseditor.feature.history.ui.compose + +import android.app.Application +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.test.ext.junit.runners.AndroidJUnit4 +import de.markusressel.mkdocseditor.feature.theme.MkDocsEditorTheme +import de.markusressel.mkdocsrestclient.history.ChangeAuthorModel +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel +import de.markusressel.mkdocsrestclient.history.HistorySummaryModel +import de.markusressel.mkdocsrestclient.history.SeenMarkModel +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.annotation.Config +import java.util.Date +import kotlin.test.assertEquals + +@RunWith(AndroidJUnit4::class) +@Config(application = Application::class, sdk = [36]) +class ChangesSinceSeenTest { + + @get:Rule + val composeRule = createComposeRule() + + private val changes = DocumentChangesModel( + since = SeenMarkModel(Date(0), "a"), + seenToken = "b", + authors = listOf( + ChangeAuthorModel(displayName = "Alice"), + ChangeAuthorModel(displayName = "Bob", agents = listOf("Claude Code")), + ), + summary = HistorySummaryModel(2, 1, listOf("Setup", "Install")), + ) + + @Test + fun `the banner names who changed the page and where, and opens or hides`() { + val clicks = mutableListOf() + composeRule.setContent { + MkDocsEditorTheme { + ChangesSinceSeenBanner(changes, onClick = { clicks += "open" }, onDismiss = { clicks += "hide" }) + } + } + + composeRule.onNodeWithText("Changed by Alice, Bob via Claude Code since you were here").performClick() + composeRule.onNodeWithText("Setup, Install").assertExists() + composeRule.onNodeWithContentDescription("Hide").performClick() + + assertEquals(listOf("open", "hide"), clicks) + } +} diff --git a/rest/src/main/java/de/markusressel/mkdocsrestclient/DummyMkDocsRestClient.kt b/rest/src/main/java/de/markusressel/mkdocsrestclient/DummyMkDocsRestClient.kt index e8f3ea9f..df75f145 100644 --- a/rest/src/main/java/de/markusressel/mkdocsrestclient/DummyMkDocsRestClient.kt +++ b/rest/src/main/java/de/markusressel/mkdocsrestclient/DummyMkDocsRestClient.kt @@ -3,7 +3,9 @@ package de.markusressel.mkdocsrestclient import de.markusressel.mkdocsrestclient.dashboard.FeedPageModel +import de.markusressel.mkdocsrestclient.history.DocumentChangesModel import de.markusressel.mkdocsrestclient.history.HistoryDiffModel +import de.markusressel.mkdocsrestclient.history.SeenModel import de.markusressel.mkdocsrestclient.history.HistoryEntryModel import de.markusressel.mkdocsrestclient.dashboard.PinScope import de.markusressel.mkdocsrestclient.dashboard.PinsModel @@ -289,6 +291,12 @@ class DummyMkDocsRestClient : IMkDocsRestClient { override suspend fun getDocumentRevisionDiffHunks(documentId: String, from: String, to: String): Result = Result.success(HistoryDiffModel(from, to)) + override suspend fun getDocumentChanges(documentId: String, since: String?): Result = + Result.success(DocumentChangesModel(seenToken = "")) + + override suspend fun putDocumentSeen(documentId: String, seenToken: String): Result = + Result.success(SeenModel(Date(), seenToken)) + override suspend fun restoreDocumentRevision(documentId: String, revision: String): Result = Result.success("") diff --git a/rest/src/main/java/de/markusressel/mkdocsrestclient/history/ChangesModels.kt b/rest/src/main/java/de/markusressel/mkdocsrestclient/history/ChangesModels.kt new file mode 100644 index 00000000..2de2cb37 --- /dev/null +++ b/rest/src/main/java/de/markusressel/mkdocsrestclient/history/ChangesModels.kt @@ -0,0 +1,63 @@ +package de.markusressel.mkdocsrestclient.history + +import com.squareup.moshi.JsonClass +import java.util.Date + +/** + * What changed in a document since the signed in account last looked, from `GET /document/{id}/changes/` + * + * @param since when the account last looked, null if it never did: then there are no hunks + * @param seenToken the text this answer is about, to send to `PUT /document/{id}/seen/` once it was shown + * @param hunks against the live text, empty if nothing changed + */ +@JsonClass(generateAdapter = true) +data class DocumentChangesModel( + val since: SeenMarkModel? = null, + val seenToken: String, + val authors: List = emptyList(), + val hunks: List = emptyList(), + val summary: HistorySummaryModel = HistorySummaryModel(), +) { + override fun toString() = "DocumentChangesModel(since=${since?.time}, authors=${authors.size}, hunks=${hunks.size})" +} + +/** The last look of the account at a document */ +@JsonClass(generateAdapter = true) +data class SeenMarkModel( + val time: Date, + val seenToken: String, +) { + override fun toString() = "SeenMarkModel(time=$time)" +} + +/** + * Someone who changed the document, with the current name, color and picture of the account, like in the feed + * + * @param agents the names of the app tokens this account changed the document with + */ +@JsonClass(generateAdapter = true) +data class ChangeAuthorModel( + val accountId: String? = null, + val username: String? = null, + val displayName: String, + val color: String? = null, + val avatar: String? = null, + val agents: List = emptyList(), +) + +/** `PUT /document/{id}/seen/` */ +@JsonClass(generateAdapter = true) +data class SeenRequestModel( + val seenToken: String, +) { + override fun toString() = "SeenRequestModel" +} + +/** The answer of `PUT /document/{id}/seen/` */ +@JsonClass(generateAdapter = true) +data class SeenModel( + val seenAt: Date, + val seenToken: String, +) { + override fun toString() = "SeenModel(seenAt=$seenAt)" +} diff --git a/rest/src/main/java/de/markusressel/mkdocsrestclient/history/HistoryApi.kt b/rest/src/main/java/de/markusressel/mkdocsrestclient/history/HistoryApi.kt index 6717aca5..bc60e986 100644 --- a/rest/src/main/java/de/markusressel/mkdocsrestclient/history/HistoryApi.kt +++ b/rest/src/main/java/de/markusressel/mkdocsrestclient/history/HistoryApi.kt @@ -42,6 +42,15 @@ interface HistoryApi { to: String = REVISION_CURRENT, ): Result + /** + * @param since a seen token, null for the last look of the signed in account + * @return what changed since then; a token the document no longer knows answers 409 `unknown-revision` + */ + suspend fun getDocumentChanges(documentId: String, since: String? = null): Result + + /** Marks the text of [seenToken] as seen by the signed in account. A token the document no longer knows answers 409. */ + suspend fun putDocumentSeen(documentId: String, seenToken: String): Result + /** Sets the live text to the one of [revision], as an edit of the signed in account. Editors and admins only. */ suspend fun restoreDocumentRevision(documentId: String, revision: String): Result } @@ -78,6 +87,21 @@ class HistoryApiImpl( method = Method.GET, ) + override suspend fun getDocumentChanges(documentId: String, since: String?): Result = + requestManager.doRequest( + url = "/document/$documentId/changes/", + urlParameters = listOfNotNull(since?.let { "since" to it }), + method = Method.GET, + ) + + override suspend fun putDocumentSeen(documentId: String, seenToken: String): Result = + requestManager.doJsonRequest( + url = "/document/$documentId/seen/", + method = Method.PUT, + jsonData = SeenRequestModel(seenToken), + kind = RequestKind.Quick, + ) + override suspend fun restoreDocumentRevision(documentId: String, revision: String): Result = requestManager.doRequest( url = "/document/$documentId/history/$revision/restore/", diff --git a/rest/src/test/java/de/markusressel/mkdocsrestclient/history/ChangesModelsTest.kt b/rest/src/test/java/de/markusressel/mkdocsrestclient/history/ChangesModelsTest.kt new file mode 100644 index 00000000..9df4c9fe --- /dev/null +++ b/rest/src/test/java/de/markusressel/mkdocsrestclient/history/ChangesModelsTest.kt @@ -0,0 +1,44 @@ +package de.markusressel.mkdocsrestclient.history + +import de.markusressel.mkdocsrestclient.reference.ApiErrorModel +import de.markusressel.mkdocsrestclient.toEntity +import java.time.Instant +import java.util.Date +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +/** Real answers of a backend with B2: Carol saw the page, then Alice added a section and Bob's token changed a line */ +class ChangesModelsTest { + + @Test + fun `changes since the last look are read with their authors, agents and hunks`() { + val changes = """ + {"since":{"time":"2026-11-14T03:00:24.962Z","seenToken":"ab181433912a1fe6082d0247c32d137940b7bd532f841748418ffa06af8b11d2"},"seenToken":"b62168b4464c85c3b78186f3af9f4d83c12361060c7087a7753ce26851115a3b","authors":[{"accountId":"5y7wrjicdbpk5b3lo7xzewblee","username":"alice","displayName":"alice","color":"#e8590c","avatar":null,"agents":[]},{"accountId":"nogzraprjnjhwib3z42cub4qia","username":"bob","displayName":"bob","color":"#2f9e44","avatar":null,"agents":["Claude Code"]}],"hunks":[{"heading":"Setup","headingOccurrence":1,"offset":0,"oldStart":1,"oldLines":3,"newStart":1,"newLines":7,"lines":[{"op":" ","text":"# Setup"},{"op":" ","text":""},{"op":"-","text":"Some text."},{"op":"+","text":"Some better text."},{"op":"+","text":""},{"op":"+","text":"## Install"},{"op":"+","text":""},{"op":"+","text":"Run the installer."}]}],"summary":{"linesAdded":5,"linesRemoved":1,"headings":["Setup","Install"]}} + """.trimIndent().toEntity() + + assertEquals(Date.from(Instant.parse("2026-11-14T03:00:24.962Z")), changes.since?.time) + assertEquals("b62168b4464c85c3b78186f3af9f4d83c12361060c7087a7753ce26851115a3b", changes.seenToken) + assertEquals(listOf("alice", "bob"), changes.authors.map { it.username }) + assertEquals(listOf("Claude Code"), changes.authors[1].agents) + assertEquals(8, changes.hunks.single().lines.size) + assertEquals(HistorySummaryModel(5, 1, listOf("Setup", "Install")), changes.summary) + } + + @Test + fun `a page that never was seen has no since and no hunks`() { + val changes = """ + {"since":null,"seenToken":"b62168b4","authors":[],"hunks":[],"summary":{"linesAdded":0,"linesRemoved":0,"headings":[]}} + """.trimIndent().toEntity() + + assertNull(changes.since) + assertEquals(emptyList(), changes.hunks) + } + + @Test + fun `a token the document no longer knows is told apart by its code`() { + val body = """{"name":"Conflict","code":"unknown-revision","message":"the document does not know this revision, get the changes again"}""" + + assertEquals("unknown-revision", ApiErrorModel.parse(body.toByteArray())?.code) + } +} From c91f536f73ef8be14a4ab36f0eeb0fe21ab5db72 Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Sat, 14 Nov 2026 04:29:09 +0100 Subject: [PATCH 2/2] Fix what the emulator test against a real backend found - The changes since the last visit were asked for inside a state update, which runs again when the state changed meanwhile: each run marked the page seen, so the shown answer was always empty. Leaving the page no longer marks it on ON_STOP either, which the screen gets while opening. - The account itself is left out of the names of the banner. - In the history an agent goes with its own person: "Bob via Claude Code, Anna" instead of "Bob, Anna via Claude Code". - Lines with little in common get no word marks. - A commit time a little ahead of the device clock reads as now. Co-Authored-By: Claude Opus 5.5 --- .../feature/editor/ui/CodeEditorViewModel.kt | 19 +++++++++++++---- .../feature/history/domain/HistoryText.kt | 17 +++++++++++++++ .../history/domain/SeenChangesUseCase.kt | 7 ++++--- .../feature/history/domain/WordDiff.kt | 15 +++++++++++-- .../ui/compose/HistoryScreenContent.kt | 21 ++++++++++--------- .../feature/history/domain/HistoryTextTest.kt | 10 +++++++++ .../history/domain/SeenChangesUseCaseTest.kt | 7 +++++++ .../feature/history/domain/WordDiffTest.kt | 6 ++++++ .../ui/compose/HistoryScreenContentTest.kt | 3 ++- 9 files changed, 85 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt index 8d780c7e..6d890ca2 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/editor/ui/CodeEditorViewModel.kt @@ -854,17 +854,29 @@ internal class CodeEditorViewModel @Inject constructor( session.setDocument(documentId) if (documentId != null && seenChangesAsked != documentId) { seenChangesAsked = documentId - launch { _uiState.update { it.copy(changesSinceSeen = seenChanges.open(documentId)) } } + launch { + // not inside update: it runs its block again when the state changed meanwhile, and each run marks seen + val changes = seenChanges.open(documentId) + _uiState.update { it.copy(changesSinceSeen = changes) } + seenChangesOpened = true + } } } /** the document whose changes since the last visit were asked for, once per editor */ private var seenChangesAsked: String? = null - /** the page as it is now counts as seen when the user leaves it, see [SeenChangesUseCase.leave] */ + /** whether the changes since the last visit are known; marking the page seen before that would swallow them */ + private var seenChangesOpened = false + + /** + * The page as it is now counts as seen when the user closes it, see [SeenChangesUseCase.leave]. Not on ON_STOP: the + * screen gets one while it opens. + */ private fun leavePage() { + if (!seenChangesOpened) return val documentId = uiState.value.documentId ?: seenChangesAsked ?: return - // also after the editor is closed: it is a short request, and without it the own edits come back as news + // after the editor is closed: it is a short request, and without it the own edits come back as news launch(NonCancellable) { seenChanges.leave(documentId) } } @@ -1002,7 +1014,6 @@ internal class CodeEditorViewModel @Inject constructor( */ internal fun onStop() { session.persist() - leavePage() } override fun onCleared() { diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryText.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryText.kt index 36ad44b6..8d925541 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryText.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryText.kt @@ -39,6 +39,23 @@ internal val HistoryAuthorModel.shownName: String internal val HistoryEntryModel.people: List get() = (listOf(author) + coAuthors).distinctBy { it.accountId.ifEmpty { it.email } } +/** + * The people of an entry, each with the agents they made the changes with: "Bob via Claude Code, Anna". An agent + * without its person among them, or from a backend that only sends token names, goes with the author. + * + * @return each person with the names of their agents + */ +internal val HistoryEntryModel.peopleWithAgents: List>> + get() { + val people = people + val known = agents.filter { agent -> people.any { it.isAccount && it.accountId == agent.accountId } } + val homeless = agentNames - known.map { it.name }.toSet() + return people.mapIndexed { index, person -> + val own = known.filter { person.isAccount && it.accountId == person.accountId }.map { it.name } + person to (own + if (index == 0) homeless else emptyList()).distinct() + } + } + /** * The names of the agents of an entry. A backend before `agents` only has the token names. */ diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt index dc1bb75d..20b8d542 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCase.kt @@ -24,15 +24,16 @@ internal class SeenChangesUseCase @Inject constructor( * The changes to tell about when the page opens. The page counts as seen as soon as they are shown, with the token * of this answer, so an edit that arrives while reading stays news. * - * @return null if there is nothing to tell: the page was never seen, nothing changed, only the account itself - * changed it, or the server can't say + * @return the changes with only the authors that are news, null if there is nothing to tell: the page was never + * seen, nothing changed, only the account itself changed it, or the server can't say */ suspend fun open(documentId: String): DocumentChangesModel? { val changes = changes(documentId) ?: return null markSeen(documentId, changes.seenToken) if (changes.since == null || changes.hunks.isEmpty()) return null val own = ownUsername() - return changes.takeIf { it.authors.any { author -> author.isNewsFor(own) } } + val others = changes.authors.filter { it.isNewsFor(own) } + return if (others.isEmpty()) null else changes.copy(authors = others) } /** The page as it is now counts as seen, when the account leaves it: its own edits are no news later. */ diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiff.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiff.kt index 53f73b0a..713a5f40 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiff.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiff.kt @@ -14,9 +14,13 @@ private const val MAX_TOKENS = 400 private val token = Regex("""\w+|\s+|[^\w\s]""") +/** Below this share of unchanged text, two lines are different lines and not one changed line */ +private const val MIN_UNCHANGED_SHARE = 0.4 + /** * Which words of [old] were removed and which of [new] were added. Words, spaces and single signs count as units, so a - * change marks whole words. + * change marks whole words. Lines with little in common get no marks: the line color says enough, and marks on nearly + * every word only hide the few that stayed. */ internal fun wordChanges(old: String, new: String): WordChanges { val a = token.findAll(old).toList() @@ -42,7 +46,14 @@ internal fun wordChanges(old: String, new: String): WordChanges { else -> removed += a[i++].range } } - return WordChanges(removed.merged(), added.merged()) + val changes = WordChanges(removed.merged(), added.merged()) + val unchanged = old.length - changes.removed.sumOf { it.end - it.start } + val longer = maxOf(old.length, new.length) + return if (longer > 0 && old.isNotEmpty() && new.isNotEmpty() && unchanged < MIN_UNCHANGED_SHARE * longer) { + WordChanges(emptyList(), emptyList()) + } else { + changes + } } private fun whole(text: String) = if (text.isEmpty()) null else Highlight(0, text.length) diff --git a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContent.kt b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContent.kt index 943a0dd2..c9251692 100644 --- a/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContent.kt +++ b/app/src/main/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContent.kt @@ -56,7 +56,7 @@ import de.markusressel.mkdocseditor.feature.history.domain.Highlight import de.markusressel.mkdocseditor.feature.history.domain.agentNames import de.markusressel.mkdocseditor.feature.history.domain.notableMessage import de.markusressel.mkdocseditor.feature.history.domain.pairChangedLines -import de.markusressel.mkdocseditor.feature.history.domain.people +import de.markusressel.mkdocseditor.feature.history.domain.peopleWithAgents import de.markusressel.mkdocseditor.feature.history.domain.shownName import de.markusressel.mkdocseditor.feature.history.domain.wordChanges import de.markusressel.mkdocseditor.feature.history.ui.HistoryViewModel.DiffState @@ -223,12 +223,13 @@ private fun EntryAvatar(entry: HistoryEntryModel) { private fun authorColor(author: HistoryAuthorModel): Color = parsePeerColor(author.color) ?: fallbackPeerColor(author.username.ifEmpty { author.name }) -/** "Anna, Bob via Claude Code" */ +/** "Bob via Claude Code, Anna" */ @Composable private fun whoText(entry: HistoryEntryModel): String { - val people = entry.people.joinToString(", ") { it.shownName } - val agents = entry.agentNames - return if (agents.isEmpty()) people else stringResource(R.string.history_via, people, agents.joinToString(", ")) + val via = stringResource(R.string.history_via) + return entry.peopleWithAgents.joinToString(", ") { (person, agents) -> + if (agents.isEmpty()) person.shownName else via.format(person.shownName, agents.joinToString(", ")) + } } @Composable @@ -238,12 +239,12 @@ private fun summaryText(summary: HistorySummaryModel?): String? { return if (summary.headings.isEmpty()) lines else "$lines · ${summary.headings.joinToString(", ")}" } +/** a commit from a server whose clock is a little ahead is "now", not "in 0 minutes" */ @Composable -private fun relativeTime(time: Date): String = DateUtils.getRelativeTimeSpanString( - time.time, - System.currentTimeMillis(), - DateUtils.MINUTE_IN_MILLIS, -).toString() +private fun relativeTime(time: Date): String { + val now = System.currentTimeMillis() + return DateUtils.getRelativeTimeSpanString(minOf(time.time, now), now, DateUtils.MINUTE_IN_MILLIS).toString() +} @Composable private fun EntryDiff(diff: DiffState?, onUiEvent: (UiEvent) -> Unit) { diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryTextTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryTextTest.kt index e0abd775..dac36329 100644 --- a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryTextTest.kt +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/HistoryTextTest.kt @@ -75,6 +75,16 @@ class HistoryTextTest { assertEquals(listOf("Claude Code"), entry(appTokens = listOf("Claude Code")).agentNames) } + @Test + fun `an agent goes with its own person, one of an unknown person or without account with the author`() { + val bob = author("bob", "a2") + val agents = listOf(HistoryAgentModel("Claude Code", "a2"), HistoryAgentModel("Script", "a9")) + val withAgents = entry(author("anna", "a1"), listOf(bob), agents = agents).peopleWithAgents + + assertEquals(listOf("anna" to listOf("Script"), "bob" to listOf("Claude Code")), withAgents.map { (p, a) -> p.shownName to a }) + assertEquals(listOf("Claude Code"), entry(appTokens = listOf("Claude Code")).peopleWithAgents.single().second) + } + @Test fun `the standard message of an edit is left out, others are shown`() { assertNull(entry().notableMessage) diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt index 12c08fd1..fda91320 100644 --- a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/SeenChangesUseCaseTest.kt @@ -74,6 +74,13 @@ class SeenChangesUseCaseTest { assertEquals("Claude Code", useCase.open("d1")?.authors?.single()?.agents?.single()) } + @Test + fun `the account itself is left out of the names, next to someone else`() = runTest { + answer = Result.success(changes(listOf(carol, alice))) + + assertEquals(listOf(alice), useCase.open("d1")?.authors) + } + @Test fun `a page seen for the first time has no news, but is marked`() = runTest { answer = Result.success(DocumentChangesModel(since = null, seenToken = "now")) diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiffTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiffTest.kt index 1b39ed44..f82dee76 100644 --- a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiffTest.kt +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/domain/WordDiffTest.kt @@ -15,6 +15,12 @@ class WordDiffTest { assertEquals(listOf(Highlight(12, 16), Highlight(23, 26)), changes.added) } + @Test + fun `lines with little in common get no marks`() { + assertEquals(WordChanges(emptyList(), emptyList()), wordChanges("Then reboot.", "Wait for it to finish.")) + assertEquals(listOf(Highlight(5, 12)), wordChanges("Some text.", "Some better text.").added) + } + @Test fun `an emptied line is marked as a whole`() { assertEquals(WordChanges(listOf(Highlight(0, 3)), emptyList()), wordChanges("abc", "")) diff --git a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContentTest.kt b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContentTest.kt index 2ca06360..dcea20a9 100644 --- a/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContentTest.kt +++ b/app/src/test/java/de/markusressel/mkdocseditor/feature/history/ui/compose/HistoryScreenContentTest.kt @@ -43,7 +43,7 @@ class HistoryScreenContentTest { private val entries = listOf( HistoryEntryModel( revision = "b", time = Date(), author = anna, coAuthors = listOf(bob), message = "Update a.md", path = "a.md", - agents = listOf(HistoryAgentModel("Claude Code", "a1")), summary = HistorySummaryModel(1, 1, listOf("Install")), + agents = listOf(HistoryAgentModel("Claude Code", "a2")), summary = HistorySummaryModel(1, 1, listOf("Install")), ), HistoryEntryModel(revision = "a", time = Date(0), author = anna, message = "Restore a.md to 0123456789ab", path = "a.md"), ) @@ -69,6 +69,7 @@ class HistoryScreenContentTest { } composeRule.onNodeWithText("Anna, Bob via Claude Code").assertExists() + composeRule.onNodeWithText("Anna via Claude Code, Bob").assertDoesNotExist() composeRule.onNodeWithText("+1 −1 · Install", substring = true).assertExists() composeRule.onNodeWithText("Restore a.md to 0123456789ab").assertExists() composeRule.onNodeWithText("Update a.md").assertDoesNotExist()