Skip to content

feature: add solution on daily 21 KT #268

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

khanh5923
Copy link
Contributor

@khanh5923 khanh5923 commented Jan 5, 2025

Dạ mọi người xem giúp em bài này nhé. Em cảm ơn.

Summary by CodeRabbit

  • New Features

    • Added a new test suite for ticket purchasing functionality
    • Implemented price conversion and verification mechanism for ticket purchases
  • Tests

    • Created comprehensive Playwright test for ticket buying process
    • Added login, ticket selection, and cart verification steps

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Walkthrough

This pull request introduces a new Playwright test suite for a ticket purchasing feature. The test script focuses on simulating a ticket purchase process on a concert ticket website. It includes a convertPrice function to handle price string conversions, implements user login and logout hooks, and performs a comprehensive test that includes navigating to a ticket section, purchasing a ticket, and verifying the cart and pricing details.

Changes

File Change Summary
daily-challenges/2024-10/21/khanh5923_21.spec.ts Added new Playwright test suite for ticket purchasing feature, including convertPrice function and comprehensive test case for ticket purchase workflow

Sequence Diagram

sequenceDiagram
    participant User
    participant Website
    participant LoginPage
    participant TicketSection
    participant Cart

    User->>LoginPage: Navigate and login
    LoginPage-->>Website: Authenticate user
    User->>TicketSection: Select ticket
    User->>TicketSection: Set ticket quantity
    User->>TicketSection: Confirm purchase
    TicketSection-->>Cart: Add ticket to cart
    User->>Cart: Verify cart details
    User->>Website: Navigate back to home page
Loading

Possibly related PRs

Suggested reviewers

  • minhphong306

Poem

🎫 A Rabbit's Ticket Tale 🐰

With Playwright's magic, tests unfurl,
Tickets dance, prices swirl and twirl,
Click by click, the journey's neat,
A digital purchase, oh so sweet!
Code hops along, no bug in sight! 🎉


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

sonarqubecloud bot commented Jan 5, 2025

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a9999d and ee8e442.

📒 Files selected for processing (1)
  • daily-challenges/2024-10/21/khanh5923_21.spec.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
daily-challenges/2024-10/21/khanh5923_21.spec.ts

[error] 4-4: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 28-28: This let declares a variable that is only assigned once.

'miniCart' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 31-31: This let declares a variable that is only assigned once.

'priceProductCart' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 33-33: This let declares a variable that is only assigned once.

'priceProductSection' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

@@ -0,0 +1,36 @@
import { test, expect } from '@playwright/test';
test.describe('khanh5923_20-Buy ticket', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Minor naming mismatch in the test suite.
The describe block is titled 'khanh5923_20-Buy ticket', but the test name is 'khanh5923_21'. To maintain consistency, consider adjusting one of them.

await dialog.accept();
});
await page.click(`//button[@class='btn-confirm']`);
let miniCart = page.locator(`//div[@id="cart-icon"]//span[@id="cart-count"]`);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use const instead of let for variables that are never reassigned.
The variables miniCart, priceProductCart, and priceProductSection remain unchanged after their initial assignments, so const is more appropriate.

-let miniCart = page.locator(`//div[@id="cart-icon"]//span[@id="cart-count"]`);
+const miniCart = page.locator(`//div[@id="cart-icon"]//span[@id="cart-count"]`);

-let priceProductCart = (await page.locator(`//tbody[@id="cart-items"]//td[2]`).textContent()) || '';
+const priceProductCart = (await page.locator(`//tbody[@id="cart-items"]//td[2]`).textContent()) || '';

-let priceProductSection = (await page.locator(`${locatorTicket}::ul//span[@class="price"]`).textContent()) || '';
+const priceProductSection = (await page.locator(`${locatorTicket}::ul//span[@class="price"]`).textContent()) || '';

Also applies to: 31-31, 33-33

🧰 Tools
🪛 Biome (1.9.4)

[error] 28-28: This let declares a variable that is only assigned once.

'miniCart' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +20 to +35
test('khanh5923_21', async ({ page }) => {
const locatorTicket = `//div[@id='ticket-section']//h3[text()='${dataTest.ticketName}']/following-sibling`;
await page.click(`${locatorTicket}::button`);
await page.fill(`//input[@id='ticket-quantity']`, `1`);
page.on('dialog', async dialog => {
await dialog.accept();
});
await page.click(`//button[@class='btn-confirm']`);
let miniCart = page.locator(`//div[@id="cart-icon"]//span[@id="cart-count"]`);
expect(await miniCart.textContent()).toBe(`${dataTest.ticketQuantity}`);
await miniCart.click();
let priceProductCart = (await page.locator(`//tbody[@id="cart-items"]//td[2]`).textContent()) || '';
await page.click(`//button[@id="back-home-btn"]`);
let priceProductSection = (await page.locator(`${locatorTicket}::ul//span[@class="price"]`).textContent()) || '';
expect(convertPrice(priceProductCart)).toBe(convertPrice(priceProductSection));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding additional negative and edge-case coverage.
No negative flows are tested, such as a failed login, invalid ticket quantity, or unavailability of the ticket. Strengthening test coverage would improve confidence in the feature.

🧰 Tools
🪛 Biome (1.9.4)

[error] 28-28: This let declares a variable that is only assigned once.

'miniCart' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 31-31: This let declares a variable that is only assigned once.

'priceProductCart' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 33-33: This let declares a variable that is only assigned once.

'priceProductSection' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

Comment on lines +3 to +4
function convertPrice(price: string) {
return parseInt(price.replace(/\D/g, ''));
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Prefer Number.parseInt over the global parseInt.
As recommended by static analysis, using Number.parseInt enhances consistency and clarity.

-function convertPrice(price: string) {
-    return parseInt(price.replace(/\D/g, ''));
+function convertPrice(price: string) {
+    return Number.parseInt(price.replace(/\D/g, ''), 10);
}
📝 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
function convertPrice(price: string) {
return parseInt(price.replace(/\D/g, ''));
function convertPrice(price: string) {
return Number.parseInt(price.replace(/\D/g, ''), 10);
🧰 Tools
🪛 Biome (1.9.4)

[error] 4-4: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

test('khanh5923_21', async ({ page }) => {
const locatorTicket = `//div[@id='ticket-section']//h3[text()='${dataTest.ticketName}']/following-sibling`;
await page.click(`${locatorTicket}::button`);
await page.fill(`//input[@id='ticket-quantity']`, `1`);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use the dataTest.ticketQuantity for consistency.
Currently, the code uses 1 directly instead of referencing dataTest.ticketQuantity. This can cause inconsistencies if the quantity requirement changes.

-await page.fill(`//input[@id='ticket-quantity']`, `1`);
+await page.fill(`//input[@id='ticket-quantity']`, `${dataTest.ticketQuantity}`);

Committable suggestion skipped: line range outside the PR's diff.

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.

1 participant