-
Notifications
You must be signed in to change notification settings - Fork 715
test: unflattened testcases #4704
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
Conversation
WalkthroughThe pull request introduces changes to the Playwright UI testing workflow by adding a new test file, Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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 suggestionsMake 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.testfilenamearray 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.testfilenamearray. 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-testsLength 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
selectStreamAndStreamTypeForLogsfunction is well-structured and uses appropriate selectors.
61-65: Verify the regular expression.The
removeUTFCharactersfunction 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
applyQueryButtonfunction is well-structured and uses appropriate assertions.
78-90: LGTM!The
beforeEachhook is correctly set up and performs the necessary actions before each test case.
There was a problem hiding this 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
logfromconsole.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.,
fillLoginUserIdinstead offill).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 theingestionfunction.
- Add proper error handling using
try-catchblocks 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
selectStreamAndStreamTypeForLogsSearchto better describe its purpose.- Rename the
streamparameter tostreamNamefor 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-catchblocks to catch and log any errors that may occur during the query application process.- Rename the
searchvariable tosearchResponsefor 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
allsearchvariable declaration before theselectStreamAndStreamTypeForLogsfunction call to ensure the response is captured.- Rename the
allsearchvariable toallSearchResponsefor 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
📒 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 suggestionsMake 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 objectiveThe addition of "unflattened.spec.js" to the
testfilenamearray 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)
| function removeUTFCharacters(text) { | ||
| // console.log(text, "tex"); | ||
| // Remove UTF characters using regular expression | ||
| return text.replace(/[^\x00-\x7F]/g, " "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
| 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(); | ||
| }); |
There was a problem hiding this comment.
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.,
clickStreamDetailButtoninstead ofclick). - 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.
Summary by CodeRabbit
New Features
Bug Fixes