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

test(web): publish and unpublish items from table #1312

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

caichi-t
Copy link
Contributor

@caichi-t caichi-t commented Nov 18, 2024

Overview

This PR adds the test for publishing and unpublishing items from table.

Summary by CodeRabbit

  • Tests
    • Renamed test case for better clarity on publishing/unpublishing from the edit page.
    • Added a new test case for publishing/unpublishing items from the table view, enhancing test coverage.

@caichi-t caichi-t requested a review from nourbalaha as a code owner November 18, 2024 07:55
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the test cases in content.spec.ts. A test case was renamed to better reflect its focus on actions from the edit page, while original steps were removed to streamline the process. New assertions for checking item statuses after publishing and unpublishing were added. Additionally, a new test case was introduced to verify similar actions from a table view, enhancing the overall test coverage for item publishing and unpublishing functionalities.

Changes

File Change Summary
web/e2e/project/content/content.spec.ts - Renamed test case: "Publishing and Unpublishing item has succeeded" to "Publishing and Unpublishing item from edit page has succeeded".
- Removed original steps for changing item settings.
- Added new assertions for "DRAFT" and "PUBLIC" statuses.
- Introduced new test case: "Publishing and Unpublishing item from table has succeeded" with similar assertions.

Possibly related PRs

Suggested reviewers

  • nourbalaha

Poem

In the land of code where rabbits play,
Tests were changed in a bright new way.
From edit pages to tables wide,
Publishing joy, we take in stride!
With statuses clear, our hops are light,
Testing the features, all feels just right! 🐰✨


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

netlify bot commented Nov 18, 2024

Deploy Preview for reearth-cms ready!

Name Link
🔨 Latest commit 9cf8be9
🔍 Latest deploy log https://app.netlify.com/sites/reearth-cms/deploys/673b18661ed93d0008a7a990
😎 Deploy Preview https://deploy-preview-1312--reearth-cms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the web label Nov 18, 2024
Copy link
Contributor

@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 (3)
web/e2e/project/content/content.spec.ts (3)

51-74: LGTM! Consider extracting status verification helper.

The test case is well-structured with clear steps and appropriate assertions. The renaming improves clarity about the test's scope.

Consider extracting the status verification into a helper function to reduce duplication:

async function verifyItemStatus(page: Page, expectedStatus: "DRAFT" | "PUBLIC") {
  await expect(page.getByText(expectedStatus)).toBeVisible();
}

This would make the test more maintainable and reduce the repetitive status checks at lines 60, 63-64, 67, 71-73.


76-98: LGTM! Consider additional test scenarios.

The test case effectively covers the basic flow for publishing/unpublishing from table view.

Consider adding these valuable test scenarios:

  1. Publishing/unpublishing multiple selected items
  2. Error cases (e.g., network failure during publish)
  3. Canceling the confirmation dialog

Example for multiple items:

// Select multiple items
await page.getByLabel("", { exact: true }).first().check();
await page.getByLabel("", { exact: true }).nth(1).check();
await page.getByText("Publish", { exact: true }).click();
await page.getByRole("button", { name: "Yes" }).click();
// Verify both items are published
await expect(page.getByText("PUBLIC")).toHaveCount(2);

51-98: Consider improving test organization and coverage.

The test implementation is solid but could benefit from some architectural improvements:

  1. Create a dedicated test fixture for content-related operations to reduce setup duplication
  2. Consider grouping these publishing-related tests in a describe block
  3. Add test coverage for edge cases and error scenarios

Example test organization:

test.describe('Content Publishing', () => {
  test.beforeEach(async ({ page }) => {
    // Setup content item
  });

  test('from edit page...', async ({ page }) => {
    // Existing test
  });

  test('from table...', async ({ page }) => {
    // Existing test
  });

  test('handles errors...', async ({ page }) => {
    // New error cases
  });
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2836d3f and 5435393.

📒 Files selected for processing (1)
  • web/e2e/project/content/content.spec.ts (1 hunks)

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (3)
web/e2e/project/content/content.spec.ts (3)

51-74: Consider adding negative test cases

The test only covers the happy path. Consider adding test cases for:

  • Attempting to unpublish an already unpublished item
  • Attempting to publish an already published item

51-98: Extract common setup into helper functions

Both test cases share similar setup code. Consider extracting common operations into helper functions:

async function createTestItem(page: Page, text: string = "text") {
  await page.getByRole("button", { name: "plus New Item" }).click();
  await page.getByLabel("text").fill(text);
  await page.getByRole("button", { name: "Save" }).click();
  await closeNotification(page);
  await expect(page.getByText("DRAFT")).toBeVisible({ timeout: 5000 });
}

async function verifyItemStatus(page: Page, status: "DRAFT" | "PUBLIC") {
  await expect(page.getByText(status)).toBeVisible({ timeout: 5000 });
}

This would make the tests more maintainable and reduce code duplication.


51-98: Consider implementing a Page Object Model pattern

The test file would benefit from implementing the Page Object Model (POM) pattern to:

  • Encapsulate page-specific selectors and actions
  • Improve test maintainability
  • Make tests more readable and robust

Example structure:

// contentPage.ts
class ContentPage {
  constructor(private page: Page) {}

  async createItem(text: string) {
    // Implementation
  }

  async publishItem(itemIndex: number) {
    // Implementation
  }

  async unpublishItem(itemIndex: number) {
    // Implementation
  }

  async verifyItemStatus(itemIndex: number, status: "DRAFT" | "PUBLIC") {
    // Implementation
  }
}

// content.spec.ts
test("Publishing from table", async ({ page }) => {
  const contentPage = new ContentPage(page);
  await contentPage.createItem("test");
  await contentPage.publishItem(0);
  await contentPage.verifyItemStatus(0, "PUBLIC");
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2836d3f and 5435393.

📒 Files selected for processing (1)
  • web/e2e/project/content/content.spec.ts (1 hunks)

web/e2e/project/content/content.spec.ts Show resolved Hide resolved
web/e2e/project/content/content.spec.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants