Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cka-dev
Copy link
Contributor

@cka-dev cka-dev commented Oct 8, 2025

Details:

  • clear function dind't rewrite viewmodel's record with empty list
  • added a test to make sure this does not break in the future

Bug: 449768224
Change-Id: Ibb5725a4c03a0d5ae51e3b564cbebfaf7211c188

Details:
  - clear function dind't rewrite viewmodel's record with empty list
  - added a test to make sure this does not break in the future

Bug: 449768224
Change-Id: Ibb5725a4c03a0d5ae51e3b564cbebfaf7211c188
@cka-dev cka-dev requested a review from romanofranz as a code owner October 8, 2025 22:13
@gemini-code-assist
Copy link

Summary of Changes

Hello @cka-dev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This PR fixes a bug in the DrawingCanvasViewModel where clearing the drawing canvas did not persist the empty stroke list to storage. The clearStrokes function now triggers a save operation, and a new test verifies that clearing the canvas correctly updates both the ViewModel's state and the persistent storage.

Highlights

  • Intent: This pull request addresses a bug (Bug: 449768224) where the clear function in the DrawingCanvasViewModel did not correctly persist the cleared state (an empty list of strokes) to the underlying data record. The fix ensures that clearing the canvas also saves this empty state, and a new test has been added to prevent future regressions.
  • Changes: The primary change is in DrawingCanvasViewModel.kt, where the clearStrokes() function now explicitly calls viewModelScope.launch { saveStrokes() } after updating the UI state with an empty list of strokes. This ensures the cleared state is persisted. Additionally, a new test case, clearStrokes_clears_and_saves_empty_strokes(), has been added to DrawingCanvasViewModelTest.kt to verify this behavior, asserting that both the ViewModel's UI state and the underlying repository reflect the empty strokes after clearing.
  • Reviewer Activity: No specific reviewer activity was provided in the context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

I've reviewed your pull request. The fix in DrawingCanvasViewModel to save the state after clearing strokes is correct and addresses the bug described. I've also added a new test case to ensure this functionality is covered going forward.

I found a critical issue in the new test case where the assertion doesn't correctly verify the behavior due to how the FakeNotesRepository is implemented. I've also included a suggestion to make the test more robust. Please see my detailed comments below.

Comment on lines 194 to 195
val note = notesRepository.getNoteStream(noteId).first()
assertTrue(note.strokesData.isNullOrEmpty())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This assertion is not correctly testing the desired behavior. The FakeNotesRepository doesn't populate the note.strokesData field; it uses an in-memory strokesFlow to manage strokes for testing purposes. As a result, note.strokesData will be null (its default value), and this assertion will always pass, regardless of whether the strokes were actually cleared from the repository. This gives a false sense of security that the feature is working and tested.

To fix this, you should directly check the strokes list from the FakeNotesRepository using getNoteStrokes(noteId).

Suggested change
val note = notesRepository.getNoteStream(noteId).first()
assertTrue(note.strokesData.isNullOrEmpty())
val strokesInRepo = notesRepository.getNoteStrokes(noteId)
assertTrue("Strokes should have been cleared from the repository.", strokesInRepo.isEmpty())

val stroke = Stroke(brush, ImmutableStrokeInputBatch.EMPTY)

viewModel.onStrokesFinished(listOf(stroke))
assertEquals(1, viewModel.uiState.value.strokes.size)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make this test more robust, it's good practice to verify the initial state completely before performing the main action under test. Here, you've correctly asserted that the stroke is added to the UI state. I recommend also asserting that it has been persisted to the repository.

This ensures that the clearStrokes function is tested against a correctly prepared state.

Suggested change
assertEquals(1, viewModel.uiState.value.strokes.size)
assertEquals(1, viewModel.uiState.value.strokes.size)
assertEquals(1, notesRepository.getNoteStrokes(noteId).size)

Bug: 449768224
Change-Id: I9cad96917f1794ae719c7260da41529365cc5873
@cka-dev cka-dev merged commit fd5d3ba into main Oct 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants