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.
    • Updated methods for installing new components and refreshing projects to streamline command execution through a unified approach.
    • 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, and multiple test methods for different scenarios.
tests/com.espressif.idf.ui.test/.../NewEspressifIDFProjectTest.java Updated methods whenInstallNewComponentUsingContextMenu and whenRefreshProject to use a unified command execution method for context menu actions.
tests/com.espressif.idf.ui.test/.../ProjectTestOperations.java Removed the method openProjectNewComponentUsingContextMenu, added methods checkShellContent, checkPartitionTableContent, comparePartitionTableRows, and deletePartitionTableRow for enhanced UI verification and partition management.

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.


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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 +46
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 +226
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

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 632
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.

Copy link
Collaborator

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

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

@AndriiFilippov LGTM can you please verify the builds they are failing on linux

edit:Seems like failures are not your tests

@AndriiFilippov
Copy link
Collaborator Author

@AndriiFilippov LGTM can you please verify the builds they are failing on linux

edit:Seems like failures are not your tests

So, could merge ?

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: 6

🧹 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)

156-161: Consider combining build operations into a single utility method

The method whenProjectIsBuiltUsingContextMenu performs multiple steps to build the project. To improve code reusability and readability, consider combining these steps into a single utility method within ProjectTestOperations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 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 (2 hunks)
🔇 Additional comments (7)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (2)

Line range hint 273-279: Improved code reusability with generic command launch method

The change to use ProjectTestOperations.launchCommandUsingContextMenu is a good improvement. It enhances code reusability and flexibility by using a generic method to launch context menu commands. This approach can be easily extended to other commands in the future.


Line range hint 282-284: Consistent use of generic command launch method for project refresh

This change aligns well with the previous modification, using ProjectTestOperations.launchCommandUsingContextMenu for the refresh operation. It maintains consistency in how context menu commands are executed across different operations, which is a good practice for code maintainability.

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (3)

221-226: Exception handling in cleanTestEnv method

As previously mentioned in past review comments, the cleanTestEnv method does not handle potential exceptions. Incorporating exception handling ensures that cleanup processes are executed properly even if errors occur.


42-46: Exception handling in afterEachTest method

As previously mentioned in past review comments, the afterEachTest method calls Fixture.cleanTestEnv() without exception handling. Ensure that exceptions are caught and managed to prevent tests from failing silently.


31-34: ⚠️ Potential issue

Adjust method naming conventions in the Fixture inner class

In Java, method names should follow the camelCase convention starting with a lowercase letter. The methods within the Fixture class begin with uppercase letters (e.g., ThenInformationMessagePopUp()), which is inconsistent with Java naming conventions. Please rename these methods to improve code readability and maintainability.

Apply this diff to rename the methods:

- private static void ThenInformationMessagePopUp() throws IOException
+ private static void thenInformationMessagePopUp() throws IOException

- private static void ThenBuiltInPartitionTableDisplayed() throws IOException
+ private static void thenBuiltInPartitionTableDisplayed() throws IOException

- private static void ThenCheckRowAdded() throws IOException
+ private static void thenCheckRowAdded() throws IOException

- private static void ThenCheckRowDeleted() throws IOException
+ private static void thenCheckRowDeleted() throws IOException

- private static void ThenCheckChangesSaved() throws IOException
+ private static void thenCheckChangesSaved() throws IOException

Likely invalid or redundant comment.

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (2)

27-30: LGTM on the added imports

The new imports for SWTBotLabel and SWTBotTable are appropriate for the added functionalities.


618-624: LGTM on comparePartitionTableRows method

The method comparePartitionTableRows correctly calculates the difference in row count and compares it to the expected difference.

Comment on lines +48 to +124
@Test
public void givenNewProjectCreatedNotBuiltWhenOpenPartitionTableEditorThenInformationPopUpMessage() throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor1Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenOpenPartitionTableEditor();
Fixture.ThenInformationMessagePopUp();
}

@Test
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorThenBuiltInPartitionTableDisplayed()
throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor2Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenOpenPartitionTableEditor();
Fixture.ThenBuiltInPartitionTableDisplayed();
}

@Test
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenAddRowThenCheckRowAdded() throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor3Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenOpenPartitionTableEditor();
Fixture.whenAddRowToPartitionTable();
Fixture.ThenCheckRowAdded();
}

@Test
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowThenCheckRowDeleted()
throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor4Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenOpenPartitionTableEditor();
Fixture.whenDeleteRowFromPartitionTable();
Fixture.ThenCheckRowDeleted();
}

@Test
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndQuitwhenReopenPartitionTableThenCheckChangesSaved()
throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor5Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenOpenPartitionTableEditor();
Fixture.whenDeleteRowFromPartitionTable();
Fixture.whenSaveAndQuit();
Fixture.whenOpenPartitionTableEditor();
Fixture.thenCheckChangesSaved();
}

@Test
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndCancelwhenReopenPartitionTableThenCheckChangesSaved()
throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor6Test");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenOpenPartitionTableEditor();
Fixture.whenDeleteRowFromPartitionTable();
Fixture.whenSavePartitionTable();
Fixture.whenCancel();
Fixture.whenOpenPartitionTableEditor();
Fixture.thenCheckChangesSaved();
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Place assertions directly within test methods for clarity

While using the Fixture class helps to organize code, placing assertions directly within the test methods enhances test clarity and makes it easier to understand the test flow. Consider refactoring the tests to include assertions in the test methods.

Comment on lines +133 to +138
private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
bot.sleep(1000);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid using fixed delays like bot.sleep(1000);

Using fixed delays can lead to flaky tests due to variable execution times. Instead, use explicit wait conditions provided by SWTBot to wait for specific UI elements or operations to complete.

Apply this diff to replace bot.sleep(1000); with a proper wait condition:

 private static void loadEnv() throws Exception
 {
     bot = WorkBenchSWTBot.getBot();
     EnvSetupOperations.setupEspressifEnv(bot);
-    bot.sleep(1000);
+    TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
bot.sleep(1000);
}
private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
}

Comment on lines +163 to +166
private static void whenOpenPartitionTableEditor() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential exceptions when opening the Partition Table Editor

The method whenOpenPartitionTableEditor can throw IOException, but exceptions are not being handled within the method. Consider adding exception handling to ensure that any issues are caught and logged appropriately.

Apply this diff to add exception handling:

 private static void whenOpenPartitionTableEditor()
 {
-    ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
+    try {
+        ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
+    } catch (IOException e) {
+        // Log the exception and handle it accordingly
+        e.printStackTrace();
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static void whenOpenPartitionTableEditor() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
}
private static void whenOpenPartitionTableEditor()
{
try {
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
} catch (IOException e) {
// Log the exception and handle it accordingly
e.printStackTrace();
}
}

Comment on lines +626 to +632
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
table.select(1);
bot.toolbarButton("Delete Selected").click();
bot.button("OK").click();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation in deletePartitionTableRow

To prevent potential exceptions, consider adding a check to ensure that the table has at least two rows before attempting to select and delete a row at index 1.

Apply this diff to add validation:

 public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException
 {
     SWTBotTable table = bot.table();
+    if (table.rowCount() > 1) {
         table.select(1);
         bot.toolbarButton("Delete Selected").click();
         bot.button("OK").click();
+    } else {
+        // Handle the case where there are not enough rows to delete
+        throw new IllegalStateException("Unable to delete row: Table does not have enough rows.");
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
table.select(1);
bot.toolbarButton("Delete Selected").click();
bot.button("OK").click();
}
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
if (table.rowCount() > 1) {
table.select(1);
bot.toolbarButton("Delete Selected").click();
bot.button("OK").click();
} else {
// Handle the case where there are not enough rows to delete
throw new IllegalStateException("Unable to delete row: Table does not have enough rows.");
}
}

Comment on lines +581 to +588
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.

⚠️ Potential issue

Handle potential exceptions in checkShellContent

The method checkShellContent may throw a WidgetNotFoundException if the shell or label with the expected text is not found. To enhance robustness, consider catching this exception and returning false when the shell or label is not found.

Apply this diff to handle exceptions:

 public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText)
 {
     try {
         SWTBotShell shell = bot.shell(shellName);
         shell.activate();
         SWTBotLabel label = bot.label(expectedText);
         String actualText = label.getText();
         return expectedText.equals(actualText);
     } catch (WidgetNotFoundException e) {
         return false;
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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);
}
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText)
{
try {
SWTBotShell shell = bot.shell(shellName);
shell.activate();
SWTBotLabel label = bot.label(expectedText);
String actualText = label.getText();
return expectedText.equals(actualText);
} catch (WidgetNotFoundException e) {
return false;
}
}

Comment on lines +590 to +616
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot)
{
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory",
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" };
int builtInIndex = 0;
SWTBotTable table = bot.table();
int columns = table.columnCount();
int rows = table.rowCount();
if (columns != 6 && rows != 3)
{
return false;
}
for (int col = 0; col < columns; col++)
{
for (int row = 0; row < rows; row++)
{
String tableContent = table.cell(row, col);

if (!builtInPartitionArray[builtInIndex].equals(tableContent))
{
return false;
}
builtInIndex++;
}
}
return true;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the condition and loop order in checkPartitionTableContent

  1. Incorrect logical operator in the condition

    The condition if (columns != 6 && rows != 3) should use the logical OR operator || to correctly validate the table dimensions. Using && means the return false statement will not execute if either columns equals 6 or rows equals 3.

  2. Swap the loop order for proper traversal

    The nested loops should iterate over rows first and then columns to access table cells in row-major order, matching the structure of builtInPartitionArray.

Apply this diff to correct the issues:

 public static boolean checkPartitionTableContent(SWTWorkbenchBot bot)
 {
     String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory",
             "0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" };
     int builtInIndex = 0;
     SWTBotTable table = bot.table();
     int columns = table.columnCount();
     int rows = table.rowCount();
-    if (columns != 6 && rows != 3)
+    if (columns != 6 || rows != 3)
     {
         return false;
     }
-    for (int col = 0; col < columns; col++)
+    for (int row = 0; row < rows; row++)
     {
-        for (int row = 0; row < rows; row++)
+        for (int col = 0; col < columns; col++)
         {
             String tableContent = table.cell(row, col);

             if (!builtInPartitionArray[builtInIndex].equals(tableContent))
             {
                 return false;
             }
             builtInIndex++;
         }
     }
     return true;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot)
{
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory",
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" };
int builtInIndex = 0;
SWTBotTable table = bot.table();
int columns = table.columnCount();
int rows = table.rowCount();
if (columns != 6 && rows != 3)
{
return false;
}
for (int col = 0; col < columns; col++)
{
for (int row = 0; row < rows; row++)
{
String tableContent = table.cell(row, col);
if (!builtInPartitionArray[builtInIndex].equals(tableContent))
{
return false;
}
builtInIndex++;
}
}
return true;
}
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot)
{
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory",
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" };
int builtInIndex = 0;
SWTBotTable table = bot.table();
int columns = table.columnCount();
int rows = table.rowCount();
if (columns != 6 || rows != 3)
{
return false;
}
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < columns; col++)
{
String tableContent = table.cell(row, col);
if (!builtInPartitionArray[builtInIndex].equals(tableContent))
{
return false;
}
builtInIndex++;
}
}
return true;
}

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