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

Development: Fix course messages e2e tests #9720

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Nov 9, 2024

Checklist

General

Motivation and Context

Some of the tests in CourseMessages.spec.ts were failing after the changes in message design. The tests could not identify the relocated button for delete/edit messages.

Description

deleteMessage() and editMessage() functions have been updated so that tests can identify these buttons again.

Steps for Testing

Check that the test runs through correctly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • New Features

    • Enhanced conditional rendering for UI elements in the post component, improving user experience based on various states.
    • Updated dropdown menu for editing and deleting messages to utilize a context menu approach for more intuitive interactions.
  • Bug Fixes

    • Improved styling for edit and delete buttons in the dropdown menu.
  • Refactor

    • Revised methods for editing and deleting messages to streamline interactions.

@asliayk asliayk self-assigned this Nov 9, 2024
@asliayk asliayk requested a review from a team as a code owner November 9, 2024 15:07
@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) playwright labels Nov 9, 2024
Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the HTML template of the post.component.html and the CourseMessagesPage.ts class. The HTML template enhancements focus on conditional rendering of UI elements based on various component states. In CourseMessagesPage.ts, the methods for editing and deleting messages have been updated to utilize a context menu approach, improving user interactions.

Changes

File Path Change Summary
src/main/webapp/app/shared/metis/post/post.component.html Enhanced conditional rendering for UI elements based on component states, including post title, message container, and footer. Updated dropdown menu for edit and delete actions with new CSS classes.
src/test/playwright/support/pageobjects/course/CourseMessagesPage.ts Modified editMessage and deleteMessage methods to use right-click actions for displaying dropdown menus for editing and deleting messages.

Possibly related PRs

Suggested labels

tests, ready for review, bugfix, playwright, component:Communication

Suggested reviewers

  • krusche
  • florian-glombik
  • rabeatwork
  • edkaya

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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (4)
src/main/webapp/app/shared/metis/post/post.component.html (1)

152-159: LGTM! The added CSS classes improve test stability.

The addition of editIcon and deleteIcon classes provides reliable selectors for e2e tests, addressing the issue of tests failing to locate these buttons after UI changes.

Consider adding data-testid attributes for even more stable test selectors:

-        <button class="dropdown-item d-flex editIcon" (click)="editPosting()">
+        <button class="dropdown-item d-flex editIcon" data-testid="edit-message-btn" (click)="editPosting()">
-        <button class="dropdown-item d-flex deleteIcon" (click)="deletePost()">
+        <button class="dropdown-item d-flex deleteIcon" data-testid="delete-message-btn" (click)="deletePost()">
src/test/playwright/support/pageobjects/course/CourseMessagesPage.ts (3)

245-253: LGTM with suggestion for error handling.

The implementation correctly adapts to the new UI design with context menu and provides a good fallback mechanism. However, consider adding error handling for cases where neither the context menu nor the fallback button is available.

Consider adding error handling:

 const editButton = postLocator.locator('.dropdown-menu.show .editIcon');
 if (await editButton.isVisible()) {
     await editButton.click();
 } else {
-    await postLocator.locator('.reaction-button.edit').click();
+    const fallbackButton = postLocator.locator('.reaction-button.edit');
+    if (await fallbackButton.isVisible()) {
+        await fallbackButton.click();
+    } else {
+        throw new Error('Neither context menu edit button nor fallback edit button is visible');
+    }
 }

267-276: LGTM with suggestion for error handling.

The implementation maintains consistency with the editMessage() method and correctly adapts to the UI changes. Consider adding similar error handling here as well.

Consider adding error handling:

 const deleteButton = postLocator.locator('.dropdown-menu.show .deleteIcon');
 if (await deleteButton.isVisible()) {
     await deleteButton.click();
 } else {
-    await postLocator.locator('.reaction-button.delete').click();
+    const fallbackButton = postLocator.locator('.reaction-button.delete');
+    if (await fallbackButton.isVisible()) {
+        await fallbackButton.click();
+    } else {
+        throw new Error('Neither context menu delete button nor fallback delete button is visible');
+    }
 }

Line range hint 245-276: Consider extracting common context menu interaction logic.

Both editMessage() and deleteMessage() share similar context menu interaction patterns. Consider extracting this logic into a reusable helper method to improve maintainability and reduce code duplication.

Example implementation:

private async clickContextMenuOption(
    container: Locator,
    menuOptionSelector: string,
    fallbackButtonSelector: string,
    actionName: string
): Promise<void> {
    await container.locator('.message-container').click({ button: 'right' });
    await this.page.waitForSelector('.dropdown-menu.show');

    const menuButton = container.locator(`.dropdown-menu.show ${menuOptionSelector}`);
    if (await menuButton.isVisible()) {
        await menuButton.click();
    } else {
        const fallbackButton = container.locator(fallbackButtonSelector);
        if (await fallbackButton.isVisible()) {
            await fallbackButton.click();
        } else {
            throw new Error(`Neither context menu ${actionName} button nor fallback ${actionName} button is visible`);
        }
    }
}

Usage in the methods:

// In editMessage()
await this.clickContextMenuOption(postLocator, '.editIcon', '.reaction-button.edit', 'edit');

// In deleteMessage()
await this.clickContextMenuOption(postLocator, '.deleteIcon', '.reaction-button.delete', 'delete');
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c9f0c0d and 32555ab.

📒 Files selected for processing (2)
  • src/main/webapp/app/shared/metis/post/post.component.html (1 hunks)
  • src/test/playwright/support/pageobjects/course/CourseMessagesPage.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/shared/metis/post/post.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

🔇 Additional comments (1)
src/main/webapp/app/shared/metis/post/post.component.html (1)

Line range hint 1-179: Template follows Angular syntax guidelines.

The template correctly uses the new @if syntax throughout, adhering to the coding guidelines that specify using @if over *ngIf.

@krusche krusche added this to the 7.7.0 milestone Nov 9, 2024
@krusche krusche merged commit 64f95cd into develop Nov 9, 2024
25 of 28 checks passed
@krusche krusche deleted the bugfix/fix-broken-messages-e2e-tests branch November 9, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) playwright tests
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

2 participants