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

chore(tests): E2E lib comments and cleanup #16856

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 13, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new modular exports for improved organization of testing utilities.
    • Added new functions for verifying request completion, managing user authentication, and creating applications.
    • Implemented internationalization support and enhanced element locator utilities.
  • Bug Fixes

    • Improved error handling and response validation in session management and GraphQL mocking.
  • Documentation

    • Updated documentation for configuration and utility functions to enhance clarity.
  • Chores

    • Removed deprecated support files to streamline the codebase.

@svanaeinars svanaeinars requested a review from a team as a code owner November 13, 2024 15:48
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes in this pull request involve a comprehensive restructuring of the exports in the libs/testing/e2e/src/index.ts file, transitioning from a support and utils structure to a more modular organization with categories such as helpers, modules, and session. Additionally, several new utility functions and modules have been introduced, while others have been deleted, enhancing the overall functionality for end-to-end testing.

Changes

File Path Change Summary
libs/testing/e2e/src/index.ts Removed exports from support modules and added exports from helpers, modules, and session.
libs/testing/e2e/src/lib/config/playwright-config.ts Renamed createGlobalConfig to createPlaywrightConfig and updated its documentation. Modified the reporter field and restructured the projects array.
libs/testing/e2e/src/lib/helpers/api-tools.ts Added verifyRequestCompletion, an async function for verifying network responses.
libs/testing/e2e/src/lib/helpers/locator-helpers.ts Introduced functions for locating elements based on roles and test IDs, including locatorByRole, findByRole, findByTestId, and proceed.
libs/testing/e2e/src/lib/helpers/utils.ts Added utility functions: sleep, createMockPdf, deleteMockPdf, and debug.
libs/testing/e2e/src/lib/modules/application.ts Added createApplication, an async function for creating applications based on existing data.
libs/testing/e2e/src/lib/modules/disablers.ts Introduced mocking functionality for GraphQL requests, including mockGraphQL, disableTranslations, and disableDelegations.
libs/testing/e2e/src/lib/modules/i18n.ts Added internationalization functionality using @formatjs/intl with a label function.
libs/testing/e2e/src/lib/modules/urls.ts Restructured and documented functions related to URL handling, including shouldSkipNavigation and getEnvironmentBaseUrl.
libs/testing/e2e/src/lib/session/email-account.ts Updated import path for debug and maintained existing functionality for email account registration.
libs/testing/e2e/src/lib/session/login.ts Introduced user authentication functions for AWS Cognito and IDS login, including cognitoLogin, idsLogin, and switchUser.
libs/testing/e2e/src/lib/session/session.ts Added session management functions for handling authentication checks.
libs/testing/e2e/src/lib/support/addons.ts Deleted file containing custom matchers for Playwright.
libs/testing/e2e/src/lib/support/api-tools.ts Deleted file with utility functions for handling GraphQL requests.
libs/testing/e2e/src/lib/support/application.ts Deleted file containing a function for creating applications.
libs/testing/e2e/src/lib/support/disablers.ts Deleted file with mocking functions for GraphQL operations.
libs/testing/e2e/src/lib/support/i18n.ts Deleted file with internationalization functionality.
libs/testing/e2e/src/lib/support/login.ts Deleted file with user authentication functions.
libs/testing/e2e/src/lib/support/session.ts Deleted file managing user sessions.
libs/testing/e2e/src/lib/support/utils.ts Deleted file with utility functions for testing.
libs/testing/e2e/src/lib/utils/locator-helpers.ts Deleted file containing locator utility functions.
libs/testing/e2e/src/lib/utils/pageHelpers.ts Deleted file with functions for generating CSS selectors for form elements.

Suggested labels

automerge

Suggested reviewers

  • rafnarnason

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 force-pushed the chore/e2e-improvements-config-and-structure branch from f1c592f to 681b5b7 Compare November 13, 2024 16:10
@svanaeinars svanaeinars changed the title chore: E2E lib comments and cleanup chore(tests): E2E lib comments and cleanup Nov 13, 2024
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: 14

🧹 Outside diff range and nitpick comments (26)
libs/testing/e2e/src/lib/modules/i18n.ts (1)

15-16: Add JSDoc documentation for better developer experience

The label function is well-implemented, but adding documentation would improve its usability.

Consider adding JSDoc:

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

2-2: Module organization promotes better reusability.

The separation of core modules improves maintainability and allows for better tree-shaking when importing specific functionality.

Consider documenting the purpose of each module category in the README to help other developers understand when to use each type of utility.

Also applies to: 3-3, 5-5, 9-9

libs/testing/e2e/src/lib/helpers/api-tools.ts (1)

3-10: Consider enhancing the documentation with examples and error scenarios.

While the current documentation is clear, it would be more helpful with:

  • An example usage snippet
  • Description of error scenarios (e.g., timeout, network failures)
 /**
  * Waits for a network request to complete and verifies its operation name.
  *
  * @param page - The Playwright Page object to interact with.
  * @param url - The URL substring to match the request.
  * @param op - The operation name to verify in the request's post data.
  * @returns A promise that resolves to the JSON response of the matched request.
+ * @throws {TimeoutError} When the request doesn't complete within the default timeout
+ * @example
+ * ```typescript
+ * const response = await verifyRequestCompletion(page, '/graphql', 'GetUser');
+ * expect(response.data.user).toBeDefined();
+ * ```
  */
libs/testing/e2e/src/lib/modules/application.ts (1)

3-12: Consider enhancing the documentation.

While the documentation is comprehensive, it could be even more helpful with:

  • An example usage snippet
  • More specific description of the return value (e.g., "Returns the count of applications that existed before the creation attempt")
 /**
  * Creates a new application if there are existing applications on the overview page.
  *
  * This function waits for the applications to load on the overview page by waiting for a
  * specific GraphQL response. It then counts the number of existing applications. If there
  * are existing applications, it clicks the button to create a new application.
  *
+ * @example
+ * ```typescript
+ * const existingCount = await createApplication(page);
+ * console.log(`There were ${existingCount} applications before creation`);
+ * ```
+ *
  * @param page - The Playwright Page object representing the browser page.
- * @returns The number of existing applications.
+ * @returns The count of applications that existed before the creation attempt.
  */
libs/testing/e2e/src/lib/helpers/utils.ts (3)

10-10: Add input validation for sleep duration

The sleep function should validate the input to ensure it's a positive number.

Consider adding validation:

-export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
+export const sleep = (ms: number) => {
+  if (ms < 0) throw new Error('Sleep duration must be non-negative')
+  return new Promise((r) => setTimeout(r, ms))
+}

45-47: Extract debug namespace to a constant

The debug namespace 'system-e2e' should be defined as a constant for better maintainability.

Consider this improvement:

+const DEBUG_NAMESPACE = 'system-e2e'
+
 export const debug = (msg: string, ...args: unknown[]) => {
-  debuglog('system-e2e')(msg, ...args)
+  debuglog(DEBUG_NAMESPACE)(msg, ...args)
 }

1-47: Consider creating a dedicated test file manager

Instead of individual PDF file operations, consider creating a TestFileManager class to handle test file operations more robustly:

  • Manage temporary test directories
  • Track created files for cleanup
  • Provide type-safe file operations

Would you like me to provide an example implementation of a TestFileManager class?

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

3-3: Consider expanding the Roles type to include more ARIA roles

The current Roles type is limited to 'heading', 'button', and 'radio'. Consider expanding it to include other common ARIA roles like 'textbox', 'checkbox', 'link', 'combobox', etc., to make the helper more versatile.

-type Roles = 'heading' | 'button' | 'radio'
+type Roles =
+  | 'button'
+  | 'checkbox'
+  | 'combobox'
+  | 'heading'
+  | 'link'
+  | 'radio'
+  | 'textbox'

1-55: Consider organizing helpers by functionality

While the current implementation is good, consider splitting these helpers into more specific categories:

  • Role-based helpers (locatorByRole, findByRole)
  • Test ID helpers (findByTestId)
  • Action helpers (proceed)

This would improve maintainability and make it easier to add more helpers in the future.

libs/testing/e2e/src/lib/modules/urls.ts (3)

28-32: Consider using JSDoc format for the comment block

While the comment is clear, converting it to JSDoc format would provide better IDE integration and documentation generation.

-// This set of query params is used to hide the onboarding modal as well as force locale to Icelandic.
-// Useful if you need to test something that is using Icelandic labels, for example.
+/**
+ * Query parameters to hide the onboarding modal and force Icelandic locale.
+ * Useful for testing components with Icelandic labels.
+ */

42-46: Add input validation for the authority parameter

The function should validate that the authority parameter is a non-empty string to prevent potential runtime errors.

 export const getEnvironmentBaseUrl = (authority: string) => {
+  if (!authority?.trim()) {
+    throw new Error('Authority parameter must be a non-empty string')
+  }
   const baseUrlPrefix = process.env.BASE_URL_PREFIX ?? ''
   const prefix =
     baseUrlPrefix && baseUrlPrefix !== 'main' ? `${baseUrlPrefix}-` : ''
   return `https://${prefix}${authority}`
 }

98-104: Optimize URL lookup using Set

Consider using a Set for better lookup performance, especially if this function is called frequently during tests.

-export const shouldSkipNavigation = (url: string) =>
-  [
-    JUDICIAL_SYSTEM_COA_JUDGE_HOME_URL,
-    JUDICIAL_SYSTEM_DEFENDER_HOME_URL,
-    JUDICIAL_SYSTEM_HOME_URL,
-    JUDICIAL_SYSTEM_JUDGE_HOME_URL,
-  ].includes(url)
+const SKIP_NAVIGATION_URLS = new Set([
+  JUDICIAL_SYSTEM_COA_JUDGE_HOME_URL,
+  JUDICIAL_SYSTEM_DEFENDER_HOME_URL,
+  JUDICIAL_SYSTEM_HOME_URL,
+  JUDICIAL_SYSTEM_JUDGE_HOME_URL,
+])
+export const shouldSkipNavigation = (url: string) => SKIP_NAVIGATION_URLS.has(url)
libs/testing/e2e/src/lib/session/email-account.ts (2)

Line range hint 74-156: Consider improving error handling and configuration.

Several improvements could enhance the robustness and maintainability of the code:

  1. Add error handling for file system operations
  2. Extract configuration values to constants or environment variables
  3. Consider making retry delay configurable

Here's a suggested improvement:

+ const CONFIG = {
+   AWS_REGION: process.env.AWS_REGION || 'eu-west-1',
+   IMAP_AUTH_TIMEOUT: 10000,
+   RETRY_DELAY_MS: 5000,
+ }

- const client = new SESClient({ region: 'eu-west-1' })
+ const client = new SESClient({ region: CONFIG.AWS_REGION })

  const emailConfig = {
    imap: {
      user: testAccount.user,
      password: testAccount.pass,
      host: 'imap.ethereal.email',
      port: 993,
      tls: true,
-     authTimeout: 10000,
+     authTimeout: CONFIG.IMAP_AUTH_TIMEOUT,
    },
  }

  // Add error handling for file operations
  try {
    writeFileSync(
      storagePath,
      JSON.stringify({ user: testAccount.user, pass: testAccount.pass }),
      { encoding: 'utf-8' },
    )
  } catch (error) {
    debug('Failed to write email account to file:', error)
    throw new Error('Failed to persist email account')
  }

  // Use configured retry delay
- await new Promise((r) => setTimeout(r, 5000))
+ await new Promise((r) => setTimeout(r, CONFIG.RETRY_DELAY_MS))

Line range hint 1-156: Consider implementing a more robust email testing strategy.

While the current implementation works well for basic E2E testing, consider these architectural improvements:

  1. Implement a proper retry strategy with exponential backoff
  2. Consider using a connection pool for IMAP connections
  3. Add metrics/monitoring for email verification failures
  4. Consider implementing a cleanup strategy for old email accounts

These improvements would make the E2E testing infrastructure more reliable and maintainable.

libs/testing/e2e/src/lib/session/login.ts (5)

16-22: Provide more detailed error messages for missing credentials

Currently, the error message 'Cognito credentials missing' does not specify which credential is missing. Providing specific error messages can aid in debugging and improve user experience.

Apply this diff to enhance the error handling:

 const getCognitoCredentials = (): CognitoCreds => {
   const username = process.env.AWS_COGNITO_USERNAME
   const password = process.env.AWS_COGNITO_PASSWORD

-  if (!username || !password) throw new Error('Cognito credentials missing')
+  if (!username) throw new Error('Cognito username is missing')
+  if (!password) throw new Error('Cognito password is missing')

   return { username, password }
 }

41-44: Parameterize hardcoded Cognito URL for flexibility

The hardcoded URL 'https://ids-users.auth.eu-west-1.amazoncognito.com/' may lead to maintenance issues if the URL changes or varies across environments. Consider parameterizing this URL to improve adaptability.

Apply this diff to introduce a configurable Cognito URL:

 import { expect, Page } from '@playwright/test'
 import { urls, shouldSkipNavigation } from '../modules/urls'
 import { debug } from '../helpers/utils'

+const cognitoBaseUrl = process.env.COGNITO_BASE_URL ?? 'https://ids-users.auth.eu-west-1.amazoncognito.com/'

 export type CognitoCreds = {
   username: string

Update the condition to use the parameterized URL:

 if (
-  page.url().startsWith('https://ids-users.auth.eu-west-1.amazoncognito.com/')
+  page.url().startsWith(cognitoBaseUrl)
 ) {
   await page.getByRole('button', { name: 'ids-deprecated' }).click()
 }

Ensure that COGNITO_BASE_URL is set in the environment variables when necessary.


43-43: Use resilient selectors for interacting with UI elements

The button name 'ids-deprecated' is hardcoded, which may cause tests to break if the UI changes. Consider using a data attribute or a more stable selector.

For example, if possible, add a data-testid to the button in the application code:

<button data-testid="ids-deprecated-button">ids-deprecated</button>

Then update the test code:

- await page.getByRole('button', { name: 'ids-deprecated' }).click()
+ await page.locator('[data-testid="ids-deprecated-button"]').click()

97-100: Address the TODO: Implement accessible selectors

There's a TODO to use accessible selectors when the new login page is available. Using accessible selectors improves test reliability and aligns with best practices.

Would you like assistance in updating the selectors to use accessible roles now to prepare for the new login page?


137-138: Avoid hardcoding text for selectors to support localization

The button label 'Skipta um notanda' is hardcoded in Icelandic. If the application supports multiple languages, the test may fail in other locales. Consider using a language-independent selector.

For example, use a data-testid attribute:

- await page.getByRole('button', { name: 'Skipta um notanda' }).click()
+ await page.locator('[data-testid="switch-user-button"]').click()

Ensure the application code includes the data-testid attribute:

<button data-testid="switch-user-button">Skipta um notanda</button>
libs/testing/e2e/src/lib/modules/disablers.ts (3)

16-16: Remove unused useResponseKey option from MockGQLOptions

The useResponseKey property in MockGQLOptions is defined but not used anywhere in the code. Consider removing it to clean up the code.

Apply this diff to remove the unused option:

-  useResponseKey?: boolean

42-42: Pass deepPath when recursing into array elements in deepMock function

When recursing into array elements, deepPath is not being updated, which may affect debugging and tracking. Consider passing deepPath to maintain the correct path.

Apply this diff to include deepPath:

-      (item: T) => deepMock(item, mockKey, mockData, { exactMatch }) as T,
+      (item: T, index: number) =>
+        deepMock(item, mockKey, mockData, {
+          exactMatch,
+          deepPath: `${deepPath}[${index}]`,
+        }) as T,

59-59: Remove hardcoded debugging code for currentLic key

The conditional debug statement for 'currentLic' appears to be specific and may not be relevant in the generic deepMock function. Consider removing or generalizing it.

Apply this diff to remove the hardcoded debug statement:

-    if (key.match('currentLic')) debug('Mocking currentLic', original)
libs/testing/e2e/src/lib/session/session.ts (4)

21-39: Add explicit return type to function ensureCognitoSessionIfNeeded

Adding an explicit return type enhances type safety and code readability.

Apply this diff to specify the return type as Promise<void>:

 const ensureCognitoSessionIfNeeded = async (
   page: Page,
   homeUrl = '/',
   authUrlPrefix = '',
- ) => {
+ ): Promise<void> => {

29-33: Optimize URL retrieval by storing it in a variable

To avoid redundant calls to sessionCheck.url(), consider storing the URL in a variable.

Apply this diff to optimize the code:

+      const sessionCheckUrl = sessionCheck.url()
       if (
-        sessionCheck.url().startsWith('https://cognito.shared.devland.is/') ||
-        sessionCheck
-          .url()
-          .startsWith('https://ids-users.auth.eu-west-1.amazoncognito.com/')
+        sessionCheckUrl.startsWith('https://cognito.shared.devland.is/') ||
+        sessionCheckUrl.startsWith('https://ids-users.auth.eu-west-1.amazoncognito.com/')
       ) {

120-173: Add explicit return type to function session

Defining the return type improves type safety and clarity.

Apply this diff to specify the return type as Promise<BrowserContext>:

 export const session = async ({
   browser,
   homeUrl = '/',
   phoneNumber = '',
   authUrl = urls.authUrl,
   idsLoginOn = true,
   delegation = '',
   storageState = `playwright-sessions-${homeUrl}-${phoneNumber}`,
   authTrigger = homeUrl,
 }: {
   browser: Browser
   homeUrl?: string
   phoneNumber?: string
   authUrl?: string
   idsLoginOn?: boolean | { nextAuth?: { nextAuthRoot: string } }
   delegation?: string
   storageState?: string
   authTrigger?: string | ((page: Page) => Promise<string>)
- }) => {
+ }): Promise<BrowserContext> => {

184-203: Add explicit return type to function judicialSystemSession

Specifying the return type enhances code readability and type safety.

Apply this diff to define the return type as Promise<BrowserContext>:

 export const judicialSystemSession = async ({
   browser,
   homeUrl,
 }: {
   browser: Browser
   homeUrl?: string
- }) => {
+ }): Promise<BrowserContext> => {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f34424 and 681b5b7.

📒 Files selected for processing (22)
  • libs/testing/e2e/src/index.ts (1 hunks)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (3 hunks)
  • libs/testing/e2e/src/lib/helpers/api-tools.ts (1 hunks)
  • libs/testing/e2e/src/lib/helpers/locator-helpers.ts (1 hunks)
  • libs/testing/e2e/src/lib/helpers/utils.ts (1 hunks)
  • libs/testing/e2e/src/lib/modules/application.ts (1 hunks)
  • libs/testing/e2e/src/lib/modules/disablers.ts (1 hunks)
  • libs/testing/e2e/src/lib/modules/i18n.ts (1 hunks)
  • libs/testing/e2e/src/lib/modules/urls.ts (2 hunks)
  • libs/testing/e2e/src/lib/session/email-account.ts (2 hunks)
  • libs/testing/e2e/src/lib/session/login.ts (1 hunks)
  • libs/testing/e2e/src/lib/session/session.ts (1 hunks)
  • libs/testing/e2e/src/lib/support/addons.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/api-tools.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/application.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/disablers.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/i18n.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/login.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/session.ts (0 hunks)
  • libs/testing/e2e/src/lib/support/utils.ts (0 hunks)
  • libs/testing/e2e/src/lib/utils/locator-helpers.ts (0 hunks)
  • libs/testing/e2e/src/lib/utils/pageHelpers.ts (0 hunks)
💤 Files with no reviewable changes (10)
  • libs/testing/e2e/src/lib/support/addons.ts
  • libs/testing/e2e/src/lib/support/api-tools.ts
  • libs/testing/e2e/src/lib/support/application.ts
  • libs/testing/e2e/src/lib/support/disablers.ts
  • libs/testing/e2e/src/lib/support/i18n.ts
  • libs/testing/e2e/src/lib/support/login.ts
  • libs/testing/e2e/src/lib/support/session.ts
  • libs/testing/e2e/src/lib/support/utils.ts
  • libs/testing/e2e/src/lib/utils/locator-helpers.ts
  • libs/testing/e2e/src/lib/utils/pageHelpers.ts
🧰 Additional context used
📓 Path-based instructions (12)
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/config/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."
libs/testing/e2e/src/lib/helpers/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/helpers/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/helpers/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/modules/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/modules/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/modules/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/modules/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/session/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/session/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/session/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."
🔇 Additional comments (13)
libs/testing/e2e/src/lib/modules/i18n.ts (1)

1-3: LGTM! Well-structured imports and cache initialization

The code follows TypeScript best practices with explicit named imports and proper type usage.

libs/testing/e2e/src/index.ts (4)

11-11: Configuration is properly separated.

Moving Playwright configuration to a dedicated config module follows best practices for configuration management.


1-1: Helper utilities are now logically grouped.

The organization of helper utilities into a dedicated category improves code organization and discoverability.

Let's verify that the helper modules are properly isolated and don't have circular dependencies:

#!/bin/bash
# Description: Check for potential circular dependencies in helper modules

# Search for imports between helper modules
echo "Checking for circular dependencies in helper modules..."
for file in $(fd . libs/testing/e2e/src/lib/helpers -e ts); do
  echo "Analyzing $file:"
  rg -l "import.*from.*helpers" "$file"
done

Also applies to: 6-6, 10-10


1-11: Verify backward compatibility of the restructuring.

The reorganization of exports might affect existing imports in the codebase.

Let's check for potential breaking changes:

#!/bin/bash
# Description: Check for imports that might be affected by the restructuring

# Look for old import paths that might need updating
echo "Checking for potentially affected imports..."
rg "from.*testing/e2e.*support/" 

# Look for direct imports of removed files
echo "Checking for imports of removed files..."
rg "from.*testing/e2e.*(support/api-tools|support/application|support/disablers|support/email-account|support/i18n|support/locator-helpers|support/login|support/session|support/urls|support/utils)"

4-4: Session-related functionality is properly isolated.

Grouping session-related functionality (email-account, login, session) into a dedicated category improves code organization and makes the authentication flow more obvious.

Let's verify the session modules are properly isolated:

Also applies to: 7-7, 8-8

✅ Verification successful

Session-related functionality is properly isolated and well-organized

The verification confirms that the session-related functionality is properly isolated in the session directory with clear separation of concerns:

  • email-account.ts: Handles email account creation and management for testing
  • login.ts: Contains authentication-related functions (Cognito and IDS login)
  • session.ts: Manages browser sessions and authentication state

The code is well-structured with each file having a specific responsibility within the authentication flow, making the codebase more maintainable and the authentication process more obvious.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify session modules are properly isolated and contain authentication-related code

echo "Analyzing session-related code..."
rg -A 5 "login|auth|session" libs/testing/e2e/src/lib/session/

Length of output: 424


Script:

#!/bin/bash
# Let's check the actual content and structure of the session directory
echo "Checking session directory structure..."
fd . libs/testing/e2e/src/lib/session/ -t f

echo -e "\nChecking content of email-account file..."
cat libs/testing/e2e/src/lib/session/email-account.ts

echo -e "\nChecking imports of session-related modules..."
rg "from.*session" --type ts

Length of output: 21278


Script:

#!/bin/bash
# Let's check the content of other session-related files
echo "Checking login.ts content..."
cat libs/testing/e2e/src/lib/session/login.ts

echo -e "\nChecking session.ts content..."
cat libs/testing/e2e/src/lib/session/session.ts

Length of output: 11522

libs/testing/e2e/src/lib/helpers/api-tools.ts (2)

1-1: LGTM! Clean import with proper TypeScript usage.


1-23: Implementation follows coding guidelines.

✅ Reusable across different NextJS apps
✅ Proper TypeScript usage
✅ Effective tree-shaking support through named export

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

1-1: LGTM! Clean and specific import.

The import statement follows best practices by importing only the required type.


24-26: Verify successful application creation.

The function clicks the create button but doesn't verify if the creation was successful.

Consider:

  1. Waiting for a success notification or new application to appear
  2. Returning the new application's ID or details
  3. Adding a verification step to ensure the application count increased
libs/testing/e2e/src/lib/helpers/locator-helpers.ts (1)

28-34: LGTM! Well-structured implementation

The function is well-documented, type-safe, and effectively utilizes the locatorByRole helper.

libs/testing/e2e/src/lib/modules/urls.ts (1)

Line range hint 49-90: Verify the security implications of using dev auth URL in local environment

The local environment is configured to use the dev authentication URL (AuthUrl.local = dev). This might pose security risks if developers accidentally commit their local testing credentials.

libs/testing/e2e/src/lib/session/email-account.ts (2)

73-73: Well-structured TypeScript definitions!

The type definitions and exports are clear, well-structured, and follow TypeScript best practices. The EmailAccount type provides a good contract for consumers of this library.


16-16: Verify the consistency of import path changes.

The import path change aligns with the restructuring mentioned in the PR objectives. Let's verify that all imports of the debug utility have been updated consistently.

libs/testing/e2e/src/lib/modules/i18n.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/modules/i18n.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/helpers/api-tools.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/helpers/utils.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/modules/urls.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/modules/disablers.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/modules/disablers.ts Show resolved Hide resolved
libs/testing/e2e/src/lib/session/session.ts Show resolved Hide resolved
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)
libs/testing/e2e/src/lib/config/playwright-config.ts (1)

37-42: Simplify reporter configuration

The reporter configuration could be simplified to avoid type assertion and improve readability.

Consider this cleaner approach:

-    reporter: [
-      ...((process.env.CI
-        ? [['json', { outputFile: 'test-results.json' }]]
-        : [['dot']]) as ReporterDescription[]),
-      ['html', { open: 'never' }],
-    ],
+    reporter: [
+      process.env.CI
+        ? ['json', { outputFile: 'test-results.json' }]
+        : ['dot'],
+      ['html', { open: 'never' }],
+    ] as ReporterDescription[],
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 681b5b7 and 68fd7c6.

📒 Files selected for processing (2)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (1 hunks)
  • libs/testing/e2e/src/lib/helpers/locator-helpers.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/testing/e2e/src/lib/helpers/locator-helpers.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/testing/e2e/src/lib/config/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."
🔇 Additional comments (3)
libs/testing/e2e/src/lib/config/playwright-config.ts (3)

3-9: LGTM! Well-structured interface definition

The interface is well-defined with clear parameter types and proper optional parameter marking.


11-30: JSDoc parameters need updating

The previous review comment about correcting JSDoc parameter types is still applicable.


Line range hint 49-63: LGTM! Well-structured test organization and server configuration

The project configuration provides a clear separation of test categories, and the web server configuration properly handles conditional port and URL settings.

@svanaeinars svanaeinars added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 13, 2024
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

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.44%. Comparing base (b141441) to head (0740541).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16856   +/-   ##
=======================================
  Coverage   36.44%   36.44%           
=======================================
  Files        6852     6852           
  Lines      143567   143567           
  Branches    40973    40973           
=======================================
  Hits        52330    52330           
  Misses      91237    91237           
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 40.98% <ø> (ø)
application-template-api-modules 27.65% <ø> (+<0.01%) ⬆️
services-endorsements-api 53.23% <ø> (ø)

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


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 b141441...0740541. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs 0c35470 🔗

4 Total Test Services: 0 Failed, 4 Passed
➡️ Test Sessions change in coverage: 10 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.5s 1 no change Link
application-system-api 0 0 0 112 2 3m 41.97s 1 no change Link
application-template-api-modules 0 0 0 113 0 2m 46.56s 1 no change Link
services-endorsements-api 0 0 0 42 0 1m 5.41s 1 no change Link

@kodiakhq kodiakhq bot merged commit d1ffb29 into main Nov 14, 2024
47 checks passed
@kodiakhq kodiakhq bot deleted the chore/e2e-improvements-config-and-structure branch November 14, 2024 11:17
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* chore: E2E lib comments and cleanup

* Minor fixes

* Minor tweak

* Make JSON the reporter for e2e tests in CI

---------

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
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants