test : Add tests for Test Utils helper methods#3945
test : Add tests for Test Utils helper methods#3945yuvraj-kolkar17 wants to merge 3 commits intoGraphiteEditor:masterfrom
Conversation
Signed-off-by: Yuvraj Kolkar <[email protected]>
Summary of ChangesHello, 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 pull request introduces a suite of unit tests for 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new suite of asynchronous tests for the editor's core functionalities, such as creating an editor, managing documents, and drawing basic shapes like rectangles and ellipses. The tests verify that document creation and shape drawing correctly affect the layer count. The review suggests refactoring the repeated test setup logic into a helper function to improve code reuse and maintainability. It also recommends using assert_eq! for equality checks in tests for more idiomatic Rust and clearer failure messages.
editor/src/test_utils.rs
Outdated
| let mut editor = EditorTestUtils::create(); | ||
| editor.new_document().await; |
There was a problem hiding this comment.
The test setup logic of creating an editor and a new document is repeated across multiple tests (new_document_is_active, draw_rect_helper_creates_layer, draw_ellipse_helper_creates_layer, select_primary_color_does_not_add_layer, and draw_two_shapes_gives_two_layers).
To improve code reuse and reduce boilerplate, consider extracting this into a helper function within the test module. For example:
async fn create_editor_with_new_document() -> EditorTestUtils {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
editor
}Then, each test can be simplified, for instance:
#[tokio::test]
async fn new_document_is_active() {
let editor = create_editor_with_new_document().await;
assert_eq!(editor.active_document().metadata().all_layers().count(), 0);
}
editor/src/test_utils.rs
Outdated
| async fn new_document_is_active() { | ||
| let mut editor = EditorTestUtils::create(); | ||
| editor.new_document().await; | ||
| assert!(editor.active_document().metadata().all_layers().count() == 0); |
There was a problem hiding this comment.
Using assert_eq! is more idiomatic in Rust for equality checks in tests. It also provides a more informative failure message by showing the left and right values if the assertion fails, which can be helpful for debugging.
| assert!(editor.active_document().metadata().all_layers().count() == 0); | |
| assert_eq!(editor.active_document().metadata().all_layers().count(), 0); |
Signed-off-by: Yuvraj Kolkar <[email protected]>
Added unit tests in
test_utils.rsPart of #3936
editor_creates_successfullyverifies editor initializes without panickingnew_document_is_activeverifies new document is created with no layersdraw_rect_helper_creates_layerverifies drawing a rectangle creates one layerdraw_ellipse_helper_creates_layerverifies drawing an ellipse creates one layerselect_primary_color_does_not_add_layerverifies color selection does not add a layerdraw_two_shapes_gives_two_layersverifies drawing two shapes creates two layerstest execute
