elimu-ai / webapp

🖥 Web application for hosting Android applications and educational content
https://hin.elimu.ai
MIT License
31 stars 57 forks source link

test(selenium): word learning events #1856

Closed jo-elimu closed 2 months ago

jo-elimu commented 2 months ago

Add UI tests.

411

Technical Details

Testing Instructions

Screenshots


Format Checks

[!NOTE] Files in PRs are automatically checked for format violations with mvn spotless:check.

If this PR contains files with format violations, run mvn spotless:apply to fix them.

coderabbitai[bot] commented 2 months ago

Walkthrough

The code changes involve minor modifications in comments, updates to HTML structure, enhancements to data visualization capabilities, and restructuring of import statements across several Java files. Key updates include the addition of logic for aggregating word learning events data, improvements to the usability of various web pages, and a reorganization of utility classes into a dedicated sub-package.

Changes

Files Change Summary
src/main/java/.../StoryBookLearningEventListController.java Updated comment for clarity.
src/main/java/.../WordLearningEventListController.java Added logic to aggregate word learning events by month for a chart.
src/main/webapp/WEB-INF/jsp/.../main.jsp Added id attribute to an anchor element for better accessibility.
src/main/webapp/WEB-INF/jsp/.../storybook-learning-event/list.jsp Modified table headers to include <code> tags for semantic clarity.
src/main/webapp/WEB-INF/jsp/.../word-learning-event/list.jsp Updated charting library source and improved chart and table structure and data handling.
src/test/java/.../EmojisRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../ImagesRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../LetterSoundsRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../LettersRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../SoundsRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../StoryBooksRestControllerTest.java Changed import path for DomainHelper.
src/test/java/.../WordsRestControllerTest.java Changed import path for DomainHelper.
src/test/java/selenium/.../WelcomePage.java Changed package and import paths for better organization.
src/test/java/selenium/.../WelcomePageTest.java Changed package and import paths; updated comment on test command properties.
src/test/java/selenium/analytics/.../MainAnalyticsPage.java New class for interacting with the main analytics page using Selenium.
src/test/java/selenium/analytics/.../MainAnalyticsPageTest.java New test class for MainAnalyticsPage, structured with JUnit 5.
src/test/java/selenium/analytics/.../WordLearningEventsPage.java New class for interacting with the Word Learning Events page.
src/test/java/selenium/analytics/.../WordLearningEventsPageTest.java New test class for WordLearningEventsPage, structured with JUnit 5.
src/test/java/selenium/util/.../DomainHelper.java Changed package to selenium.util for better organization.
src/test/java/selenium/util/.../ErrorHelper.java Changed package to selenium.util.
src/test/java/selenium/util/.../ErrorPage.java Changed package to selenium.util.
src/test/java/selenium/util/.../JavaScriptHelper.java Changed package to selenium.util.
src/test/java/selenium/util/.../MarkupValidationHelper.java Changed package to selenium.util.
src/test/java/selenium/util/.../SignOnHelper.java Changed package to selenium.util.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebApp
    participant ChartService
    participant Database

    User->>WebApp: Requests Word Learning Events
    WebApp->>Database: Fetch Word Learning Events
    Database-->>WebApp: Return Events Data
    WebApp->>ChartService: Prepare Data for Chart
    ChartService-->>WebApp: Return Chart Data
    WebApp-->>User: Display Chart with Events Data

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 1e5443eff195094767052e450e798cff6d69885b and 28ba3804961b63cfa1b22361dffd89863383eaed.
Files selected for processing (24) * src/main/java/ai/elimu/web/analytics/StoryBookLearningEventListController.java (1 hunks) * src/main/java/ai/elimu/web/analytics/WordLearningEventListController.java (2 hunks) * src/main/webapp/WEB-INF/jsp/analytics/main.jsp (1 hunks) * src/main/webapp/WEB-INF/jsp/analytics/storybook-learning-event/list.jsp (1 hunks) * src/main/webapp/WEB-INF/jsp/analytics/word-learning-event/list.jsp (2 hunks) * src/test/java/ai/elimu/rest/v2/content/EmojisRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/ImagesRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/LetterSoundsRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/LettersRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/SoundsRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/StoryBooksRestControllerTest.java (1 hunks) * src/test/java/ai/elimu/rest/v2/content/WordsRestControllerTest.java (1 hunks) * src/test/java/selenium/WelcomePage.java (1 hunks) * src/test/java/selenium/WelcomePageTest.java (3 hunks) * src/test/java/selenium/analytics/MainAnalyticsPage.java (1 hunks) * src/test/java/selenium/analytics/MainAnalyticsPageTest.java (1 hunks) * src/test/java/selenium/analytics/WordLearningEventsPage.java (1 hunks) * src/test/java/selenium/analytics/WordLearningEventsPageTest.java (1 hunks) * src/test/java/selenium/util/DomainHelper.java (1 hunks) * src/test/java/selenium/util/ErrorHelper.java (1 hunks) * src/test/java/selenium/util/ErrorPage.java (1 hunks) * src/test/java/selenium/util/JavaScriptHelper.java (1 hunks) * src/test/java/selenium/util/MarkupValidationHelper.java (2 hunks) * src/test/java/selenium/util/SignOnHelper.java (1 hunks)
Files skipped from review due to trivial changes (17) * src/main/java/ai/elimu/web/analytics/StoryBookLearningEventListController.java * src/main/webapp/WEB-INF/jsp/analytics/main.jsp * src/main/webapp/WEB-INF/jsp/analytics/storybook-learning-event/list.jsp * src/test/java/ai/elimu/rest/v2/content/EmojisRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/ImagesRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/LetterSoundsRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/LettersRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/SoundsRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/StoryBooksRestControllerTest.java * src/test/java/ai/elimu/rest/v2/content/WordsRestControllerTest.java * src/test/java/selenium/WelcomePage.java * src/test/java/selenium/util/DomainHelper.java * src/test/java/selenium/util/ErrorHelper.java * src/test/java/selenium/util/ErrorPage.java * src/test/java/selenium/util/JavaScriptHelper.java * src/test/java/selenium/util/MarkupValidationHelper.java * src/test/java/selenium/util/SignOnHelper.java
Additional comments not posted (9)
src/test/java/selenium/analytics/WordLearningEventsPage.java (1)
`8-18`: **Well-structured Selenium page object model.** The class `WordLearningEventsPage` follows good practices for Selenium testing, including the use of utility classes to handle errors. The constructor's direct interaction with the WebDriver is appropriate for setting up page-specific configurations. Consider adding more detailed documentation to describe the interactions and the purpose of this page object within the test suite.
src/test/java/selenium/analytics/MainAnalyticsPage.java (1)
`9-24`: **Well-implemented Selenium page interactions.** The `MainAnalyticsPage` class correctly encapsulates interactions with web elements, following Selenium best practices. The method `pressWordLearningEventsLink` is well-implemented for interacting with specific elements on the page. Consider adding error handling or retry mechanisms in the `pressWordLearningEventsLink` method to handle scenarios where the element is not immediately clickable.
src/test/java/selenium/WelcomePageTest.java (1)
Line range hint `1-12`: **Good restructuring and test setup implementation.** The changes to the package declaration and import statements enhance clarity and maintainability. The setup method's handling of headless mode and other Chrome options is well-implemented and follows best practices for Selenium testing. Ensure that the new package structure and the reorganized utility classes are consistently used across all test files to maintain uniformity in the codebase. Also applies to: 27-27
src/test/java/selenium/analytics/MainAnalyticsPageTest.java (1)
`14-52`: **Review of MainAnalyticsPageTest class setup and methods** - **Class Setup**: The logger and WebDriver are initialized correctly. The class structure follows good practices for Selenium tests. - **setUp Method**: Properly configures the WebDriver with options, including a headless mode based on system properties. It also navigates to the correct URL. - **tearDown Method**: Appropriately quits the WebDriver, ensuring no resources are left hanging post-tests. - **testMainAnalyticsPage Method**: Currently, this method only logs an action and initializes a page object but does not perform any assertions or interactions. It's important to implement actual test steps here to validate the functionality of the MainAnalyticsPage.
src/test/java/selenium/analytics/WordLearningEventsPageTest.java (1)
`15-56`: **Review of WordLearningEventsPageTest class setup and methods** - **Class Setup**: Consistent setup with logger and WebDriver, following good testing practices. - **setUp Method**: Correctly sets up the WebDriver with options and navigates to the analytics URL. - **tearDown Method**: Properly handles the quitting of the WebDriver. - **testWordLearningEventsPage Method**: Initializes necessary page objects but lacks actual interactions and assertions. It's crucial to add steps that interact with the UI and verify the expected outcomes to ensure the word learning events page is functioning as intended.
src/main/webapp/WEB-INF/jsp/analytics/word-learning-event/list.jsp (4)
`8-8`: **Approved script source update. Consider adding a local fallback.** Updating to a CDN-hosted version of Chart.js is beneficial for performance and access to new features. However, consider adding a local fallback script in case the CDN is unavailable. --- `9-9`: **Canvas ID update is consistent with JavaScript changes.** The ID update from `myChart` to `chart` is correctly reflected in the JavaScript code initializing the chart. --- `52-57`: **Table header updates enhance clarity and consistency.** The update to more descriptive, code-like identifiers for table headers is a good practice, improving clarity and potentially easing integration with front-end frameworks. --- `12-22`: **Dynamic data handling in JavaScript. Verify data sanitization.** The use of JSP tags to dynamically populate JavaScript arrays is effective. Ensure that data passed to JavaScript is properly sanitized to prevent XSS attacks.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 show all the console.log statements in this repository.` - `@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 as 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. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Project coverage is 15.06%. Comparing base (1e5443e) to head (28ba380). Report is 2 commits behind head on main.

Files Patch % Lines
...web/analytics/WordLearningEventListController.java 0.00% 21 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1856 +/- ## ============================================ - Coverage 15.10% 15.06% -0.05% Complexity 456 456 ============================================ Files 250 250 Lines 7700 7721 +21 Branches 804 807 +3 ============================================ Hits 1163 1163 - Misses 6487 6508 +21 Partials 50 50 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.