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

feat(tests): Add functions and documentation to testing/e2e #16694

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

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced enhanced E2E testing capabilities with new functions for API mocking, user session management, and email account handling.
    • Added internationalization support for localized messages.
    • Implemented utility functions for element selection and debugging in tests.
  • Documentation

    • Restructured and improved documentation for the E2E testing library, providing clearer guidance on usage and available features.
  • Bug Fixes

    • Updated the .gitignore file to exclude temporary E2E testing outputs, streamlining version control.
  • Chores

    • Added new dependency @nx/playwright to enhance testing capabilities.

@svanaeinars svanaeinars requested a review from a team as a code owner November 1, 2024 11:49
Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

Walkthrough

The pull request introduces several changes focused on enhancing end-to-end (E2E) testing capabilities. Key modifications include updating the .gitignore file to exclude specific E2E testing outputs, restructuring documentation for the libs/testing/e2e library, and modifying exports in the index.ts file to include various support modules. New utility functions for API testing, user authentication, session management, and URL handling are added, alongside enhancements to the testing framework with custom matchers and utility functions.

Changes

File Change Summary
.gitignore Added entries to ignore test-results/, playwright-report/, and tmp-sessions/.
libs/testing/e2e/README.md Restructured documentation, renamed sections, and added guidance on using Mockoon for E2E tests.
libs/testing/e2e/src/index.ts Removed previous export statement; added exports for various modules from ./lib/support and ./lib/utils.
libs/testing/e2e/src/lib/libs/testing/e2e.spec.ts Deleted unit test file for libsTestingE2e function.
libs/testing/e2e/src/lib/libs/testing/e2e.ts Deleted file containing libsTestingE2e function.
libs/testing/e2e/src/lib/support/api-tools.ts Introduced functions for API testing: graphqlSpy, mockApi, and verifyRequestCompletion.
libs/testing/e2e/src/lib/support/application.ts Added createApplication function for application management in E2E tests.
libs/testing/e2e/src/lib/support/disablers.ts Added functions for mocking GraphQL operations, including mockQGL and others.
libs/testing/e2e/src/lib/support/email-account.ts Introduced functions for managing email accounts with AWS SES and Ethereal.
libs/testing/e2e/src/lib/support/i18n.ts Added internationalization support with a custom error handler and message formatting function.
libs/testing/e2e/src/lib/support/locator-helpers.ts Introduced utility functions for locating elements in Playwright tests.
libs/testing/e2e/src/lib/support/login.ts Added functions for handling user authentication via AWS Cognito and a custom identity service.
libs/testing/e2e/src/lib/support/session.ts Introduced session management functions for Cognito and IDS logins.
libs/testing/e2e/src/lib/support/urls.ts Added types, enums, and functions for managing URLs and environment configurations.
libs/testing/e2e/src/lib/support/utils.ts Introduced utility functions for handling mock PDFs and debugging.
libs/testing/e2e/src/lib/utils/addons.ts Added custom matchers for testing framework: toHaveCountGreaterThan and toBeApplication.
libs/testing/e2e/src/lib/utils/pageHelpers.ts Added functions for selecting form elements by name.
libs/testing/e2e/src/lib/utils/playwright-config.ts Introduced configuration utility for Playwright tests with customizable settings.
package.json Added @nx/playwright dependency in devDependencies.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • rafnarnason
  • oddsson
  • kksteini

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.

@svanaeinars svanaeinars changed the title Add functions and documentation to testing/e2e feat(tests): Add functions and documentation to testing/e2e Nov 1, 2024
@svanaeinars
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.64%. Comparing base (d0c9471) to head (f723214).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16694      +/-   ##
==========================================
- Coverage   36.64%   36.64%   -0.01%     
==========================================
  Files        6872     6871       -1     
  Lines      143068   143067       -1     
  Branches    40770    40770              
==========================================
- Hits        52431    52427       -4     
- Misses      90637    90640       +3     
Flag Coverage Δ
air-discount-scheme-backend 54.17% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 37.30% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.92% <ø> (ø)
api-domains-criminal-record 47.83% <ø> (ø)
api-domains-driving-license 44.61% <ø> (ø)
api-domains-education 31.58% <ø> (ø)
api-domains-health-insurance 34.77% <ø> (ø)
api-domains-mortgage-certificate 34.93% <ø> (ø)
api-domains-payment-schedule 41.51% <ø> (ø)
application-api-files 56.78% <ø> (ø)
application-core 71.49% <ø> (+0.32%) ⬆️
application-system-api 41.33% <ø> (ø)
application-template-api-modules 27.82% <ø> (ø)
application-templates-accident-notification 29.24% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.30% <ø> (ø)
application-templates-driving-license 18.40% <ø> (ø)
application-templates-estate 12.19% <ø> (ø)
application-templates-example-payment 25.20% <ø> (ø)
application-templates-financial-aid 15.55% <ø> (ø)
application-templates-general-petition 23.42% <ø> (ø)
application-templates-inheritance-report 6.50% <ø> (ø)
application-templates-marriage-conditions 15.18% <ø> (ø)
application-templates-mortgage-certificate 43.58% <ø> (ø)
application-templates-parental-leave 29.94% <ø> (ø)
application-types 6.62% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.87% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 30.20% <ø> (ø)
auth-react 21.94% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.56% <ø> (ø)
clients-driving-license-book 43.70% <ø> (ø)
clients-financial-statements-inao 49.32% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 72.88% <ø> (-0.26%) ⬇️
clients-regulations 42.66% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.38% <ø> (ø)
clients-zendesk 54.61% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.05% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 5.20% <ø> (ø)
dokobit-signing 63.38% <ø> (ø)
download-service 44.39% <ø> (ø)
email-service 61.13% <ø> (ø)
feature-flags 91.11% <ø> (ø)
file-storage 53.71% <ø> (ø)
financial-aid-backend 51.38% <ø> (ø)
financial-aid-shared 17.81% <ø> (ø)
icelandic-names-registry-backend 54.34% <ø> (ø)
infra-nest-server 48.37% <ø> (ø)
infra-tracing 43.24% <ø> (ø)
island-ui-core 28.86% <ø> (ø)
judicial-system-api 19.52% <ø> (ø)
judicial-system-audit-trail 69.43% <ø> (ø)
judicial-system-backend 55.32% <ø> (ø)
judicial-system-formatters 79.91% <ø> (ø)
judicial-system-message 67.37% <ø> (ø)
judicial-system-message-handler 48.53% <ø> (ø)
judicial-system-scheduler 70.62% <ø> (ø)
judicial-system-types 44.13% <ø> (ø)
judicial-system-web 27.65% <ø> (ø)
license-api 42.65% <ø> (-0.06%) ⬇️
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 67.80% <ø> (-0.79%) ⬇️
nest-audit 68.20% <ø> (ø)
nest-aws 61.15% <ø> (ø)
nest-config 78.44% <ø> (ø)
nest-core 43.54% <ø> (ø)
nest-feature-flags 51.52% <ø> (ø)
nest-problem 45.82% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 62.74% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.91% <ø> (ø)
reference-backend 49.74% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 51.92% <ø> (ø)
services-auth-delegation-api 57.57% <ø> (ø)
services-auth-ids-api 51.49% <ø> (-0.01%) ⬇️
services-auth-personal-representative 45.14% <ø> (+0.02%) ⬆️
services-auth-personal-representative-public 41.33% <ø> (+0.03%) ⬆️
services-auth-public-api 49.01% <ø> (ø)
services-documents 60.81% <ø> (ø)
services-endorsements-api 53.72% <ø> (ø)
services-sessions 65.54% <ø> (ø)
services-university-gateway 49.44% <ø> (+0.11%) ⬆️
services-user-notification 46.99% <ø> (ø)
services-user-profile 61.85% <ø> (ø)
shared-components 26.93% <ø> (ø)
shared-form-fields 31.22% <ø> (ø)
shared-mocking 60.89% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.69% <ø> (ø)
skilavottord-ws 24.14% <ø> (ø)
web 1.80% <ø> (ø)

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

see 2 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 d0c9471...f723214. Read the comment docs.

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

🧹 Outside diff range and nitpick comments (12)
libs/testing/e2e/src/lib/utils/pageHelpers.ts (1)

1-2: Add TypeScript documentation for better developer experience.

Since this is a reusable testing library, adding JSDoc comments would improve the developer experience.

Add documentation:

+/**
+ * Returns a CSS selector for an input element with the specified name attribute.
+ * @param name - The value of the name attribute to match
+ * @returns A CSS selector string
+ * @example
+ * const selector = getInputByName('email');
+ * // Returns: input[name="email"]
+ */
 export const getInputByName = (name: string) => `input[name="${name}"]`

+/**
+ * Returns a CSS selector for a textarea element with the specified name attribute.
+ * @param name - The value of the name attribute to match
+ * @returns A CSS selector string
+ * @example
+ * const selector = getTextareaByName('description');
+ * // Returns: textarea[name="description"]
+ */
 export const getTextareaByName = (name: string) => `textarea[name="${name}"]`
libs/testing/e2e/src/lib/support/i18n.ts (1)

15-15: Add JSDoc documentation for better code maintainability.

The exported function would benefit from proper documentation explaining its purpose and usage.

Here's a suggested improvement:

+/**
+ * Formats a message descriptor using the configured intl instance
+ * @param {MessageDescriptor} l - The message descriptor to format
+ * @returns {string} The formatted message
+ */
 export const label = (l: MessageDescriptor) => intl.formatMessage(l)
libs/testing/e2e/src/index.ts (1)

13-13: Consider moving third-party export to top.

It's a common convention to place third-party imports/exports before local ones. This helps with:

  • Distinguishing external vs internal dependencies
  • Maintaining consistent code organization
+export * from '@playwright/test'
+
 export * from './lib/support/api-tools'
 export { createApplication } from './lib/support/application'
 export * from './lib/support/disablers'
 // ... rest of local exports
-export * from '@playwright/test'
libs/testing/e2e/src/lib/utils/playwright-config.ts (1)

3-8: Add JSDoc documentation to improve interface clarity.

While the interface is well-structured, adding JSDoc comments would improve documentation and provide better IDE support.

+/**
+ * Parameters for creating a global Playwright configuration
+ */
 interface GlobalConfigParams {
+  /** Base URL for the web server running the application under test */
   webServerUrl: string
+  /** Optional port number for the web server */
   port?: number
+  /** Command to start the web server */
   command: string
+  /** Optional working directory for the web server, defaults to '../../../' */
   cwd?: string
 }
libs/testing/e2e/src/lib/support/application.ts (1)

3-13: Enhance JSDoc documentation

While the documentation is comprehensive, consider adding:

  • @throws tag to document potential error scenarios (e.g., network failures, timeout errors)
  • More specific return type documentation (e.g., Promise<number> representing the count of existing applications)
 /**
  Creates a new application and returns the number of applications before creation.
  @async
  @function
  @param {Page} page - Playwright Page object representing the current page.
  @returns {Promise<number>} - The number of applications before the new application is created.
+ @throws {Error} - When the GraphQL request fails or times out
+ @throws {Error} - When the create application button is not found
  This function waits for the applications to load on the overview page and
  counts the number of applications. If there is an existing application, the
  overview page will not redirect to a new application. In this case, the function
  clicks the 'create-new-application' button to create a new application.
  */
.gitignore (1)

102-105: Consider adding trailing slashes for consistency.

While the ignore patterns work correctly, consider adding trailing slashes to explicitly indicate these are directories, matching the style used elsewhere in the file (e.g., node_modules/).

 # E2E outputs
-test-results/
-playwright-report/
-tmp-sessions/
+test-results//
+playwright-report//
+tmp-sessions//
libs/testing/e2e/README.md (2)

1-11: Enhance documentation with TypeScript and reusability details.

Consider adding information about:

  • TypeScript usage in the helper functions and configurations
  • How these utilities can be reused across different NextJS applications

Example addition after line 10:

- **Global Playwright Configuration:** The `createGlobalConfig` function provides a shared Playwright configuration used across multiple applications. It standardizes the testing environment.
+ **Global Playwright Configuration:** The `createGlobalConfig` function provides a shared Playwright configuration used across multiple applications. It standardizes the testing environment.
+
+ ## TypeScript Support
+
+ All helper functions and configurations are written in TypeScript, providing type safety and better IDE support. The library exports TypeScript interfaces and types that can be used in your test files.
+
+ ## Reusability
+
+ The utility functions are designed to be reusable across different NextJS applications within the project. They abstract common testing patterns and provide a consistent testing experience regardless of the specific application being tested.

46-48: Enhance CLI command documentation.

The command example could benefit from:

  • A more specific example path
  • Information about required environment variables
  • Common port numbers used in the project

Example enhancement:

```bash
-yarn mockoon-cli start --data ./apps/<my-app>/e2e/mocks/<my-app-mock>.json --port <port>
+yarn mockoon-cli start --data ./apps/web/e2e/mocks/api-mock.json --port 3000

Note: Replace the port number with one that doesn't conflict with your application's default port. Common ports used in the project are 3000, 3001, and 3002.


</blockquote></details>
<details>
<summary>libs/testing/e2e/src/lib/support/urls.ts (1)</summary><blockquote>

`19-25`: **Document the purpose of hardcoded national IDs**

The login URLs contain hardcoded national IDs without explanation. Add documentation explaining what these IDs represent (e.g., test accounts, mock data) and their specific roles.


```diff
+// National IDs for test accounts:
+// 9999999999 - Regular user
+// 0000000000 - Judge
+// 0000000001 - Court of Appeals Judge
+// 0909090909 - Defender
 export const JUDICIAL_SYSTEM_HOME_URL = '/api/auth/login?nationalId=9999999999'
 export const JUDICIAL_SYSTEM_JUDGE_HOME_URL =
   '/api/auth/login?nationalId=0000000000'
libs/testing/e2e/src/lib/support/login.ts (1)

71-74: Address the TODO: Update selector when the new login page is deployed.

There's a TODO comment indicating that an accessible selector should be used once the new login page is available. Updating the selector will improve accessibility and maintainability.

Do you want assistance in updating the selector now, or should we open a GitHub issue to track this task?

libs/testing/e2e/src/lib/support/email-account.ts (1)

83-92: Add explicit TypeScript type annotations for 'emailConfig'

To enhance type safety and readability, consider adding explicit TypeScript type annotations for emailConfig.

For example:

+ import { ImapSimpleOptions } from 'imap-simple'

 const emailConfig: ImapSimpleOptions = {
   imap: {
     user: testAccount.user,
     password: testAccount.pass,
     host: 'imap.ethereal.email',
     port: 993,
     tls: true,
     authTimeout: 10000,
   },
 }
libs/testing/e2e/src/lib/support/session.ts (1)

153-153: Ensure consistent URL matching in session validation

The assertion await expect(sessionValidation?.url()).toMatch(homeUrl) assumes that the navigated URL will exactly match homeUrl. If homeUrl is not a full URL or if there are redirects or added query parameters, this assertion might fail. Consider using toContain or normalizing URLs before comparison.

Apply this diff to adjust the assertion:

- await expect(sessionValidation?.url()).toMatch(homeUrl)
+ await expect(sessionValidation?.url()).toContain(homeUrl)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 82fde90 and f723214.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (19)
  • .gitignore (1 hunks)
  • libs/testing/e2e/README.md (1 hunks)
  • libs/testing/e2e/src/index.ts (1 hunks)
  • libs/testing/e2e/src/lib/libs/testing/e2e.spec.ts (0 hunks)
  • libs/testing/e2e/src/lib/libs/testing/e2e.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/api-tools.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/application.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/disablers.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/email-account.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/i18n.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/locator-helpers.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/login.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/session.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/urls.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/utils.ts (1 hunks)
  • libs/testing/e2e/src/lib/utils/addons.ts (1 hunks)
  • libs/testing/e2e/src/lib/utils/pageHelpers.ts (1 hunks)
  • libs/testing/e2e/src/lib/utils/playwright-config.ts (1 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (2)
  • libs/testing/e2e/src/lib/libs/testing/e2e.spec.ts
  • libs/testing/e2e/src/lib/libs/testing/e2e.ts
🧰 Additional context used
📓 Path-based instructions (15)
libs/testing/e2e/README.md (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/index.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/api-tools.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/application.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/disablers.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/email-account.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/i18n.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/locator-helpers.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/login.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/session.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/urls.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/support/utils.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/utils/addons.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/utils/pageHelpers.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/utils/playwright-config.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[grammar] ~20-~20: The verb ‘mocks’ is singular. Did you mean: “this mocks” or “these mock”?
Context: ...ommand-line interface (CLI) for running these mocks in various environments, such as pipeli...

(SINGULAR_VERB_AFTER_THESE_OR_THOSE)

🪛 Biome
libs/testing/e2e/src/lib/support/email-account.ts

[error] 35-35: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (19)
libs/testing/e2e/src/index.ts (2)

2-2: LGTM! Good use of named export.

The explicit named export of createApplication follows best practices for:

  • Clear dependency tracking
  • Effective tree-shaking
  • Self-documenting API

1-13: Verify potential circular dependencies.

With multiple interdependent testing utilities, it's important to ensure there are no circular dependencies that could cause issues.

✅ Verification successful

Let me try another approach to check for circular dependencies with corrected regex patterns.


Let me try one final check to look for imports with a more inclusive pattern that might catch any potential circular dependencies.


No circular dependencies detected in the testing utilities

Based on the analysis of import statements across all support and utils files, the codebase maintains a clean dependency structure:

  • Support modules have clear, one-way dependencies (e.g., login depends on urls and utils)
  • Utils modules are mostly self-contained with external dependencies
  • No circular import chains were found between modules
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential circular dependencies in the testing library

# Test 1: Look for files importing from index.ts
echo "Files importing from index.ts:"
rg -l "from '\.\.\/index'" libs/testing/e2e/src/

# Test 2: Check for cross-imports between support modules
echo -e "\nCross-imports between support modules:"
for file in $(fd -t f . libs/testing/e2e/src/lib/support/); do
  echo "=== Imports in $file ==="
  rg "from '.*support/" "$file" || true
done

Length of output: 3138


Script:

#!/bin/bash
# Check for circular dependencies with corrected patterns

# Look for imports between files
echo "=== Checking cross-imports in support modules ==="
for file in $(fd -t f . libs/testing/e2e/src/lib/support/); do
  filename=$(basename "$file")
  echo -e "\nFile: $filename"
  rg "from ['\"]\.\.?/support/" "$file" || true
done

echo -e "\n=== Checking imports from index.ts ==="
rg "from ['\"]\.\.?/index" libs/testing/e2e/src/lib/

# Check utils folder imports as well
echo -e "\n=== Checking utils folder imports ==="
for file in $(fd -t f . libs/testing/e2e/src/lib/utils/); do
  filename=$(basename "$file")
  echo -e "\nFile: $filename"
  rg "from ['\"]\.\.?/(support|utils)/" "$file" || true
done

Length of output: 4121


Script:

#!/bin/bash
# Final check for circular dependencies with broader patterns

echo "=== Checking all imports in support files ==="
for file in $(fd -t f . libs/testing/e2e/src/lib/support/); do
  echo -e "\nFile: $(basename "$file")"
  rg "^import .* from ['\"]" "$file" || true
done

echo -e "\n=== Checking all imports in utils files ==="
for file in $(fd -t f . libs/testing/e2e/src/lib/utils/); do
  echo -e "\nFile: $(basename "$file")"
  rg "^import .* from ['\"]" "$file" || true
done

Length of output: 4790

libs/testing/e2e/src/lib/support/locator-helpers.ts (1)

1-24: LGTM! Code follows the library guidelines.

The implementation:

  • Uses TypeScript effectively with proper type definitions
  • Provides reusable helper functions
  • Follows proper export patterns enabling tree-shaking
libs/testing/e2e/src/lib/support/utils.ts (1)

5-5: LGTM! Well-implemented utility function.

The sleep function is properly typed and follows Promise-based implementation best practices.

libs/testing/e2e/src/lib/utils/playwright-config.ts (2)

16-43: LGTM! The configuration structure follows Playwright best practices.

The configuration includes essential settings for both development and CI environments, with proper handling of:

  • Parallel execution
  • Retries and workers
  • Tracing
  • Web server management

35-38: Clarify web server URL and port configuration logic.

The current logic for handling URL and port is not immediately clear. Consider making this more explicit or adding validation.

Let's check if this configuration pattern is used consistently across the codebase:

✅ Verification successful

The URL and port configuration logic is clear and correct

The configuration follows a standard pattern where:

  • When port is provided, it's used for starting the web server and the URL is automatically derived
  • When port is not provided, a specific webServerUrl must be used instead

This is a common and valid configuration pattern for Playwright, where you either:

  1. Specify a port and let Playwright handle the URL construction
  2. Provide a complete URL when the server is already running elsewhere
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other Playwright configurations to verify URL/port handling patterns
rg -l "webServer.*port.*url" --type ts

Length of output: 40


Script:

#!/bin/bash
# Let's try a broader search for Playwright configuration patterns
rg -A 5 "webServer\s*:\s*{" --type ts

# Also search for specific port and url configurations
rg -A 3 "port\s*:\s*" --type ts

# Look for the actual file content
cat libs/testing/e2e/src/lib/utils/playwright-config.ts

Length of output: 59539

libs/testing/e2e/src/lib/utils/addons.ts (1)

1-1: LGTM: Clean and well-structured import statement

The import statement follows TypeScript best practices and includes only the necessary utilities.

libs/testing/e2e/src/lib/support/application.ts (2)

1-1: LGTM: Clean import with proper type usage

The import statement correctly imports the Page type from Playwright, ensuring proper type safety.


16-18: Verify GraphQL operation in schema

Let's ensure the GraphQL operation is properly typed and documented in the schema.

✅ Verification successful

The previous search had issues with file type recognition. Let's try a broader search to find any references to this operation and its definition.


GraphQL operation is properly typed and used across the application

The ApplicationApplications operation is well-defined and properly used throughout the codebase:

  • It's defined as a GraphQL query in multiple locations with proper typing (ApplicationApplicationsInput)
  • Used consistently in both frontend and backend:
    • Frontend: Used in service portal, native app, and e2e tests
    • Backend: Implemented in the application domain with proper resolvers and service layer
  • The operation in the e2e test file matches the schema definition and its usage across the application

The GraphQL operation being waited for in the e2e test is correctly implemented and typed in the schema.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ApplicationApplications query definition in GraphQL schema files
echo "Searching for ApplicationApplications query definition..."
fd -e graphql -e gql | xargs rg -l "type Query" | while read -r file; do
  echo "Checking file: $file"
  rg -A 5 "applicationApplications" "$file"
done

# Search for any tests using this query
echo "Searching for existing tests..."
rg -l "ApplicationApplications" --type=typescript --type=javascript

Length of output: 1067


Script:

#!/bin/bash
# Let's try a different approach to search for the GraphQL operation
echo "Searching for ApplicationApplications in all files..."
rg -i "ApplicationApplications" -A 5 -B 5

# Also search for any GraphQL query definitions
echo "Searching for GraphQL query definitions..."
rg "query.*ApplicationApplications" -A 5

Length of output: 53577

.gitignore (1)

101-105: LGTM! Appropriate additions for E2E testing outputs.

The new entries correctly exclude Playwright's test results, reports, and temporary session data from version control, which is the right approach for generated test artifacts.

package.json (1)

356-356: Verify @playwright/test peer dependency.

The @nx/playwright package typically requires @playwright/test as a peer dependency. While it's present in the dependencies, ensure it's at a compatible version.

#!/bin/bash
# Check if @playwright/test version is compatible with @nx/playwright
rg -A 2 "@playwright/test.*\"1\.48\"" package.json
libs/testing/e2e/src/lib/support/login.ts (5)

5-8: Type definition for 'CognitoCreds' utilizes TypeScript effectively.

The CognitoCreds type is properly defined with username and password fields, enhancing type safety and clarity in credential management.


10-18: getCognitoCredentials function correctly retrieves and validates credentials.

The function appropriately accesses environment variables and throws an error if credentials are missing, ensuring that authentication cannot proceed without valid inputs.


31-46: cognitoLogin function correctly handles the Cognito authentication flow.

The function successfully automates the login process, including form interactions and navigation handling. The use of optional credentials parameter enhances reusability.


48-93: idsLogin function effectively manages login through the identity service.

The function accurately handles phone number input, delegation selection, and waits for appropriate page navigation. The comments provide clarity on the handling of both new and current login pages.


95-109: switchUser function accurately switches between user profiles.

The function correctly interacts with the user menu and handles optional user selection. Waiting for page navigation ensures the user interface updates as expected.

libs/testing/e2e/src/lib/support/disablers.ts (1)

15-15: 🛠️ Refactor suggestion

Enhance reusability by ensuring flexible parameter types.

By updating the type of deepMockKey to accept both Matchable and Matchable[], you improve the function's flexibility and reusability across different scenarios.

As updated previously:

 deepMockKey?: Matchable | Matchable[]

Likely invalid or redundant comment.

libs/testing/e2e/src/lib/support/session.ts (2)

19-38: Function ensureCognitoSessionIfNeeded is well-implemented

The function correctly identifies when Cognito authentication is required and performs the login process appropriately. The use of page.request.get to validate the session and handling redirects is effective.


159-176: Function judicialSystemSession is correctly implemented

The function properly sets up a new browser context and ensures the Cognito session for the judicial system. This is a good abstraction for tests specific to the judicial system context.

Comment on lines +1 to +2
export const getInputByName = (name: string) => `input[name="${name}"]`
export const getTextareaByName = (name: string) => `textarea[name="${name}"]`
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

Consider refactoring to reduce code duplication.

Both functions share similar logic for generating selectors. This could be abstracted into a reusable helper.

Consider this refactor:

+/**
+ * Returns a CSS selector for a form element with the specified element type and name attribute.
+ * @param elementType - The HTML element type (e.g., 'input', 'textarea')
+ * @param name - The value of the name attribute to match
+ * @returns A CSS selector string
+ */
+const getElementByName = (elementType: string, name: string) => 
+  `${elementType}[name="${name}"]`
+
+/**
+ * Returns a CSS selector for an input element with the specified name attribute.
+ */
+export const getInputByName = (name: string) => getElementByName('input', name)
+
+/**
+ * Returns a CSS selector for a textarea element with the specified name attribute.
+ */
+export const getTextareaByName = (name: string) => getElementByName('textarea', name)
📝 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
export const getInputByName = (name: string) => `input[name="${name}"]`
export const getTextareaByName = (name: string) => `textarea[name="${name}"]`
/**
* Returns a CSS selector for a form element with the specified element type and name attribute.
* @param elementType - The HTML element type (e.g., 'input', 'textarea')
* @param name - The value of the name attribute to match
* @returns A CSS selector string
*/
const getElementByName = (elementType: string, name: string) =>
`${elementType}[name="${name}"]`
/**
* Returns a CSS selector for an input element with the specified name attribute.
*/
export const getInputByName = (name: string) => getElementByName('input', name)
/**
* Returns a CSS selector for a textarea element with the specified name attribute.
*/
export const getTextareaByName = (name: string) => getElementByName('textarea', name)

⚠️ Potential issue

Add input validation and escape special characters.

The functions directly interpolate the input into CSS selectors without validation, which could lead to CSS injection if the name contains special characters.

Consider adding input validation and escaping:

+const escapeCSSString = (str: string): string => {
+  return CSS.escape(str);
+}
+
-export const getInputByName = (name: string) => `input[name="${name}"]`
-export const getTextareaByName = (name: string) => `textarea[name="${name}"]`
+export const getInputByName = (name: string) => `input[name="${escapeCSSString(name)}"]`
+export const getTextareaByName = (name: string) => `textarea[name="${escapeCSSString(name)}"]`

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

libs/testing/e2e/src/lib/support/i18n.ts Show resolved Hide resolved
@@ -1 +1,13 @@
export * from './lib/libs/testing/e2e'
export * from './lib/support/api-tools'
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

Consider using named exports for better tree-shaking.

While using export * is convenient, it can make tree-shaking less effective. Consider explicitly listing the exports from each module to:

  • Make dependencies more visible
  • Enable better dead code elimination
  • Provide better documentation of available functionality

Example refactor for api-tools:

-export * from './lib/support/api-tools'
+export { 
+  graphqlSpy,
+  mockApi,
+  verifyRequestCompletion 
+} from './lib/support/api-tools'

Also applies to: 3-10

Comment on lines +102 to +135
async getLastEmail(retries: number): Promise<null | {
subject: string | undefined
text: string | undefined
html: string | false
}> {
// makes debugging very simple
debug('getting the last email')
debug(JSON.stringify(emailConfig))

debug('connecting to mail server...')
const connection = await connect(emailConfig)
debug('connected')
try {
// grab up to 50 emails from the inbox
debug('Opening inbox...')
await connection.openBox('INBOX')
debug('Opened inbox.')
const searchCriteria = ['UNSEEN']
const fetchOptions = {
bodies: [''],
markSeen: true,
}
debug('Starting search for new messages...')
const messages = await connection.search(searchCriteria, fetchOptions)
debug('Search finished')

if (!messages.length) {
debug('cannot find any emails')
if (retries <= 0) {
return null
} else {
await new Promise((r) => setTimeout(r, 5000))
return userEmail.getLastEmail(retries - 1)
}
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

Refactor 'getLastEmail' to avoid recursion and prevent stack overflows

The getLastEmail function uses recursion for retry logic, which can lead to stack overflows if the number of retries is large. Consider refactoring to use an iterative approach.

Here's an example refactor:

 async getLastEmail(retries: number): Promise<null | {
   subject: string | undefined
   text: string | undefined
   html: string | false
 }> {
-   // Existing recursive implementation
+   let attempts = retries
+   while (attempts >= 0) {
+     debug('connecting to mail server...')
+     const connection = await connect(emailConfig)
+     debug('connected')
+     try {
+       // ... (rest of your logic)
+       if (!messages.length) {
+         debug('cannot find any emails')
+         if (attempts === 0) {
+           return null
+         } else {
+           await new Promise((r) => setTimeout(r, 5000))
+           attempts--
+           continue
+         }
+       } else {
+         // Return the email
+         return {
+           subject: mail.subject,
+           text: mail.text,
+           html: mail.html,
+         }
+       }
+     } finally {
+       connection.end()
+     }
+   }
 }

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

libs/testing/e2e/src/lib/support/session.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/support/session.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/support/session.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/support/session.ts Show resolved Hide resolved
@datadog-island-is
Copy link

Datadog Report

All test runs a4135f4 🔗

101 Total Test Services: 0 Failed, 98 Passed
🔻 Test Sessions change in coverage: 3 decreased, 1 increased (+0.01%), 196 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 82 0 24.78s N/A Link
air-discount-scheme-web 0 0 0 2 0 7.02s N/A Link
api 0 0 0 4 0 2.3s N/A Link
api-catalogue-services 0 0 0 23 0 9.04s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 15.66s N/A Link
api-domains-assets 0 0 0 3 0 9.38s N/A Link
api-domains-auth-admin 0 0 0 18 0 10.06s N/A Link
api-domains-communications 0 0 0 5 0 28.29s N/A Link
api-domains-criminal-record 0 0 0 5 0 8.11s N/A Link
api-domains-driving-license 0 0 0 23 0 26.58s N/A Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • testing-e2e - jest 0% (-66.66%) - Details
  • message-queue - jest 68.26% (-0.9%) - Details
  • clients-middlewares - jest 75.62% (-0.1%) - Details

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