Files
AppFlowy-Web/cypress/e2e/database/datetime-column.cy.ts
2025-11-17 13:19:36 +08:00

130 lines
4.9 KiB
TypeScript

import {
AddPageSelectors,
DatabaseGridSelectors,
DateTimeSelectors,
PropertyMenuSelectors,
GridFieldSelectors,
FieldType,
waitForReactUpdate
} from '../../support/selectors';
import { AuthTestUtils } from '../../support/auth-utils';
import { generateRandomEmail } from '../../support/test-config';
describe('DateTime Column Type', () => {
beforeEach(() => {
cy.on('uncaught:exception', (err) => {
if (err.message.includes('Minified React error') ||
err.message.includes('View not found') ||
err.message.includes('No workspace or service found')) {
return false;
}
return true;
});
cy.viewport(1280, 720);
});
it('should create grid with datetime column and interact with date cells', () => {
const testEmail = generateRandomEmail();
cy.log(`[TEST START] Testing datetime column - Test email: ${testEmail}`);
// Login
cy.log('[STEP 1] Visiting login page');
cy.visit('/login', { failOnStatusCode: false });
cy.wait(2000);
const authUtils = new AuthTestUtils();
cy.log('[STEP 2] Starting authentication');
authUtils.signInWithTestUrl(testEmail).then(() => {
cy.log('[STEP 3] Authentication successful');
cy.url({ timeout: 30000 }).should('include', '/app');
cy.wait(3000);
// Create a new grid
cy.log('[STEP 4] Creating new grid');
AddPageSelectors.inlineAddButton().first().should('be.visible').click();
waitForReactUpdate(1000);
AddPageSelectors.addGridButton().should('be.visible').click();
cy.wait(8000);
// Verify grid exists
cy.log('[STEP 5] Verifying grid exists');
DatabaseGridSelectors.grid().should('exist');
// Verify cells exist
cy.log('[STEP 6] Verifying cells exist');
DatabaseGridSelectors.cells().should('exist');
// Add new column
cy.log('[STEP 7] Adding new column by clicking new property button');
PropertyMenuSelectors.newPropertyButton().should('be.visible');
PropertyMenuSelectors.newPropertyButton().first().scrollIntoView().click({ force: true });
waitForReactUpdate(3000);
// The new column is created and the property menu should be open automatically
// Let's wait for property trigger to be available
cy.log('[STEP 8] Waiting for property menu to open');
PropertyMenuSelectors.propertyTypeTrigger().then($trigger => {
if ($trigger.length > 0) {
cy.log('[STEP 9] Property type trigger found, changing to DateTime');
cy.wrap($trigger.first()).click({ force: true });
waitForReactUpdate(1000);
cy.log('[STEP 10] Selecting DateTime option');
PropertyMenuSelectors.propertyTypeOption(FieldType.DateTime).click({ force: true });
waitForReactUpdate(2000);
} else {
cy.log('[STEP 9] Property type trigger not found, looking for field header');
GridFieldSelectors.allFieldHeaders().last().scrollIntoView().click({ force: true });
waitForReactUpdate(1000);
PropertyMenuSelectors.propertyTypeTrigger().first().click({ force: true });
waitForReactUpdate(1000);
cy.log('[STEP 10] Selecting DateTime option');
PropertyMenuSelectors.propertyTypeOption(FieldType.DateTime).click({ force: true });
waitForReactUpdate(2000);
}
});
// Close any open menus
cy.log('[STEP 11] Closing menus');
cy.get('body').type('{esc}{esc}');
waitForReactUpdate(1000);
// Verify datetime cells exist
cy.log('[STEP 12] Checking for datetime cells');
DateTimeSelectors.allDateTimeCells().then($cells => {
if ($cells.length > 0) {
cy.log(`[STEP 13] Found ${$cells.length} datetime cells`);
DateTimeSelectors.allDateTimeCells().first().scrollIntoView().click({ force: true });
waitForReactUpdate(1000);
DateTimeSelectors.dateTimePickerPopover().then($popover => {
if ($popover.length > 0) {
cy.log('[STEP 14] DateTime picker opened successfully');
const today = new Date();
const dateStr = `${(today.getMonth() + 1).toString().padStart(2, '0')}/${today.getDate().toString().padStart(2, '0')}/${today.getFullYear()}`;
cy.log(`[STEP 15] Entering date: ${dateStr}`);
DateTimeSelectors.dateTimeDateInput().clear().type(dateStr);
DateTimeSelectors.dateTimeDateInput().type('{enter}');
waitForReactUpdate(1000);
cy.log('[STEP 16] Date entered successfully');
} else {
cy.log('[STEP 14] DateTime picker did not open, but column was created');
}
});
} else {
cy.log('[STEP 13] DateTime cells not found, but column creation was attempted');
}
});
cy.log('[STEP 17] DateTime column test completed');
});
});
});