Skip to content
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

SWTBot test case: Partition Table Editor #1012

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

AndriiFilippov
Copy link
Collaborator

@AndriiFilippov AndriiFilippov commented Jul 1, 2024

Description

add Partition Table Editor test cases.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • Tests
    • Introduced a new automated test for the Partition Table Editor to validate its functionality with newly created projects.
    • Removed an outdated method for opening the context menu for component installation, indicating a shift in project management workflow.
    • Added new methods to enhance verification of UI elements and partition table contents during testing, improving overall test coverage.

Copy link

coderabbitai bot commented Jul 1, 2024

Walkthrough

The new file NewEspressifIDFProjectPartitionTableEditorTest.java introduces a test class dedicated to validating the functionality of the Partition Table Editor within the Espressif IDF project environment. It includes setup and teardown methods for managing the test environment, ensuring that the editor behaves correctly when interacting with newly created projects. Additionally, the ProjectTestOperations.java file has undergone changes, including the removal of a method related to component installation and the addition of methods for verifying UI shell content and partition table contents.

Changes

Files Change Summary
tests/com.espressif.idf.ui.test/.../NewEspressifIDFProjectPartitionTableEditorTest.java Introduced a new test class for validating the Partition Table Editor functionality, added various setup and cleanup methods, including a static inner class for test fixtures.
tests/com.espressif.idf.ui.test/.../ProjectTestOperations.java Removed the method openProjectNewComponentUsingContextMenu, indicating a change in how new components are managed, and added methods checkShellContent, checkPartitionTableContent, and comparePartitionTableRows for verifying UI elements.

Suggested reviewers

  • alirana01
  • kolipakakondal

Poem

Through tests we march with great delight,
Ensuring code's function day and night.
With projects built and cleaned anew,
The editor shines, its purpose true.
In lines of code, our trust takes flight,
For Espressif's work, both clear and bright.


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 311374a and 4e33063.

Files selected for processing (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3321cc0 and f64ad58.

Files selected for processing (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
Additional comments not posted (6)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (6)

35-38: Specify a more specific exception type.

The beforeTestClass method currently throws a generic Exception. It's better to specify a more specific exception type to improve readability and error handling.

-	public static void beforeTestClass() throws Exception
+	public static void beforeTestClass() throws IOException

55-60: Make the sleep duration configurable or add a comment.

The loadEnv method includes a sleep duration of 1000 milliseconds. Consider making this duration configurable or adding a comment to explain its necessity.

-	bot.sleep(1000);
+	bot.sleep(1000); // Sleep to ensure the environment is fully set up

OR

private static final int SLEEP_DURATION = 1000;

private static void loadEnv() throws Exception {
	bot = WorkBenchSWTBot.getBot();
	EnvSetupOperations.setupEspressifEnv(bot);
	bot.sleep(SLEEP_DURATION);
}

62-66: LGTM!

The method givenNewEspressifIDFProjectIsSelected is correctly implemented.


68-71: LGTM!

The method givenProjectNameIs is correctly implemented.


73-76: LGTM!

The method whenNewProjectIsSelected is correctly implemented.


78-83: LGTM!

The method whenProjectIsBuiltUsingContextMenu is correctly implemented.

Comment on lines +41 to +45
public void afterEachTest()
{
Fixture.cleanTestEnv();
}
Copy link

Choose a reason for hiding this comment

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

Handle potential exceptions within the method.

The afterEachTest method currently does not handle potential exceptions. Consider adding exception handling to ensure the test environment is cleaned up properly even if an error occurs.

@After
public void afterEachTest() {
	try {
		Fixture.cleanTestEnv();
	} catch (Exception e) {
		// Log the exception and proceed with cleanup
		e.printStackTrace();
	}
}

Comment on lines +85 to +111
private static void cleanTestEnv()
{
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
}
Copy link

Choose a reason for hiding this comment

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

Handle potential exceptions within the method.

The cleanTestEnv method currently does not handle potential exceptions. Consider adding exception handling to ensure the test environment is cleaned up properly even if an error occurs.

private static void cleanTestEnv() {
	try {
		TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
		ProjectTestOperations.closeAllProjects(bot);
		ProjectTestOperations.deleteAllProjects(bot);
	} catch (Exception e) {
		// Log the exception and proceed with cleanup
		e.printStackTrace();
	}
}

@kolipakakondal
Copy link
Collaborator

@alirana01 please review this

@AndriiFilippov AndriiFilippov changed the title SWTBot test case: Partition Table Editor WIP: SWTBot test case: Partition Table Editor Aug 30, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1)

47-55: Refactor the method name to follow Java naming conventions.

The method name is very long and does not follow the Java naming conventions. Please refactor it to a shorter name that follows the camelCase convention.

For example:

@Test
public void testPartitionTableEditorDisabledForNewUnbuiltProject() throws Exception {
	// ...
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f64ad58 and 2acabf6.

Files selected for processing (3)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (1 hunks)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java
Additional comments not posted (10)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (9)

35-39: LGTM!

The beforeTestClass method is correctly implemented to load the test environment.


41-45: Skipping comment as the past review feedback is still applicable.

Please address the exception handling suggestion from the previous review round.


64-69: LGTM!

The loadEnv method is correctly implemented to load the test environment.


71-75: LGTM!

The givenNewEspressifIDFProjectIsSelected method is correctly implemented to set up the project category and subcategory for the test.


77-80: LGTM!

The givenProjectNameIs method is correctly implemented to set up the project name for the test.


82-85: LGTM!

The whenNewProjectIsSelected method is correctly implemented to set up a new project for the test.


94-97: LGTM!

The whenOpenPartitionTableEditor method is correctly implemented to open the partition table editor for the test.


99-104: LGTM!

The thenEditorIsDisabled method is correctly implemented to validate the partition table editor is disabled for the test.


106-111: Skipping comment as the past review feedback is still applicable.

Please address the exception handling suggestion from the previous review round.

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (1)

273-273: LGTM!

The change refactors the method call to use a more generic launchCommandUsingContextMenu method, which improves code reusability and maintainability. The behavior of the test case remains unchanged.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2acabf6 and c070833.

Files selected for processing (2)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java

Comment on lines +580 to +587
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText)
{
SWTBotShell shell = bot.shell(shellName);
shell.activate();
SWTBotLabel label = bot.label(expectedText);
String actualText = label.getText();
return expectedText.equals(actualText);
}
Copy link

Choose a reason for hiding this comment

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

Looks good! Consider a minor refactoring.

The new checkShellContent method seems to be a useful addition for UI testing. The implementation logic is straightforward and easy to understand.

As a minor improvement, consider extracting the label text comparison logic to a separate private method, something like:

private static boolean isLabelTextMatching(SWTBotLabel label, String expectedText) {
    return expectedText.equals(label.getText());
}

And then use it in checkShellContent:

return isLabelTextMatching(label, expectedText);

This would improve readability and reusability of the text comparison logic.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (2)

581-588: LGTM! Consider adding error handling.

The checkShellContent method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.

As an improvement, consider adding error handling for exceptional cases, such as when the specified shell or label is not found. This will make the method more robust and provide better feedback to the caller.


590-616: LGTM! Consider adding error handling.

The checkPartitionTableContent method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.

As an improvement, consider adding error handling for exceptional cases, such as when the table is not found or has a different structure. This will make the method more robust and provide better feedback to the caller.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 622f45b and 72ca9ac.

Files selected for processing (2)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java
Additional comments not posted (1)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (1)

Line range hint 629-647: LGTM!

The joinJobByName method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.

The method handles the InterruptedException by logging an error message, which is a good practice.

No changes are necessary.

Comment on lines 618 to 628
public static boolean compareRows(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
int defaultRows = 3;
int actualRows = table.rowCount();
if (1 != (actualRows - defaultRows))
{
return false;
}
return true;
}
Copy link

Choose a reason for hiding this comment

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

Fix the incorrect logic.

The logic of the compareRows method seems incorrect. It checks if the actual number of rows is not equal to the default value plus one, which is the opposite of what the method name suggests.

If the actual number of rows is equal to the default value plus one, the method should return true, but it returns false instead.

Please update the logic to match the expected behavior:

public static boolean compareRows(SWTWorkbenchBot bot) throws IOException
{
    SWTBotTable table = bot.table();
    int defaultRows = 3;
    int actualRows = table.rowCount();
    return actualRows == defaultRows + 1;
}

This will ensure that the method returns true when the actual number of rows is equal to the default value plus one, and false otherwise.

@AndriiFilippov AndriiFilippov changed the title WIP: SWTBot test case: Partition Table Editor SWTBot test case: Partition Table Editor Sep 18, 2024
@AndriiFilippov
Copy link
Collaborator Author

please, review @alirana01 @sigmaaa

Tests cover basic functional checks:

  1. Project not built: Verify if a pop-up appears when opening the Partition Table.
  2. Check if the table content corresponds to the documentation.
  3. Add a row to the table.
  4. Delete a row from the table.
  5. Delete a row, Save and Quit, reopen, and verify the changes.
  6. Delete a row, Save, reopen, and verify the changes.

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.

2 participants