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(j-s): Regression E2E for court's handling of indictment cases #17457

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

unakb
Copy link
Member

@unakb unakb commented Jan 9, 2025

E2E test fyrir ákærur - dómari móttekur, klárar og sendir til Ríksak

What

Added a regression test for the judges step of an indictment. It handles the receiving of an indictment case, assigns it to a judge and sends the subpoena. Then proceeds to complete a ruling in the case and sends it to the public prosecutor.

Why

So we can have an automated test for this step of an indictment case. We now have the following steps covered:

  • Creation of a new indictment
  • The acceptance of the indictment and sending it to the court
  • The court's handling of the indictment

Screenshots / Gifs

E2E.court.mov

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

    • Enhanced indictment test suite with more comprehensive UI interaction checks
    • Added new helper functions for generating court case numbers and document uploads
  • Improvements

    • Updated test flow to include more detailed verification steps
    • Improved flexibility in generating court case numbers with optional prefixes
    • Added more robust document upload processes and case creation interactions
  • Tests

    • Expanded test coverage for judicial system workflows
    • Added new verification steps for indictment case creation and management

@unakb unakb requested a review from a team as a code owner January 9, 2025 11:59
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > babel-jest > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > tempy > del > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/codegen > [email protected]: Glob versions prior to v9 are no longer supported
warning react-native > @react-native/community-cli-plugin > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning react-native > @react-native-community/cli > @react-native-community/cli-tools > [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/dev-middleware > @rnx-kit/chromium-edge-launcher > [email protected]: Rimraf versions prior to v4 are no longer supported
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.
warning next-auth > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning next-auth > [email protected]: this version is no longer supported
warning next-auth > @next-auth/typeorm-legacy-adapter > typeorm > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > stylus > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > webpack-dev-middleware > [email protected]: this will be v4
warning @nx/next > @nx/webpack > fork-ts-checker-webpack-plugin > [email protected]: this will be v4
warning workspace-aggregator-61e2581b-55bf-4a37-b7ea-ef6c1173d1d3 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning "@nx/eslint > @nx/js > [email protected]" has unmet peer dependency "@types/node@".
warning "@nx/next > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "styled-components > babel-plugin-styled-components > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > [email protected]" has unmet peer dependency "react-is@>= 16.8.0".
warning "@nx/react > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > [email protected]" has unmet peer dependency "@types/node@
".
warning " > [email protected]" has incorrect peer dependency "[email protected]".
warning "react-native > @react-native/[email protected]" has unmet peer dependency "@babel/preset-env@^7.1.6".
warning "react-native > @react-native/community-cli-plugin > @react-native/[email protected]" has unmet peer dependency "@babel/core@*".
warning "@vanilla-extract/next-plugin > @vanilla-extract/[email protected]" has unmet peer dependency "webpack@^4.30.0 || ^5.20.2".
warning " > [email protected]" has incorrect peer dependency "react@^16.13.1 || ^17".
warning " > [email protected]" has incorrect peer dependency "react-dom@^16.13.1 || ^17".
warning "next-auth > @next-auth/[email protected]" has unmet peer dependency "@prisma/client@^2.16.1".
warning "@nx/next > [email protected]" has unmet peer dependency "webpack@^5.1.0".

Walkthrough

This pull request focuses on enhancing the indictment tests in the judicial system e2e test suite. The changes include updating test helper functions, modifying the test flow for indictment cases, and adding more comprehensive UI interaction checks. Key modifications involve introducing new helper functions like randomIndictmentCourtCaseNumber and chooseDocument, and updating the existing randomCourtCaseNumber function to support optional prefixes.

Changes

File Change Summary
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts - Replaced uploadDocument with chooseDocument
- Added randomPoliceCaseNumber generation
- Enhanced test flow with additional verification steps
- Updated logic for filling in court case number and selecting a judge
apps/system-e2e/src/tests/judicial-system/utils/helpers.ts - Updated randomCourtCaseNumber to accept optional prefix
- Added randomIndictmentCourtCaseNumber function
- Introduced new helper methods for document handling

Possibly related PRs

Suggested labels

automerge

Finishing Touches

  • 📝 Generate Docstrings

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.

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.

@unakb unakb changed the title J s/indictment e2e judge test(j-s): Regression E2E for court's handling of indictment cases Jan 9, 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: 0

🧹 Nitpick comments (6)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (4)

105-105: *Typo in label text 'LÖKE málsnúmer Veldu málsnú'

The label text 'LÖKE málsnúmer *Veldu málsnú' appears to be incomplete or contain a typo in the word 'málsnú'. Please verify and correct the label text to ensure it displays accurately.


126-126: Typo in label text 'Krefjast sviptingarKrefjast'

The label text 'Krefjast sviptingarKrefjast' seems to have a duplicated word 'Krefjast'. Please check the text and correct it to avoid repetition.


234-234: Incomplete label text 'Ákærði óskar ekki eftir að sé'

The label text 'Ákærði óskar ekki eftir að sé' looks incomplete and may be missing some words at the end. Please verify and update the label text for clarity and completeness.


253-257: Use more specific selectors instead of .nth()

Using .nth() to select elements can make tests brittle if the order of elements changes. Consider using more specific selectors or test IDs to target the upload buttons for documents to enhance test reliability.

Also applies to: 263-267

apps/system-e2e/src/tests/judicial-system/utils/helpers.ts (2)

8-12: Ensure consistent formatting for court case numbers

The function randomCourtCaseNumber may generate numbers like 'R-0/2025', which might not be desirable. To maintain consistency, consider padding the random number with leading zeros to ensure a fixed length, such as three digits.

You can modify the function as follows:

 export const randomCourtCaseNumber = (prefix?: string) => {
-  return `${prefix ?? 'R'}-${Math.floor(
-    Math.random() * 1000,
-  )}/${new Date().getFullYear()}`
+  const randomNumber = Math.floor(Math.random() * 1000)
+  const formattedNumber = randomNumber.toString().padStart(3, '000')
+  return `${prefix ?? 'R'}-${formattedNumber}/${new Date().getFullYear()}`
 }

Line range hint 44-47: Avoid using fixed timeouts; wait for specific events instead

In the chooseDocument function, await page.waitForTimeout(1000) introduces an unnecessary delay and may lead to flaky tests. It's better to wait for specific events or conditions to ensure proper synchronization without arbitrary timeouts.

You can remove the timeout and rely on the file chooser event:

 export const chooseDocument = async (
   page: Page,
   clickButton: () => Promise<void>,
   fileName: string,
 ) => {
   const fileChooserPromise = page.waitForEvent('filechooser')
   await clickButton()

   const fileChooser = await fileChooserPromise
-  await page.waitForTimeout(1000)
   await fileChooser.setFiles(createFakePdf(fileName))
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2d6db8 and aa21b61.

📒 Files selected for processing (2)
  • apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (5 hunks)
  • apps/system-e2e/src/tests/judicial-system/utils/helpers.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/system-e2e/src/tests/judicial-system/utils/helpers.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."
🔇 Additional comments (1)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (1)

217-217: Verify date format for 'courtDate' input

Ensure that the date string returned by getDaysFromNow(7) matches the expected format for the courtDate input field. The date picker might require a specific format such as 'dd.MM.yyyy'. Adjust the date format if necessary to prevent potential issues.

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

🧹 Nitpick comments (2)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (2)

77-132: Consider enhancing assertions in the processing and indictment sections.

While the test flow is good, consider adding these improvements:

  1. Add assertions for error states in form submissions
  2. Verify the state of UI elements after each transition
  3. Add data validation checks for the indictment form

Example assertion for form validation:

await expect(page.getByTestId('form-errors')).toHaveCount(0, 'Form should be valid');

Line range hint 1-287: Consider implementing a more robust test architecture.

While the implementation is good, consider these architectural improvements:

  1. Create shared test fixtures for common setup
  2. Implement custom test assertions for domain-specific validations
  3. Add test data factories for generating consistent test data

Example fixture:

export const indictmentFixture = base.extend({
  setupIndictment: async ({ prosecutorPage }, use) => {
    // Common setup code
    await use(/* setup result */);
  },
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa21b61 and df8d766.

📒 Files selected for processing (1)
  • apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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."
🔇 Additional comments (3)
apps/system-e2e/src/tests/judicial-system/regression/indictment-tests.spec.ts (3)

9-10: LGTM! Helper functions imported for court case handling.

The new imports align well with the PR objectives for testing the court's handling of indictment cases.


25-26: LGTM! Good practice moving case number generation to setup.

Moving the police case number generation to the beginning improves test maintainability and ensures consistency across the test suite.


249-268: Enhance document upload validation and error handling.

While the document upload implementation works, consider adding:

  1. File type validation
  2. File size limits
  3. Upload failure handling

Run this script to check existing file validation:

Comment on lines +172 to +206
test('judge should receive indictment case', async ({ judgePage }) => {
const page = judgePage
const nextWeek = getDaysFromNow(7)

// Case list
await page.goto('/krofur')
await page.getByText(accusedName).click()

// Indictment Overview
await expect(page).toHaveURL(`domur/akaera/yfirlit/${caseId}`)

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])

// Reception and assignment
await expect(page).toHaveURL(`domur/akaera/mottaka/${caseId}`)

await page
.getByTestId('courtCaseNumber')
.fill(randomIndictmentCourtCaseNumber())
await page.keyboard.press('Tab')

await page.getByText('Veldu dómara/aðstoðarmann').click()
await page
.getByTestId('select-judge')
.getByText('Test Dómari')
.last()
.click()

await Promise.all([
page.getByTestId('continueButton').click(),
verifyRequestCompletion(page, '/api/graphql', 'Case'),
])
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

Add error case coverage for judge's workflow.

The happy path is well tested, but consider adding tests for:

  1. Invalid court case number format
  2. Missing judge assignment
  3. Failed API responses

Example test case:

test('should handle invalid court case number', async ({ judgePage }) => {
  await judgePage.getByTestId('courtCaseNumber').fill('invalid');
  await expect(judgePage.getByTestId('error-message')).toBeVisible();
});

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Nice 👏 The rabbit is also proposing to test some failure cases instead of only the valid flow (or happy path) for some fields, which could be useful for fields such as the court case number etc. But I will leave it up to you to decide, as I don't think this is a blocker ✅

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.

2 participants