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

fix(j-s): E2E Tests #16133

Merged
merged 2 commits into from
Sep 24, 2024
Merged

fix(j-s): E2E Tests #16133

merged 2 commits into from
Sep 24, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Sep 24, 2024

E2E Tests

Update e2e tests

What

  • Updates e2e tests to handle new input components for national id and name.

Why

  • To get e2e test running again.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features
    • Simplified logic for step validity in the Hearing Arrangements component.
  • Bug Fixes
    • Updated input field names in tests for custody, indictment, and search warrant functionalities to enhance accuracy and reliability.

@gudjong gudjong requested review from a team as code owners September 24, 2024 11:25
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes involve modifications to the logic and selectors used in various components and test files within the judicial system application. Specifically, the validity assessment for the HearingArrangements component has been simplified, and several input field names in the test cases have been updated to reflect new naming conventions. These adjustments aim to streamline the code and ensure consistency across the application.

Changes

File Change Summary
apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/HearingArrangements/HearingArrangements.tsx Modified the validity logic for the HearingArrangements component by removing the isTransitioningCase condition, making it solely dependent on isHearingArrangementsStepValidRC(workingCase).
apps/system-e2e/src/tests/judicial-system/regression/custody-tests.spec.ts Updated the input field name from accusedName to inputName in the custody tests, affecting how the test script interacts with the form.
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts Changed input selectors from nationalId to inputNationalId and from accusedName to inputName. Introduced a new Promise.all block for button interactions.
apps/system-e2e/src/tests/judicial-system/regression/search-warrant-tests.spec.ts Renamed the input field selector for the accused's name from accusedName to inputName, reflecting a change in the HTML structure or naming conventions.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • unakb

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.

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
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 (5)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (2)

42-45: LGTM! Consider adding comments for clarity.

The updates to the selectors for national ID and name input fields are appropriate and align with the PR objectives. These changes make the tests more specific and robust.

Consider adding a brief comment explaining the reason for these selector changes, e.g.:

// Updated selectors to match new input component IDs
await page.getByTestId('inputNationalId').click()
await page.getByTestId('inputNationalId').fill('01.01.2000')
await page.getByTestId('inputName').click()
await page.getByTestId('inputName').fill(accusedName)

81-84: Good addition. Consider adding a comment for context.

The new Promise.all block effectively handles the concurrent operations of clicking the 'Nei' button and verifying the case update request. This addition improves the test's robustness.

To enhance readability, consider adding a brief comment explaining the purpose of this block, e.g.:

// Handle 'No' response and verify case update
await Promise.all([
  page.getByText('Nei').last().click(),
  verifyRequestCompletion(page, '/api/graphql', 'UpdateCase'),
])
apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/HearingArrangements/HearingArrangements.tsx (1)

Line range hint 1-238: Consider component decomposition for improved maintainability.

The HearingArrangements component demonstrates good practices:

  • Proper use of React hooks and context
  • Effective use of TypeScript for type safety
  • Appropriate use of Next.js useRouter hook

However, the component is quite large and handles multiple responsibilities. To improve maintainability and adhere to the Single Responsibility Principle, consider the following refactoring suggestions:

  1. Extract the modal logic and state into a separate component.
  2. Create a custom hook for case-related operations (e.g., useCaseOperations) to encapsulate the logic currently in the useCase hook.
  3. Consider breaking down the form sections into smaller, reusable components.

These changes would make the code more modular and easier to test and maintain.

Here's a high-level example of how you might start refactoring:

// Extract modal to a separate component
const NotificationModal = ({ isOpen, onClose, onSend, onContinue, workingCase, isSending, error }) => {
  // Modal JSX here
}

// Extract case operations to a custom hook
const useCaseOperations = () => {
  // Case-related operations here
}

// Main component
export const HearingArrangements = () => {
  const { workingCase, setWorkingCase } = useContext(FormContext)
  const { sendNotification, transitionCase, updateCase } = useCaseOperations()
  
  // Component logic here
  
  return (
    <PageLayout>
      {/* Other components */}
      <NotificationModal
        isOpen={navigateTo !== undefined}
        onClose={() => setNavigateTo(undefined)}
        onSend={handleSendNotification}
        onContinue={handleContinue}
        workingCase={workingCase}
        isSending={isSendingNotification}
        error={sendNotificationError}
      />
    </PageLayout>
  )
}

This refactoring would improve the component's structure and make it easier to understand and maintain.

apps/system-e2e/src/tests/judicial-system/regression/custody-tests.spec.ts (2)

66-66: Approved, but consider using a more descriptive input name.

The change from 'accusedName' to 'inputName' has been implemented correctly. However, 'inputName' is less specific and might reduce clarity in the test. Consider using a more descriptive name that reflects the purpose of the input, such as 'accusedFullName' or 'defendantName', to maintain clarity in the test code.


Line range hint 1-486: Consider refactoring for improved maintainability.

The overall structure of the E2E tests follows good practices for Playwright, including well-organized test cases, proper use of async/await, and comprehensive page object interactions. However, the file is quite long, which could make maintenance challenging. Consider the following improvements:

  1. Split the tests into smaller, more focused files based on specific workflows or features.
  2. Extract common setup and teardown logic into separate helper functions or fixtures.
  3. Create reusable page object models for frequently used UI components.
  4. Consider using custom test commands for repetitive actions to reduce code duplication.

These refactoring steps could enhance the maintainability and readability of your E2E test suite.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9c26661 and cfedcac.

Files selected for processing (4)
  • apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/HearingArrangements/HearingArrangements.tsx (1 hunks)
  • apps/system-e2e/src/tests/judicial-system/regression/custody-tests.spec.ts (1 hunks)
  • apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (2 hunks)
  • apps/system-e2e/src/tests/judicial-system/regression/search-warrant-tests.spec.ts (1 hunks)
Additional context used
Path-based instructions (4)
apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/HearingArrangements/HearingArrangements.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/system-e2e/src/tests/judicial-system/regression/custody-tests.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/system-e2e/src/tests/judicial-system/regression/search-warrant-tests.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Additional comments not posted (5)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (2)

89-89: LGTM! Good for readability.

The addition of this empty line improves the code structure by clearly separating different sections of the test. This enhances readability and maintainability.


Line range hint 1-146: Overall, excellent updates to the E2E tests.

The changes in this file successfully address the PR objectives by updating selectors for new input components and enhancing the test's robustness. The additions of new asynchronous operations and improved error handling are particularly noteworthy. The code adheres to NextJS best practices and makes efficient use of TypeScript for type safety.

A few minor suggestions have been made to improve code clarity through comments, but these are not critical. Great job on keeping the E2E tests up-to-date and functional!

apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/HearingArrangements/HearingArrangements.tsx (1)

96-96: Verify the impact of simplifying the stepIsValid condition.

The condition for stepIsValid has been simplified by removing the isTransitioningCase check. While this improves code readability, it may change the component's behavior during case transitions.

Please confirm that this change is intentional and doesn't introduce any issues in the following scenarios:

  1. When a case is in the process of transitioning.
  2. In the context of the handleNavigationTo function, which still uses isTransitioningCase.

Consider adding a comment explaining the rationale behind this change to improve code maintainability.

To verify the impact, you can run the following script to check for other occurrences of isTransitioningCase in the codebase:

apps/system-e2e/src/tests/judicial-system/regression/search-warrant-tests.spec.ts (2)

Line range hint 1-248: Overall, the changes look good. Ensure comprehensive E2E testing.

The modification to update the input selector for the accused's name is in line with the PR objectives. The change is minimal and focused, which reduces the risk of introducing new issues.

To ensure the E2E test suite remains robust after this change:

  1. Run the entire E2E test suite and verify all tests pass:

  2. Check for any deprecation warnings or console errors during test execution:

These steps will help validate that the selector change hasn't inadvertently affected other parts of the test suite.


44-44: LGTM! Consider reviewing similar selectors.

The change from input[name=accusedName] to input[name=inputName] aligns with the PR objectives of updating E2E tests for new input components. This modification correctly updates the selector for the accused's name input field.

To ensure consistency, please verify if there are any other similar selectors in this file or related test files that might need updating. You can use the following script to check for other potential instances:

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 36.65%. Comparing base (942b852) to head (798b68b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...onCase/HearingArrangements/HearingArrangements.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16133      +/-   ##
==========================================
- Coverage   36.69%   36.65%   -0.05%     
==========================================
  Files        6761     6759       -2     
  Lines      139064   138971      -93     
  Branches    39498    39488      -10     
==========================================
- Hits        51035    50942      -93     
  Misses      88029    88029              
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.56% <ø> (-0.01%) ⬇️
application-template-api-modules 23.61% <ø> (-0.02%) ⬇️
application-ui-shell 21.29% <ø> (ø)
judicial-system-web 28.56% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...onCase/HearingArrangements/HearingArrangements.tsx 0.00% <0.00%> (ø)

... and 18 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 942b852...798b68b. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 24, 2024

Datadog Report

All test runs f4a7aab 🔗

5 Total Test Services: 0 Failed, 5 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.01%), 13 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.86s 1 no change Link
application-system-api 0 0 0 111 2 3m 10.72s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 47.4s 1 decreased (-0.01%) Link
application-ui-shell 0 0 0 74 0 34.25s 1 no change Link
judicial-system-web 0 0 0 338 0 1m 7.42s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-template-api-modules - jest 25.68% (-0.01%) - Details

Copy link
Member

@brynjarorng brynjarorng left a comment

Choose a reason for hiding this comment

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

LGTM

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants