-
Notifications
You must be signed in to change notification settings - Fork 60
Fix pagination issue #2298
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
Merged
Merged
Fix pagination issue #2298
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
876b531
Add changes for Load more option to work
sindhuba 9dad75c
Remove localhost
sindhuba 50a244e
Add Mongo Pagination tests
sindhuba 1c34425
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba 865e9c9
Run npm format
sindhuba 90c694d
Fix error in tests
sindhuba de11ece
Cleanup CORSByPass
sindhuba bd3f4f5
Revert "Cleanup CORSByPass"
sindhuba 9505b2e
Merge remote-tracking branch 'origin/master' into users/sindhuba/fix-…
sindhuba 6f29330
Merge branch 'master' of https://github.com/Azure/cosmos-explorer int…
sindhuba cb42f78
Merge branch 'master' of https://github.com/Azure/cosmos-explorer int…
sindhuba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
| import { setupCORSBypass } from "../CORSBypass"; | ||
| import { DataExplorer, QueryTab, TestAccount, CommandBarButton, Editor } from "../fx"; | ||
| import { serializeMongoToJson } from "../testData"; | ||
|
|
||
| const databaseId = "test-e2etests-mongo-pagination"; | ||
| const collectionId = "test-coll-mongo-pagination"; | ||
| let explorer: DataExplorer = null!; | ||
|
|
||
| test.setTimeout(5 * 60 * 1000); | ||
|
|
||
| test.describe("Test Mongo Pagination", () => { | ||
| let queryTab: QueryTab; | ||
| let queryEditor: Editor; | ||
|
|
||
| test.beforeEach("Open query tab", async ({ page }) => { | ||
| await setupCORSBypass(page); | ||
| explorer = await DataExplorer.open(page, TestAccount.MongoReadonly); | ||
|
|
||
| const containerNode = await explorer.waitForContainerNode(databaseId, collectionId); | ||
| await containerNode.expand(); | ||
|
|
||
| const containerMenuNode = await explorer.waitForContainerDocumentsNode(databaseId, collectionId); | ||
| await containerMenuNode.openContextMenu(); | ||
| await containerMenuNode.contextMenuItem("New Query").click(); | ||
|
|
||
| queryTab = explorer.queryTab("tab0"); | ||
| queryEditor = queryTab.editor(); | ||
| await queryEditor.locator.waitFor({ timeout: 30 * 1000 }); | ||
| await queryTab.executeCTA.waitFor(); | ||
| await explorer.frame.getByTestId("NotificationConsole/ExpandCollapseButton").click(); | ||
| await explorer.frame.getByTestId("NotificationConsole/Contents").waitFor(); | ||
| }); | ||
|
|
||
| test("should execute a query and load more results", async ({ page }) => { | ||
| const query = "{}"; | ||
|
|
||
| await queryEditor.locator.click(); | ||
| await queryEditor.setText(query); | ||
|
|
||
| const executeQueryButton = explorer.commandBarButton(CommandBarButton.ExecuteQuery); | ||
| await executeQueryButton.click(); | ||
|
|
||
| // Wait for query execution to complete | ||
| await expect(queryTab.resultsView).toBeVisible({ timeout: 60000 }); | ||
| await expect(queryTab.resultsEditor.locator).toBeAttached({ timeout: 30000 }); | ||
|
|
||
| // Get initial results | ||
| const resultText = await queryTab.resultsEditor.text(); | ||
|
|
||
| if (!resultText || resultText.trim() === "" || resultText.trim() === "[]") { | ||
| throw new Error("Query returned no results - the collection appears to be empty"); | ||
| } | ||
|
|
||
| const resultData = serializeMongoToJson(resultText); | ||
|
|
||
| if (resultData.length === 0) { | ||
| throw new Error("Parsed results contain 0 documents - collection is empty"); | ||
| } | ||
|
|
||
| if (resultData.length < 100) { | ||
| expect(resultData.length).toBeGreaterThan(0); | ||
| return; | ||
| } | ||
|
|
||
| expect(resultData.length).toBe(100); | ||
|
|
||
| // Pagination test | ||
| let totalPagesLoaded = 1; | ||
| const maxLoadMoreAttempts = 10; | ||
|
|
||
| for (let loadMoreAttempts = 0; loadMoreAttempts < maxLoadMoreAttempts; loadMoreAttempts++) { | ||
| const loadMoreButton = queryTab.resultsView.getByText("Load more"); | ||
|
|
||
| try { | ||
| await expect(loadMoreButton).toBeVisible({ timeout: 5000 }); | ||
| } catch { | ||
| // Load more button not visible - pagination complete | ||
| break; | ||
| } | ||
|
|
||
| const beforeClickText = await queryTab.resultsEditor.text(); | ||
| const beforeClickHash = Buffer.from(beforeClickText || "") | ||
| .toString("base64") | ||
| .substring(0, 50); | ||
|
|
||
| await loadMoreButton.click(); | ||
|
|
||
| // Wait for content to update | ||
| let editorContentChanged = false; | ||
| for (let waitAttempt = 1; waitAttempt <= 3; waitAttempt++) { | ||
| await page.waitForTimeout(2000); | ||
|
|
||
| const currentEditorText = await queryTab.resultsEditor.text(); | ||
| const currentHash = Buffer.from(currentEditorText || "") | ||
| .toString("base64") | ||
| .substring(0, 50); | ||
|
|
||
| if (currentHash !== beforeClickHash) { | ||
| editorContentChanged = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (editorContentChanged) { | ||
| totalPagesLoaded++; | ||
| } else { | ||
| // No content change detected, stop pagination | ||
| break; | ||
| } | ||
|
|
||
| await page.waitForTimeout(1000); | ||
| } | ||
|
|
||
| // Final verification | ||
| const finalIndicator = queryTab.resultsView.locator("text=/\\d+ - \\d+/"); | ||
| const finalIndicatorText = await finalIndicator.textContent(); | ||
|
|
||
| if (finalIndicatorText) { | ||
| const match = finalIndicatorText.match(/(\d+) - (\d+)/); | ||
| if (match) { | ||
| const totalDocuments = parseInt(match[2]); | ||
| expect(totalDocuments).toBe(405); | ||
| expect(totalPagesLoaded).toBe(5); | ||
| } else { | ||
| throw new Error(`Invalid results indicator format: ${finalIndicatorText}`); | ||
| } | ||
| } else { | ||
| expect(totalPagesLoaded).toBe(5); | ||
| } | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.