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

Merged
merged 10 commits into from
Nov 12, 2024

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new functions for API testing, including graphqlSpy, mockApi, and verifyRequestCompletion.
    • Added functionality for managing email accounts and user authentication.
    • Enhanced internationalization support with a new i18n setup.
    • Added utility functions for managing mock PDF files.
  • Documentation

    • Restructured and enhanced documentation for the E2E testing library.
  • Chores

    • Updated .gitignore to exclude E2E testing output files.
    • Added a new dependency for Playwright in package.json.
    • Updated ownership assignments in the .github/CODEOWNERS file.

@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 across multiple files primarily focused on enhancing end-to-end (E2E) testing capabilities. Key modifications include updates to the .gitignore file to exclude E2E testing outputs, restructuring and improving documentation for the libs/testing/e2e library, and adding new utility functions and types for managing API interactions, user sessions, and internationalization. Additionally, the exports in the index file have been refined to provide access to a broader set of functionalities, while new files have been created to support email account management and mocking GraphQL operations.

Changes

File Change Summary
.gitignore Added patterns to ignore test-results/, playwright-report/, and tmp-sessions/ directories and files.
libs/testing/e2e/README.md Restructured documentation; renamed title to "E2E Testing" and added detailed descriptions and new sections on using Mockoon for E2E tests.
libs/testing/e2e/src/index.ts Removed export of all from ./lib/libs/testing/e2e; added specific exports from various support and utility modules.
libs/testing/e2e/src/lib/libs/testing/e2e.spec.ts Deleted unit test file for the libsTestingE2e function.
libs/testing/e2e/src/lib/libs/testing/e2e.ts Deleted file containing the libsTestingE2e function.
libs/testing/e2e/src/lib/support/api-tools.ts Introduced three functions: graphqlSpy, mockApi, and verifyRequestCompletion for API testing.
libs/testing/e2e/src/lib/support/application.ts Added createApplication function for managing application creation in tests.
libs/testing/e2e/src/lib/support/disablers.ts Introduced functions for mocking GraphQL operations, including mockQGL and others for specific scenarios.
libs/testing/e2e/src/lib/support/email-account.ts Added functions for managing email accounts with AWS SES and Ethereal, including registerEmailAddressWithSES and makeEmailAccount.
libs/testing/e2e/src/lib/support/i18n.ts Introduced internationalization support with a new label function.
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 handling user sessions in tests.
libs/testing/e2e/src/lib/support/urls.ts Added types, enums, and functions for URL management in testing environments.
libs/testing/e2e/src/lib/support/utils.ts Introduced utility functions for handling mock PDFs and debugging.
libs/testing/e2e/src/lib/utils/pageHelpers.ts Added functions for selecting input and textarea elements by name.
package.json Added new dependency @nx/playwright in devDependencies.
.github/CODEOWNERS Updated ownership assignments and renamed "System tests" section to "QA".

Possibly related PRs

Suggested labels

automerge, deploy-feature

Suggested reviewers

  • rafnarnason
  • oddsson
  • Toti91

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.44%. Comparing base (c4b4548) to head (301eb10).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16694   +/-   ##
=======================================
  Coverage   36.44%   36.44%           
=======================================
  Files        6853     6852    -1     
  Lines      143479   143478    -1     
  Branches    40949    40949           
=======================================
+ Hits        52285    52290    +5     
+ Misses      91194    91188    -6     
Flag Coverage Δ
air-discount-scheme-backend 54.06% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 37.02% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.60% <ø> (ø)
api-domains-criminal-record 47.48% <ø> (ø)
api-domains-driving-license 44.47% <ø> (ø)
api-domains-education 30.55% <ø> (ø)
api-domains-health-insurance 34.33% <ø> (ø)
api-domains-mortgage-certificate 34.68% <ø> (ø)
api-domains-payment-schedule 41.25% <ø> (ø)
application-api-files 62.45% <ø> (ø)
application-core 70.98% <ø> (+0.23%) ⬆️
application-system-api 40.97% <ø> (ø)
application-template-api-modules 27.63% <ø> (-0.02%) ⬇️
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.26% <ø> (ø)
application-templates-estate 12.15% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.22% <ø> (ø)
application-templates-parental-leave 29.83% <ø> (+0.11%) ⬆️
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.82% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 30.20% <ø> (ø)
auth-react 21.84% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.20% <ø> (ø)
clients-driving-license-book 43.44% <ø> (ø)
clients-financial-statements-inao 48.98% <ø> (ø)
clients-license-client 1.26% <ø> (ø)
clients-middlewares 72.88% <ø> (-0.26%) ⬇️
clients-regulations 42.27% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.19% <ø> (ø)
clients-zendesk 50.37% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 38.89% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.14% <ø> (ø)
contentful-apps 4.69% <ø> (ø)
dokobit-signing 62.58% <ø> (ø)
download-service 44.24% <ø> (ø)
email-service 60.41% <ø> (ø)
feature-flags 90.47% <ø> (ø)
file-storage 45.86% <ø> (ø)
financial-aid-backend 51.26% <ø> (ø)
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.62% <ø> (ø)
judicial-system-audit-trail 68.70% <ø> (ø)
judicial-system-backend 55.18% <ø> (ø)
judicial-system-formatters 79.13% <ø> (ø)
judicial-system-message 66.86% <ø> (ø)
judicial-system-message-handler 47.81% <ø> (ø)
judicial-system-scheduler 70.47% <ø> (ø)
judicial-system-types 43.99% <ø> (ø)
judicial-system-web 27.51% <ø> (ø)
license-api 42.50% <ø> (-0.08%) ⬇️
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 68.58% <ø> (+0.78%) ⬆️
nest-audit 68.20% <ø> (ø)
nest-aws 54.03% <ø> (ø)
nest-config 77.87% <ø> (ø)
nest-core 43.54% <ø> (ø)
nest-feature-flags 50.96% <ø> (ø)
nest-problem 45.82% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 61.90% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.89% <ø> (ø)
reference-backend 49.74% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 52.47% <ø> (ø)
services-auth-delegation-api 58.26% <ø> (+0.06%) ⬆️
services-auth-ids-api 52.08% <ø> (+0.01%) ⬆️
services-auth-personal-representative 45.55% <ø> (-0.01%) ⬇️
services-auth-personal-representative-public 41.64% <ø> (-0.12%) ⬇️
services-auth-public-api 49.56% <ø> (ø)
services-documents 60.81% <ø> (ø)
services-endorsements-api 53.34% <ø> (ø)
services-sessions 65.35% <ø> (-0.05%) ⬇️
services-university-gateway 49.34% <ø> (+0.02%) ⬆️
services-user-notification 46.85% <ø> (ø)
services-user-profile 61.84% <ø> (ø)
shared-components 26.88% <ø> (ø)
shared-form-fields 31.24% <ø> (ø)
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 fae12b4...301eb10. 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.

libs/testing/e2e/src/lib/utils/pageHelpers.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/support/i18n.ts Show resolved Hide resolved
libs/testing/e2e/src/index.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/support/locator-helpers.ts Outdated Show resolved Hide resolved
libs/testing/e2e/src/lib/support/locator-helpers.ts Outdated 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
libs/testing/e2e/src/lib/support/session.ts Show resolved Hide resolved
@datadog-island-is
Copy link

datadog-island-is bot commented Nov 1, 2024

Datadog Report

All test runs b99995b 🔗

101 Total Test Services: 0 Failed, 98 Passed
🔻 Test Sessions change in coverage: 4 decreased, 3 increased, 193 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 32.31s N/A Link
air-discount-scheme-web 0 0 0 2 0 8.82s N/A Link
api 0 0 0 4 0 3.05s N/A Link
api-catalogue-services 0 0 0 23 0 12.93s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 20.74s N/A Link
api-domains-assets 0 0 0 3 0 13.46s N/A Link
api-domains-auth-admin 0 0 0 18 0 14.77s N/A Link
api-domains-communications 0 0 0 5 0 34.39s N/A Link
api-domains-criminal-record 0 0 0 5 0 10.08s N/A Link
api-domains-driving-license 0 0 0 23 0 35.68s N/A Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • testing-e2e - jest 0% (-66.66%) - Details
  • clients-middlewares - jest 75.62% (-0.1%) - Details
  • services-auth-personal-representative-public - jest 40.99% (-0.04%) - Details
  • license-api - jest 33.89% (-0.02%) - Details

@svanaeinars svanaeinars requested a review from a team as a code owner November 11, 2024 15:52
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 (1)
.github/CODEOWNERS (1)

389-391: LGTM! Consider adding a descriptive comment.

The ownership assignments for E2E testing directories to the QA team are appropriate and well-structured. For consistency with other sections in the file that have detailed comments, consider adding a brief description of the QA team's responsibilities.

 # QA
+# QA team is responsible for end-to-end testing infrastructure and implementation
 /apps/system-e2e/                                                                                        @island-is/qa
 /libs/testing/e2e                                                                                        @island-is/qa
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f723214 and 6f48213.

📒 Files selected for processing (1)
  • .github/CODEOWNERS (1 hunks)

@svanaeinars svanaeinars requested a review from a team as a code owner November 12, 2024 09:08
Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

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

LGTM

@svanaeinars svanaeinars added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Nov 12, 2024
Copy link
Member

@baering baering left a comment

Choose a reason for hiding this comment

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

Core files LGTM

@svanaeinars svanaeinars added the automerge Merge this PR as soon as all checks pass label Nov 12, 2024
@kodiakhq kodiakhq bot merged commit c769f00 into main Nov 12, 2024
261 checks passed
@kodiakhq kodiakhq bot deleted the feat/testing-e2e-library-updates branch November 12, 2024 18:29
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* Add functions and documentation to testing/e2e

* Address codeRabbit suggestions and fix linting error

* Fixes + update @nx/playwright version

* Rearrange files in testing/e2e/src/lib

* Update import

* Make QA codeowners of testing/e2e

* Revert codeowners change

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
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.

4 participants