-
Notifications
You must be signed in to change notification settings - Fork 14
fix clear screen function in Drawing canvas's viewmodel #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
| val note = notesRepository.getNoteStream(noteId).first() | ||
| assertTrue(note.strokesData.isNullOrEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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
Details:
Bug: 449768224
Change-Id: Ibb5725a4c03a0d5ae51e3b564cbebfaf7211c188