Skip to content

Conversation

@neha00290
Copy link
Contributor

@neha00290 neha00290 commented Oct 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new suite of UI tests for a logging application, enhancing testing coverage.
    • Added functionality to automate user login and data ingestion processes within the tests.
    • Implemented a test case to toggle settings and verify UI interactions.
  • Bug Fixes

    • Expanded the test file list to include additional scenarios for more comprehensive testing.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The pull request introduces changes to the Playwright UI testing workflow by adding a new test file, unflattened.spec.js, to the configuration in .github/workflows/playwright.yml. This addition expands the testing coverage for the UI of a logging application. The new test file contains a suite of tests that automate user interactions and data ingestion processes. No other significant changes were made to the workflow structure or environment variables.

Changes

File Path Change Summary
.github/workflows/playwright.yml Updated the testfilename array in the ui_integration_tests job to include unflattened.spec.js.
tests/ui-testing/playwright-tests/unflattened.spec.js Introduced a new Playwright test suite for a logging application, including login and data ingestion tests.

Possibly related PRs

  • test: testcases for visualization functionality #4061: The changes in this PR also involve updates to the .github/workflows/playwright.yml file, specifically expanding the list of test files in the workflow configuration, similar to the addition of unflattened.spec.js in the main PR.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
tests/ui-testing/playwright-tests/unflattened.spec.js (3)

9-22: Consider extracting environment variables.

The login function is well-structured and follows the correct flow. However, consider extracting the environment variables into constants at the top of the file for better readability and maintainability.


24-50: Consider using a separate configuration file.

The ingestion function is correctly implemented. However, consider moving the configuration variables (e.g., headers, URLs) to a separate configuration file to improve code organization and maintainability.


92-132: Consider adding more assertions.

The test case 'stream to toggle store original data toggle and display o2 id' is comprehensive and covers the required user interactions. However, consider adding more assertions to verify the expected behavior and state of the application after each significant interaction.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ea4b759 and b898b48.

📒 Files selected for processing (2)
  • .github/workflows/playwright.yml (1 hunks)
  • tests/ui-testing/playwright-tests/unflattened.spec.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/ui-testing/playwright-tests/unflattened.spec.js (1)

Pattern **/*.js: You are a smart javascript/typescript pull request reviewer.
You are going to review all the javascript/typescript files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🪛 Biome
tests/ui-testing/playwright-tests/unflattened.spec.js

[error] 64-64: Unexpected control character(s) in regular expression: \x00

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

🔇 Additional comments (7)
.github/workflows/playwright.yml (1)

87-87: LGTM! New test file added to UI integration tests.

The addition of "unflattened.spec.js" to the matrix.testfilename array is correct and aligns with the PR objective. This change will include the new unflattened testcases in the UI integration test suite, enhancing overall test coverage.

To ensure the new test file exists and is properly located, run the following script:

✅ Verification successful

Verification Successful!

The new test file "unflattened.spec.js" exists in the specified directory and is properly included in the matrix.testfilename array. The addition enhances test coverage as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the new test file

# Test: Check if the new test file exists
fd -t f "unflattened.spec.js" tests/ui-testing/playwright-tests

Length of output: 117

tests/ui-testing/playwright-tests/unflattened.spec.js (6)

1-5: LGTM!

The imports are correctly defined and follow the proper syntax.


6-7: LGTM!

The configuration for parallel mode and the dynamic stream name generation are appropriate.


52-57: LGTM!

The selectStreamAndStreamTypeForLogs function is well-structured and uses appropriate selectors.


61-65: Verify the regular expression.

The removeUTFCharacters function uses a regular expression to remove non-ASCII characters. However, the regular expression [^\x00-\x7F] includes a control character \x00, which is flagged as suspicious by the static analysis tool.

Verify if the regular expression is intended to include the null character \x00. If not, consider updating the regular expression to [^\x01-\x7F] to exclude control characters.

🧰 Tools
🪛 Biome

[error] 64-64: Unexpected control character(s) in regular expression: \x00

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)


66-76: LGTM!

The applyQueryButton function is well-structured and uses appropriate assertions.


78-90: LGTM!

The beforeEach hook is correctly set up and performs the necessary actions before each test case.

@neha00290 neha00290 merged commit 2b13a4c into main Oct 4, 2024
@neha00290 neha00290 deleted the e2e-unflattened-tests branch October 4, 2024 03:30
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: 2

🧹 Outside diff range and nitpick comments (7)
tests/ui-testing/playwright-tests/unflattened.spec.js (7)

1-5: Organize imports and remove unused imports.

  • Group imports by type (e.g., external libraries, internal modules) and sort them alphabetically within each group for better readability.
  • Remove the unused import log from console.

Apply this diff to organize imports and remove unused imports:

-import { test, expect } from "@playwright/test";
-import logData from "../../ui-testing/cypress/fixtures/log.json";
-import { log } from "console";
-import logsdata from "../../test-data/logs_data.json";
+import { expect, test } from "@playwright/test";
+
+import logData from "../../ui-testing/cypress/fixtures/log.json";
+import logsdata from "../../test-data/logs_data.json";

6-6: Consider using more descriptive test configuration.

The test configuration { mode: 'parallel' } is not very descriptive. Consider adding a comment to explain the purpose of this configuration or using a more descriptive configuration object.

// Run tests in parallel mode for faster execution
test.describe.configure({ mode: 'parallel' });

9-22: Extract selectors and use more descriptive variable names.

  • Extract selectors into constants for better readability and maintainability.
  • Use more descriptive variable names for the page object methods (e.g., fillLoginUserId instead of fill).

Apply this diff to extract selectors and use more descriptive variable names:

async function login(page) {
  await page.goto(process.env["ZO_BASE_URL"]);
  //  await page.getByText('Login as internal user').click();
  await page.waitForTimeout(1000);
-  await page
-    .locator('[data-cy="login-user-id"]')
-    .fill(process.env["ZO_ROOT_USER_EMAIL"]);
+  const loginUserIdSelector = '[data-cy="login-user-id"]';
+  await page.locator(loginUserIdSelector).fillLoginUserId(process.env["ZO_ROOT_USER_EMAIL"]);
  //Enter Password
  await page.locator('label').filter({ hasText: 'Password *' }).click();
-  await page
-    .locator('[data-cy="login-password"]')
-    .fill(process.env["ZO_ROOT_USER_PASSWORD"]);
+  const loginPasswordSelector = '[data-cy="login-password"]';
+  await page.locator(loginPasswordSelector).fillLoginPassword(process.env["ZO_ROOT_USER_PASSWORD"]);
-  await page.locator('[data-cy="login-sign-in"]').click();
+  const loginSignInSelector = '[data-cy="login-sign-in"]';
+  await page.locator(loginSignInSelector).clickSignIn();
}

24-50: Improve error handling and logging in the ingestion function.

  • Add proper error handling using try-catch blocks to catch and log any errors that may occur during the ingestion process.
  • Log the response status code and message for better debugging.

Apply this diff to improve error handling and logging:

async function ingestion(page) {
  const orgId = process.env["ORGNAME"];
  const streamName = "e2e_automate";
  const basicAuthCredentials = Buffer.from(
    `${process.env["ZO_ROOT_USER_EMAIL"]}:${process.env["ZO_ROOT_USER_PASSWORD"]}`
  ).toString('base64');

  const headers = {
    "Authorization": `Basic ${basicAuthCredentials}`,
    "Content-Type": "application/json",
  };
-  const response = await page.evaluate(async ({ url, headers, orgId, streamName, logsdata }) => {
-    const fetchResponse = await fetch(`${url}/api/${orgId}/${streamName}/_json`, {
-      method: 'POST',
-      headers: headers,
-      body: JSON.stringify(logsdata)
-    });
-    return await fetchResponse.json();
-  }, {
-    url: process.env.INGESTION_URL,
-    headers: headers,
-    orgId: orgId,
-    streamName: streamName,
-    logsdata: logsdata
-  });
-  console.log(response);
+  try {
+    const response = await page.evaluate(async ({ url, headers, orgId, streamName, logsdata }) => {
+      const fetchResponse = await fetch(`${url}/api/${orgId}/${streamName}/_json`, {
+        method: 'POST',
+        headers: headers,
+        body: JSON.stringify(logsdata)
+      });
+      return await fetchResponse.json();
+    }, {
+      url: process.env.INGESTION_URL,
+      headers: headers,
+      orgId: orgId,
+      streamName: streamName,
+      logsdata: logsdata
+    });
+    console.log(`Ingestion response: ${response.status} - ${response.statusText}`);
+  } catch (error) {
+    console.error(`Ingestion error: ${error.message}`);
+    throw error;
+  }
}

52-57: Use more descriptive function and variable names.

  • Rename the function to selectStreamAndStreamTypeForLogsSearch to better describe its purpose.
  • Rename the stream parameter to streamName for clarity.

Apply this diff to use more descriptive names:

-const selectStreamAndStreamTypeForLogs = async (page, stream) => {
+const selectStreamAndStreamTypeForLogsSearch = async (page, streamName) => {
  await page.waitForTimeout(
    4000); await page.locator(
      '[data-test="log-search-index-list-select-stream"]').click({ force: true }); await page.locator(
-        "div.q-item").getByText(`${stream}`).first().click({ force: true });
+        "div.q-item").getByText(`${streamName}`).first().click({ force: true });
};

66-76: Improve error handling and use more descriptive variable names.

  • Add proper error handling using try-catch blocks to catch and log any errors that may occur during the query application process.
  • Rename the search variable to searchResponse for clarity.

Apply this diff to improve error handling and use more descriptive names:

async function applyQueryButton(page) {
  // click on the run query button
  // Type the value of a variable into an input field
-  const search = page.waitForResponse(logData.applyQuery);
+  const searchResponse = page.waitForResponse(logData.applyQuery);
  await page.waitForTimeout(3000);
-  await page.locator("[data-test='logs-search-bar-refresh-btn']").click({
-    force: true,
-  });
+  try {
+    await page.locator("[data-test='logs-search-bar-refresh-btn']").click({
+      force: true,
+    });
+  } catch (error) {
+    console.error(`Error clicking refresh button: ${error.message}`);
+    throw error;
+  }
  // get the data from the search variable
-  await expect.poll(async () => (await search).status()).toBe(200);
+  await expect.poll(async () => (await searchResponse).status()).toBe(200);
}

78-90: Improve test setup and use more descriptive variable names.

  • Move the allsearch variable declaration before the selectStreamAndStreamTypeForLogs function call to ensure the response is captured.
  • Rename the allsearch variable to allSearchResponse for clarity.

Apply this diff to improve test setup and use more descriptive names:

test.beforeEach(async ({ page }) => {
  await login(page);
  await page.waitForTimeout(1000)
  await ingestion(page);
  await page.waitForTimeout(2000)

  await page.goto(
    `${logData.logsUrl}?org_identifier=${process.env["ORGNAME"]}`
  );
-  const allsearch = page.waitForResponse("**/api/default/_search**");
+  const allSearchResponse = page.waitForResponse("**/api/default/_search**");
  await selectStreamAndStreamTypeForLogs(page, logData.Stream);
  await applyQueryButton(page);
+  await allSearchResponse;
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ea4b759 and b898b48.

📒 Files selected for processing (2)
  • .github/workflows/playwright.yml (1 hunks)
  • tests/ui-testing/playwright-tests/unflattened.spec.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/ui-testing/playwright-tests/unflattened.spec.js (1)

Pattern **/*.js: You are a smart javascript/typescript pull request reviewer.
You are going to review all the javascript/typescript files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

🪛 Biome
tests/ui-testing/playwright-tests/unflattened.spec.js

[error] 64-64: Unexpected control character(s) in regular expression: \x00

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

🔇 Additional comments (2)
.github/workflows/playwright.yml (1)

87-87: LGTM: Addition of unflattened testcase aligns with PR objective

The addition of "unflattened.spec.js" to the testfilename array in the matrix strategy is appropriate and directly addresses the PR objective of adding unflattened testcases. This change will ensure that the new unflattened testcases are executed as part of the UI integration tests.

tests/ui-testing/playwright-tests/unflattened.spec.js (1)

61-65: ****

🧰 Tools
🪛 Biome

[error] 64-64: Unexpected control character(s) in regular expression: \x00

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

Comment on lines +61 to +65
function removeUTFCharacters(text) {
// console.log(text, "tex");
// Remove UTF characters using regular expression
return text.replace(/[^\x00-\x7F]/g, " ");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using control characters in regular expressions.

The regular expression /[^\x00-\x7F]/g contains control characters (\x00-\x7F), which can lead to unexpected behavior and make the code less readable.

Consider using a more readable and maintainable regular expression to remove non-ASCII characters:

function removeNonAsciiCharacters(text) {
  return text.replace(/[^\u0000-\u007F]/g, " ");
}
🧰 Tools
🪛 Biome

[error] 64-64: Unexpected control character(s) in regular expression: \x00

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

Comment on lines +92 to +132
test('stream to toggle store orginal data toggle and display o2 id', async ({ page }) => {
await page.locator('[data-test="menu-link-\\/streams-item"]').click();
await page.getByPlaceholder('Search Stream').click();
await page.getByPlaceholder('Search Stream').fill('e2e_automate');
await page.getByRole('button', { name: 'Stream Detail' }).first().click();
await page.locator('[data-test="log-stream-store-original-data-toggle-btn"] div').nth(2).click();
await page.locator('[data-test="schema-update-settings-button"]').click();
await page.waitForTimeout(1000);
await ingestion(page);
await page.waitForTimeout(2000);
await page.locator('button').filter({ hasText: 'close' }).click();
await page.getByRole('button', { name: 'Explore' }).first().click();
await page.waitForTimeout(1000);
await page.locator('[data-test="date-time-btn"]').click();
await page.locator('[data-test="date-time-relative-tab"]').click();
await page.waitForTimeout(2000);
await page.locator('[data-test="log-table-column-1-_timestamp"] [data-test="table-row-expand-menu"]').click();
await page.locator('[data-test="log-table-column-0-source"]').click()
await page.waitForTimeout(1000);
await page.locator('[data-test="log-detail-json-content"] [data-test="log-expand-detail-key-_o2_id-text"]').click();
await page.locator('[data-test="log-detail-json-content"] [data-test="tab-unflattened"]').click();
await page.waitForTimeout(1000);
await page.locator('[data-test="close-dialog"]').click();
await page.locator('[data-test="menu-link-\\/streams-item"]').click();
await page.getByPlaceholder('Search Stream').click();
await page.getByPlaceholder('Search Stream').fill('e2e_automate');
await page.getByRole('button', { name: 'Stream Detail' }).first().click();
await page.locator('[data-test="log-stream-store-original-data-toggle-btn"] div').nth(2).click();
await page.locator('[data-test="schema-update-settings-button"]').click();
await page.locator('button').filter({ hasText: 'close' }).click();
await page.waitForTimeout(1000);
await ingestion(page);
await page.waitForTimeout(2000);
await page.getByRole('button', { name: 'Explore' }).first().click();
await page.waitForTimeout(3000);
await page.locator('[data-test="date-time-btn"]').click();
await page.locator('[data-test="date-time-relative-tab"]').click();
await page.waitForTimeout(2000);
await page.locator('[data-test="log-table-column-1-_timestamp"] [data-test="table-row-expand-menu"]').click();
await page.getByText('arrow_drop_down_timestamp:').click();
});
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

Improve test structure and use more descriptive variable names.

  • Break down the test into smaller, focused test cases for better readability and maintainability.
  • Use more descriptive variable names for the page object methods (e.g., clickStreamDetailButton instead of click).
  • Add comments to explain the purpose of each test step.

Apply this diff to improve test structure and use more descriptive names:

-test('stream to toggle store orginal data toggle and display o2 id', async ({ page }) => {
+test('toggle store original data and display o2 id for a stream', async ({ page }) => {
+  // Navigate to the streams page
  await page.locator('[data-test="menu-link-\\/streams-item"]').click();
+  // Search for the "e2e_automate" stream
  await page.getByPlaceholder('Search Stream').click();
  await page.getByPlaceholder('Search Stream').fill('e2e_automate');
-  await page.getByRole('button', { name: 'Stream Detail' }).first().click();
+  await page.getByRole('button', { name: 'Stream Detail' }).first().clickStreamDetailButton();
+  // Toggle the "store original data" setting
  await page.locator('[data-test="log-stream-store-original-data-toggle-btn"] div').nth(2).click();
-  await page.locator('[data-test="schema-update-settings-button"]').click();
+  await page.locator('[data-test="schema-update-settings-button"]').clickUpdateSettingsButton();
  await page.waitForTimeout(1000);
+  // Ingest data and close the stream detail modal
  await ingestion(page);
  await page.waitForTimeout(2000);
-  await page.locator('button').filter({ hasText: 'close' }).click();
+  await page.locator('button').filter({ hasText: 'close' }).clickCloseButton();
+  // Navigate to the explore page and expand the first log entry
-  await page.getByRole('button', { name: 'Explore' }).first().click();
+  await page.getByRole('button', { name: 'Explore' }).first().clickExploreButton();
  await page.waitForTimeout(1000);
  await page.locator('[data-test="date-time-btn"]').click();
  await page.locator('[data-test="date-time-relative-tab"]').click();
  await page.waitForTimeout(2000);
  await page.locator('[data-test="log-table-column-1-_timestamp"] [data-test="table-row-expand-menu"]').click();
+  // Display the o2 id in the unflattened view
  await page.locator('[data-test="log-table-column-0-source"]').click()
  await page.waitForTimeout(1000);
  await page.locator('[data-test="log-detail-json-content"] [data-test="log-expand-detail-key-_o2_id-text"]').click();
  await page.locator('[data-test="log-detail-json-content"] [data-test="tab-unflattened"]').click();
  await page.waitForTimeout(1000);
-  await page.locator('[data-test="close-dialog"]').click();
+  await page.locator('[data-test="close-dialog"]').clickCloseDialog();
+  // Toggle off the "store original data" setting
  await page.locator('[data-test="menu-link-\\/streams-item"]').click();
  await page.getByPlaceholder('Search Stream').click();
  await page.getByPlaceholder('Search Stream').fill('e2e_automate');
-  await page.getByRole('button', { name: 'Stream Detail' }).first().click();
+  await page.getByRole('button', { name: 'Stream Detail' }).first().clickStreamDetailButton();
  await page.locator('[data-test="log-stream-store-original-data-toggle-btn"] div').nth(2).click();
-  await page.locator('[data-test="schema-update-settings-button"]').click();
-  await page.locator('button').filter({ hasText: 'close' }).click();
+  await page.locator('[data-test="schema-update-settings-button"]').clickUpdateSettingsButton();
+  await page.locator('button').filter({ hasText: 'close' }).clickCloseButton();
  await page.waitForTimeout(1000);
+  // Ingest data and verify the o2 id is not displayed
  await ingestion(page);
  await page.waitForTimeout(2000);
-  await page.getByRole('button', { name: 'Explore' }).first().click();
+  await page.getByRole('button', { name: 'Explore' }).first().clickExploreButton();
  await page.waitForTimeout(3000);
  await page.locator('[data-test="date-time-btn"]').click();
  await page.locator('[data-test="date-time-relative-tab"]').click();
  await page.waitForTimeout(2000);
  await page.locator('[data-test="log-table-column-1-_timestamp"] [data-test="table-row-expand-menu"]').click();
  await page.getByText('arrow_drop_down_timestamp:').click();
});

Committable suggestion was skipped due to low confidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants