-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Keep cell selected by objectId and field name after data browser refresh (#2631) #3252
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
Open
evolvomind
wants to merge
6
commits into
parse-community:alpha
Choose a base branch
from
evolvomind:feat/keep-correct-cell-selected-after-refresh
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+283
−1
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e78a46
feat: Keep cell selected by objectId and field name after data browse…
evolvomind df0cf51
feat: Keep cell selected by objectId and field name after data browse…
evolvomind dde3985
fix: replaced mock test with Puppetear E2E test
evolvomind ae2ea48
Merge branch 'alpha' into feat/keep-correct-cell-selected-after-refresh
evolvomind 471177c
fix: E2E use evaluate() for cell attributes
evolvomind 845c3c2
Apply suggestion from @coderabbitai[bot]
evolvomind 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
Some comments aren't visible on the classic Files Changed page.
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
225 changes: 225 additions & 0 deletions
225
src/lib/tests/e2e/DataBrowser.pendingRestore.e2e.test.js
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,225 @@ | ||
| /* | ||
| * Copyright (c) 2016-present, Parse, LLC | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the license found in the LICENSE file in | ||
| * the root directory of this source tree. | ||
| */ | ||
|
|
||
| /** | ||
| * E2E tests for the Data Browser "pendingRestore" feature: the selected cell | ||
| * (by objectId and field name) is restored after a refresh. These tests drive | ||
| * the real Parse Server, Dashboard, and DataBrowser in a browser so we | ||
| * exercise the actual componentDidUpdate path instead of a mock. | ||
| * | ||
| * To run the full e2e (with Parse Server and MongoDB): | ||
| * MONGODB_URI=mongodb://localhost:27017/pending_restore_e2e \ | ||
| * NODE_OPTIONS=--experimental-vm-modules \ | ||
| * npx jest --testPathPatterns=DataBrowser.pendingRestore.e2e --forceExit | ||
| * | ||
| * Without MongoDB or the flag, the tests are skipped and pass (no assertions run). | ||
| */ | ||
|
|
||
| jest.disableAutomock(); | ||
| jest.setTimeout(60_000); | ||
|
|
||
| const express = require('express'); | ||
| const ParseServer = require('parse-server').ParseServer; | ||
| const ParseDashboard = require('../../../../Parse-Dashboard/app'); | ||
| const puppeteer = require('puppeteer'); | ||
| const Parse = require('parse/node'); | ||
|
|
||
| const APP_ID = 'pendingRestoreE2EAppId'; | ||
| const MASTER_KEY = 'masterKeyE2E'; | ||
| const SERVER_PORT = 5150; | ||
| const DASH_PORT = 5151; | ||
| const SERVER_URL = `http://localhost:${SERVER_PORT}/parse`; | ||
| const MOUNT = '/dashboard'; | ||
| const DASH_URL = `http://localhost:${DASH_PORT}${MOUNT}`; | ||
| const CLASS_NAME = 'PendingRestoreE2ETest'; | ||
|
|
||
| let parseServerInstance; | ||
| let parseHttpServer; | ||
| let dashboardServer; | ||
| let browser; | ||
|
|
||
| async function startParseServer() { | ||
| const api = new ParseServer({ | ||
| databaseURI: process.env.MONGODB_URI || 'mongodb://localhost:27017/pending_restore_e2e', | ||
| appId: APP_ID, | ||
| masterKey: MASTER_KEY, | ||
| serverURL: SERVER_URL, | ||
| }); | ||
| await api.start(); | ||
| const app = express(); | ||
| app.use('/parse', api.app); | ||
| return new Promise((resolve, reject) => { | ||
| parseHttpServer = app.listen(SERVER_PORT, () => { | ||
| parseServerInstance = api; | ||
| resolve(); | ||
| }); | ||
| parseHttpServer.on('error', reject); | ||
| }); | ||
| } | ||
|
|
||
| async function startDashboard() { | ||
| const dashApp = express(); | ||
| dashApp.use( | ||
| MOUNT, | ||
| ParseDashboard( | ||
| { | ||
| apps: [ | ||
| { | ||
| serverURL: SERVER_URL, | ||
| appId: APP_ID, | ||
| masterKey: MASTER_KEY, | ||
| appName: 'TestApp', | ||
| }, | ||
| ], | ||
| trustProxy: 1, | ||
| }, | ||
| { allowInsecureHTTP: true } | ||
| ) | ||
| ); | ||
| return new Promise((resolve, reject) => { | ||
| dashboardServer = dashApp.listen(DASH_PORT, resolve); | ||
| dashboardServer.on('error', reject); | ||
| }); | ||
| } | ||
|
|
||
| async function seedTestObject() { | ||
| Parse.initialize(APP_ID, undefined, MASTER_KEY); | ||
| Parse.serverURL = SERVER_URL; | ||
| const obj = new Parse.Object(CLASS_NAME); | ||
| obj.set('title', 'E2E Hello'); | ||
| obj.set('count', 42); | ||
| await obj.save(null, { useMasterKey: true }); | ||
| return obj.id; | ||
| } | ||
|
|
||
| let e2eSkipped = false; | ||
|
|
||
| function shouldSkipE2E(err) { | ||
| const msg = err && (err.message || err.toString()); | ||
| if ( | ||
| msg && | ||
| (msg.includes('connect ECONNREFUSED') || | ||
| msg.includes('MongoServerSelectionError') || | ||
| msg.includes('MongoNetworkError')) | ||
| ) { | ||
| console.warn('DataBrowser.pendingRestore e2e: MongoDB not available, skipping.'); | ||
| return true; | ||
| } | ||
| if (msg && msg.includes('experimental-vm-modules')) { | ||
| console.warn( | ||
| 'DataBrowser.pendingRestore e2e: Run with NODE_OPTIONS=--experimental-vm-modules and MongoDB for full e2e.' | ||
| ); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| beforeAll(async () => { | ||
| try { | ||
| await startParseServer(); | ||
| } catch (e) { | ||
| if (shouldSkipE2E(e)) { | ||
| e2eSkipped = true; | ||
| return; | ||
| } | ||
| throw e; | ||
| } | ||
| await startDashboard(); | ||
| Parse.initialize(APP_ID, undefined, MASTER_KEY); | ||
| Parse.serverURL = SERVER_URL; | ||
| browser = await puppeteer.launch({ args: ['--no-sandbox'] }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| if (browser) { | ||
| await browser.close(); | ||
| } | ||
| if (dashboardServer) { | ||
| await new Promise(resolve => dashboardServer.close(resolve)); | ||
| } | ||
| if (parseHttpServer) { | ||
| await new Promise(resolve => parseHttpServer.close(resolve)); | ||
| } | ||
| if (parseServerInstance && typeof parseServerInstance.handleShutdown === 'function') { | ||
| await parseServerInstance.handleShutdown(); | ||
| } | ||
| }); | ||
|
|
||
| describe('DataBrowser pendingRestore e2e', () => { | ||
| it('keeps the correct cell selected after a data refresh', async () => { | ||
| if (e2eSkipped || !parseServerInstance) { | ||
| return; | ||
| } | ||
| const objectId = await seedTestObject(); | ||
| const page = await browser.newPage(); | ||
|
|
||
| await page.goto(`${DASH_URL}/apps/TestApp/browser/${CLASS_NAME}`, { | ||
| waitUntil: 'networkidle2', | ||
| timeout: 15000, | ||
| }); | ||
|
|
||
| await page.waitForSelector('[data-object-id]', { timeout: 10000 }); | ||
|
|
||
| const cellSelector = `[data-object-id="${objectId}"][data-field="title"]`; | ||
| await page.waitForSelector(cellSelector, { timeout: 5000 }); | ||
| await page.click(cellSelector); | ||
|
|
||
| const hasCurrentBefore = (await page.$('[data-current-cell="true"]')) !== null; | ||
| expect(hasCurrentBefore).toBe(true); | ||
|
|
||
| const refreshByText = await page.$x("//a[.//span[text()='Refresh']]").then(nodes => nodes[0]); | ||
| expect(refreshByText).toBeTruthy(); | ||
| await refreshByText.click(); | ||
|
|
||
| await page.waitForSelector('[data-object-id]', { timeout: 10000 }); | ||
|
|
||
| const hasCurrentAfter = (await page.$('[data-current-cell="true"]')) !== null; | ||
| expect(hasCurrentAfter).toBe(true); | ||
|
|
||
| const currentCell = await page.$('[data-current-cell="true"]'); | ||
| expect(currentCell).toBeTruthy(); | ||
| const dataObjectId = await currentCell.getAttribute('data-object-id'); | ||
| const dataField = await currentCell.getAttribute('data-field'); | ||
| expect(dataObjectId).toBe(objectId); | ||
| expect(dataField).toBe('title'); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await page.close(); | ||
| }); | ||
|
|
||
| it('clears selection when the object no longer exists after refresh', async () => { | ||
| if (e2eSkipped || !parseServerInstance) { | ||
| return; | ||
| } | ||
| const objectId = await seedTestObject(); | ||
| const page = await browser.newPage(); | ||
|
|
||
| await page.goto(`${DASH_URL}/apps/TestApp/browser/${CLASS_NAME}`, { | ||
| waitUntil: 'networkidle2', | ||
| timeout: 15000, | ||
| }); | ||
| await page.waitForSelector('[data-object-id]', { timeout: 10000 }); | ||
|
|
||
| const cellSelector = `[data-object-id="${objectId}"][data-field="title"]`; | ||
| await page.waitForSelector(cellSelector, { timeout: 5000 }); | ||
| await page.click(cellSelector); | ||
|
|
||
| const obj = await new Parse.Query(CLASS_NAME).get(objectId, { useMasterKey: true }); | ||
| await obj.destroy({ useMasterKey: true }); | ||
|
|
||
| const refreshByText = await page.$x("//a[.//span[text()='Refresh']]").then(nodes => nodes[0]); | ||
| expect(refreshByText).toBeTruthy(); | ||
| await refreshByText.click(); | ||
|
|
||
| await page.waitForSelector('[data-object-id]', { timeout: 10000 }); | ||
|
|
||
| const anyCurrent = (await page.$('[data-current-cell="true"]')) !== null; | ||
| expect(anyCurrent).toBe(false); | ||
|
|
||
| await page.close(); | ||
| }); | ||
| }); | ||
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.