|
| 1 | +import 'cypress-real-events'; |
| 2 | +import { |
| 3 | + AuthSelectors, |
| 4 | + DatabaseGridSelectors, |
| 5 | + PageSelectors, |
| 6 | + SpaceSelectors, |
| 7 | + ViewActionSelectors, |
| 8 | + waitForReactUpdate, |
| 9 | +} from '../../support/selectors'; |
| 10 | +import { |
| 11 | + openRowDetail, |
| 12 | + closeRowDetailWithEscape, |
| 13 | + RowDetailSelectors, |
| 14 | +} from '../../support/row-detail-helpers'; |
| 15 | +import { TestConfig } from '../../support/test-config'; |
| 16 | + |
| 17 | +const _exportUserEmail = 'export_user@appflowy.io'; |
| 18 | +const _exportUserPassword = 'AppFlowy!@123'; |
| 19 | +const _testDatabaseName = 'Database 1'; |
| 20 | +const _spaceName = 'General'; |
| 21 | +const _gettingStartedPageName = 'Getting started'; |
| 22 | + |
| 23 | +/** |
| 24 | + * Expand a space in the sidebar by clicking on it if not already expanded |
| 25 | + */ |
| 26 | +function expandSpaceInSidebar(spaceNameToExpand: string) { |
| 27 | + cy.log(`[HELPER] Expanding space "${spaceNameToExpand}" in sidebar`); |
| 28 | + |
| 29 | + SpaceSelectors.itemByName(spaceNameToExpand, { timeout: 30000 }).then(($space) => { |
| 30 | + const expandedIndicator = $space.find('[data-testid="space-expanded"]'); |
| 31 | + const isExpanded = expandedIndicator.attr('data-expanded') === 'true'; |
| 32 | + |
| 33 | + if (!isExpanded) { |
| 34 | + SpaceSelectors.itemByName(spaceNameToExpand).find('[data-testid="space-name"]').click({ force: true }); |
| 35 | + waitForReactUpdate(1000); |
| 36 | + } |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * Expand a page in the sidebar by clicking its expand toggle if not already expanded |
| 42 | + */ |
| 43 | +function expandPageInSidebar(pageName: string) { |
| 44 | + cy.log(`[HELPER] Expanding page "${pageName}" in sidebar`); |
| 45 | + |
| 46 | + PageSelectors.itemByName(pageName, { timeout: 30000 }).then(($pageItem) => { |
| 47 | + const expandToggle = $pageItem.find('[data-testid="outline-toggle-expand"]'); |
| 48 | + if (expandToggle.length > 0) { |
| 49 | + cy.wrap(expandToggle).first().click({ force: true }); |
| 50 | + waitForReactUpdate(1000); |
| 51 | + } |
| 52 | + }); |
| 53 | +} |
| 54 | + |
| 55 | +describe('Cloud Database Duplication', () => { |
| 56 | + const { gotrueUrl } = TestConfig; |
| 57 | + |
| 58 | + beforeEach(() => { |
| 59 | + cy.on('uncaught:exception', (err) => { |
| 60 | + if ( |
| 61 | + err.message.includes('Minified React error') || |
| 62 | + err.message.includes('View not found') || |
| 63 | + err.message.includes('No workspace or service found') || |
| 64 | + err.message.includes('ResizeObserver loop') |
| 65 | + ) { |
| 66 | + return false; |
| 67 | + } |
| 68 | + return true; |
| 69 | + }); |
| 70 | + |
| 71 | + cy.viewport(1280, 720); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should duplicate Database 1 and verify data independence', () => { |
| 75 | + cy.log(`[TEST START] Testing cloud database duplication with: ${_exportUserEmail}`); |
| 76 | + |
| 77 | + // Step 1: Visit login page |
| 78 | + cy.log('[STEP 1] Visiting login page'); |
| 79 | + cy.visit('/login', { failOnStatusCode: false }); |
| 80 | + cy.wait(5000); |
| 81 | + |
| 82 | + // Step 2: Enter email |
| 83 | + cy.log('[STEP 2] Entering email address'); |
| 84 | + AuthSelectors.emailInput().should('be.visible', { timeout: 30000 }).type(_exportUserEmail); |
| 85 | + cy.wait(500); |
| 86 | + |
| 87 | + // Step 3: Click on "Sign in with password" button |
| 88 | + cy.log('[STEP 3] Clicking sign in with password button'); |
| 89 | + AuthSelectors.passwordSignInButton().should('be.visible').click(); |
| 90 | + cy.wait(1000); |
| 91 | + |
| 92 | + // Step 4: Verify we're on the password page |
| 93 | + cy.log('[STEP 4] Verifying password page loaded'); |
| 94 | + cy.url().should('include', 'action=enterPassword'); |
| 95 | + |
| 96 | + // Step 5: Enter password |
| 97 | + cy.log('[STEP 5] Entering password'); |
| 98 | + AuthSelectors.passwordInput().should('be.visible').type(_exportUserPassword); |
| 99 | + cy.wait(500); |
| 100 | + |
| 101 | + // Step 6: Submit password |
| 102 | + cy.log('[STEP 6] Submitting password for authentication'); |
| 103 | + AuthSelectors.passwordSubmitButton().should('be.visible').click(); |
| 104 | + |
| 105 | + // Step 7: Wait for successful login |
| 106 | + cy.log('[STEP 7] Waiting for successful login'); |
| 107 | + cy.url({ timeout: 30000 }).should('include', '/app'); |
| 108 | + |
| 109 | + // Step 8: Wait for the app to fully load |
| 110 | + cy.log('[STEP 8] Waiting for app to fully load'); |
| 111 | + cy.wait(5000); |
| 112 | + |
| 113 | + // Step 9: Wait for data sync (similar to desktop test's 30 second wait) |
| 114 | + cy.log('[STEP 9] Waiting for data sync'); |
| 115 | + // Wait for page list to appear |
| 116 | + PageSelectors.names({ timeout: 60000 }).should('exist'); |
| 117 | + cy.wait(5000); |
| 118 | + |
| 119 | + // Step 10: Delete any existing duplicate databases (cleanup) |
| 120 | + cy.log('[STEP 10] Cleaning up existing duplicate databases'); |
| 121 | + const copySuffix = ' (Copy)'; |
| 122 | + const duplicatePrefix = `${_testDatabaseName}${copySuffix}`; |
| 123 | + |
| 124 | + // Check and delete existing duplicates |
| 125 | + cy.get('body').then(($body) => { |
| 126 | + const duplicatePages = $body.find(`[data-testid="page-name"]:contains("${duplicatePrefix}")`); |
| 127 | + if (duplicatePages.length > 0) { |
| 128 | + cy.log(`[STEP 10.1] Found ${duplicatePages.length} existing duplicates, deleting them`); |
| 129 | + // Delete each duplicate found |
| 130 | + duplicatePages.each((index, el) => { |
| 131 | + const pageName = Cypress.$(el).text().trim(); |
| 132 | + if (pageName.startsWith(duplicatePrefix)) { |
| 133 | + PageSelectors.moreActionsButton(pageName).click({ force: true }); |
| 134 | + waitForReactUpdate(500); |
| 135 | + ViewActionSelectors.deleteButton().click({ force: true }); |
| 136 | + waitForReactUpdate(500); |
| 137 | + cy.get('body').then(($body2) => { |
| 138 | + if ($body2.find('[data-testid="confirm-delete-button"]').length > 0) { |
| 139 | + cy.get('[data-testid="confirm-delete-button"]').click({ force: true }); |
| 140 | + } |
| 141 | + }); |
| 142 | + waitForReactUpdate(1000); |
| 143 | + } |
| 144 | + }); |
| 145 | + } |
| 146 | + }); |
| 147 | + |
| 148 | + // Step 11: Expand the General space and Getting started, then open Database 1 |
| 149 | + cy.log('[STEP 11] Expanding General space and Getting started page'); |
| 150 | + expandSpaceInSidebar(_spaceName); |
| 151 | + waitForReactUpdate(1000); |
| 152 | + expandPageInSidebar(_gettingStartedPageName); |
| 153 | + waitForReactUpdate(1000); |
| 154 | + cy.log('[STEP 11.1] Opening Database 1'); |
| 155 | + PageSelectors.nameContaining(_testDatabaseName).first().click({ force: true }); |
| 156 | + waitForReactUpdate(3000); |
| 157 | + |
| 158 | + // Step 12: Wait for database grid to load |
| 159 | + cy.log('[STEP 12] Waiting for database grid to load'); |
| 160 | + DatabaseGridSelectors.grid({ timeout: 30000 }).should('exist'); |
| 161 | + waitForReactUpdate(2000); |
| 162 | + |
| 163 | + // Step 13: Count original rows |
| 164 | + cy.log('[STEP 13] Counting original rows'); |
| 165 | + let originalRowCount = 0; |
| 166 | + DatabaseGridSelectors.dataRows().then(($rows) => { |
| 167 | + originalRowCount = $rows.length; |
| 168 | + cy.log(`[STEP 13.1] Original database has ${originalRowCount} rows`); |
| 169 | + expect(originalRowCount).to.be.greaterThan(0, 'Expected rows in the source database'); |
| 170 | + }); |
| 171 | + |
| 172 | + // Step 14: Duplicate the database |
| 173 | + cy.log('[STEP 14] Duplicating the database'); |
| 174 | + PageSelectors.moreActionsButton(_testDatabaseName).click({ force: true }); |
| 175 | + waitForReactUpdate(500); |
| 176 | + |
| 177 | + cy.log('[STEP 14.1] Clicking duplicate button'); |
| 178 | + ViewActionSelectors.duplicateButton().should('be.visible').click(); |
| 179 | + waitForReactUpdate(3000); |
| 180 | + |
| 181 | + // Step 15: Wait for duplicate to appear in sidebar |
| 182 | + cy.log('[STEP 15] Waiting for duplicate to appear in sidebar'); |
| 183 | + PageSelectors.nameContaining(duplicatePrefix, { timeout: 90000 }).should('exist'); |
| 184 | + waitForReactUpdate(2000); |
| 185 | + |
| 186 | + // Step 16: Open the duplicated database |
| 187 | + cy.log('[STEP 16] Opening the duplicated database'); |
| 188 | + PageSelectors.nameContaining(duplicatePrefix).first().click({ force: true }); |
| 189 | + waitForReactUpdate(3000); |
| 190 | + |
| 191 | + // Step 17: Wait for duplicated database grid to load |
| 192 | + cy.log('[STEP 17] Waiting for duplicated database grid to load'); |
| 193 | + DatabaseGridSelectors.grid({ timeout: 30000 }).should('exist'); |
| 194 | + waitForReactUpdate(2000); |
| 195 | + |
| 196 | + // Step 18: Verify duplicated row count matches original |
| 197 | + cy.log('[STEP 18] Verifying duplicated row count'); |
| 198 | + DatabaseGridSelectors.dataRows().then(($rows) => { |
| 199 | + const duplicatedRowCount = $rows.length; |
| 200 | + cy.log(`[STEP 18.1] Duplicated database has ${duplicatedRowCount} rows`); |
| 201 | + expect(duplicatedRowCount).to.equal( |
| 202 | + originalRowCount, |
| 203 | + 'Duplicated database should preserve row count' |
| 204 | + ); |
| 205 | + }); |
| 206 | + |
| 207 | + // Step 19: Edit a cell in the duplicated database |
| 208 | + cy.log('[STEP 19] Editing a cell in the duplicated database'); |
| 209 | + const marker = `db-duplicate-marker-${Date.now()}`; |
| 210 | + |
| 211 | + DatabaseGridSelectors.cells().first().click(); |
| 212 | + waitForReactUpdate(500); |
| 213 | + cy.focused().clear(); |
| 214 | + cy.focused().type(marker); |
| 215 | + cy.focused().type('{enter}'); |
| 216 | + waitForReactUpdate(1000); |
| 217 | + |
| 218 | + // Step 20: Verify the marker was added |
| 219 | + cy.log('[STEP 20] Verifying marker was added to duplicated database'); |
| 220 | + DatabaseGridSelectors.cells().first().should('contain.text', marker); |
| 221 | + |
| 222 | + // Step 20.1: Open first row detail page and add marker to row document |
| 223 | + cy.log('[STEP 20.1] Opening first row detail page in duplicated database'); |
| 224 | + openRowDetail(0); |
| 225 | + waitForReactUpdate(1000); |
| 226 | + |
| 227 | + // Step 20.2: Verify document area exists |
| 228 | + cy.log('[STEP 20.2] Verifying document area exists in row detail'); |
| 229 | + RowDetailSelectors.documentArea().should('exist'); |
| 230 | + |
| 231 | + // Step 20.3: Add marker to row document |
| 232 | + const rowDocumentMarker = `row-doc-marker-${Date.now()}`; |
| 233 | + cy.log(`[STEP 20.3] Adding marker to row document: ${rowDocumentMarker}`); |
| 234 | + // Find the Slate editor within the row detail modal and type in it |
| 235 | + RowDetailSelectors.modal() |
| 236 | + .find('[data-slate-editor="true"]') |
| 237 | + .first() |
| 238 | + .scrollIntoView() |
| 239 | + .click({ force: true }) |
| 240 | + .type(rowDocumentMarker, { delay: 30, force: true }); |
| 241 | + waitForReactUpdate(1000); |
| 242 | + |
| 243 | + // Step 20.4: Verify the marker was added to row document |
| 244 | + cy.log('[STEP 20.4] Verifying marker was added to row document'); |
| 245 | + RowDetailSelectors.modal().should('contain.text', rowDocumentMarker); |
| 246 | + |
| 247 | + // Step 20.5: Close row detail |
| 248 | + cy.log('[STEP 20.5] Closing row detail page'); |
| 249 | + closeRowDetailWithEscape(); |
| 250 | + waitForReactUpdate(1000); |
| 251 | + |
| 252 | + // Step 21: Open the original database |
| 253 | + cy.log('[STEP 21] Opening the original database'); |
| 254 | + // Ensure space and Getting started are still expanded |
| 255 | + expandSpaceInSidebar(_spaceName); |
| 256 | + waitForReactUpdate(500); |
| 257 | + expandPageInSidebar(_gettingStartedPageName); |
| 258 | + waitForReactUpdate(500); |
| 259 | + // Find the original database by looking for elements containing "Database 1" but NOT "(Copy)" |
| 260 | + PageSelectors.nameContaining(_testDatabaseName) |
| 261 | + .filter((index, el) => { |
| 262 | + const text = Cypress.$(el).text().trim(); |
| 263 | + return !text.includes('(Copy)'); |
| 264 | + }) |
| 265 | + .first() |
| 266 | + .click({ force: true }); |
| 267 | + waitForReactUpdate(3000); |
| 268 | + |
| 269 | + // Step 22: Wait for original database grid to load |
| 270 | + cy.log('[STEP 22] Waiting for original database grid to load'); |
| 271 | + DatabaseGridSelectors.grid({ timeout: 30000 }).should('exist'); |
| 272 | + waitForReactUpdate(2000); |
| 273 | + |
| 274 | + // Step 23: Verify the marker is NOT in the original database |
| 275 | + cy.log('[STEP 23] Verifying cell marker is NOT in original database'); |
| 276 | + DatabaseGridSelectors.cells().then(($cells) => { |
| 277 | + let markerFound = false; |
| 278 | + $cells.each((index, cell) => { |
| 279 | + if (Cypress.$(cell).text().includes(marker)) { |
| 280 | + markerFound = true; |
| 281 | + return false; |
| 282 | + } |
| 283 | + }); |
| 284 | + |
| 285 | + expect(markerFound).to.equal( |
| 286 | + false, |
| 287 | + 'Original database should not contain duplicate cell edits' |
| 288 | + ); |
| 289 | + }); |
| 290 | + |
| 291 | + // Step 23.1: Open first row detail page in original database |
| 292 | + cy.log('[STEP 23.1] Opening first row detail page in original database'); |
| 293 | + openRowDetail(0); |
| 294 | + waitForReactUpdate(1000); |
| 295 | + |
| 296 | + // Step 23.2: Verify row document does NOT contain the marker |
| 297 | + cy.log('[STEP 23.2] Verifying row document marker is NOT in original database'); |
| 298 | + RowDetailSelectors.documentArea().then(($doc) => { |
| 299 | + const docText = $doc.text(); |
| 300 | + expect(docText).to.not.include( |
| 301 | + 'row-doc-marker-', |
| 302 | + 'Original row document should not contain duplicate edits' |
| 303 | + ); |
| 304 | + }); |
| 305 | + |
| 306 | + // Step 23.3: Close row detail |
| 307 | + cy.log('[STEP 23.3] Closing row detail page'); |
| 308 | + closeRowDetailWithEscape(); |
| 309 | + waitForReactUpdate(1000); |
| 310 | + |
| 311 | + // Step 24: Cleanup - delete the duplicated database |
| 312 | + cy.log('[STEP 24] Cleaning up - deleting duplicated database'); |
| 313 | + PageSelectors.nameContaining(duplicatePrefix).first().then(($el) => { |
| 314 | + const duplicateName = $el.text().trim(); |
| 315 | + PageSelectors.moreActionsButton(duplicateName).click({ force: true }); |
| 316 | + waitForReactUpdate(500); |
| 317 | + ViewActionSelectors.deleteButton().should('be.visible').click(); |
| 318 | + waitForReactUpdate(500); |
| 319 | + cy.get('body').then(($body) => { |
| 320 | + if ($body.find('[data-testid="confirm-delete-button"]').length > 0) { |
| 321 | + cy.get('[data-testid="confirm-delete-button"]').click({ force: true }); |
| 322 | + } |
| 323 | + }); |
| 324 | + }); |
| 325 | + |
| 326 | + cy.log('[STEP 25] Cloud database duplication test completed successfully'); |
| 327 | + }); |
| 328 | +}); |
0 commit comments