From 24d46493a4f9a56aa5fb3836210ffff140971f68 Mon Sep 17 00:00:00 2001 From: annie Date: Wed, 3 Sep 2025 15:50:57 +0800 Subject: [PATCH] chore: fix test --- cypress/e2e/page/create-delete-page.cy.ts | 6 +++--- cypress/e2e/page/more-page-action.cy.ts | 10 +++++----- cypress/e2e/page/publish-page.cy.ts | 11 ++++++----- cypress/e2e/user/user.cy.ts | 8 ++++---- package.json | 3 --- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cypress/e2e/page/create-delete-page.cy.ts b/cypress/e2e/page/create-delete-page.cy.ts index 9222b547..3103f985 100644 --- a/cypress/e2e/page/create-delete-page.cy.ts +++ b/cypress/e2e/page/create-delete-page.cy.ts @@ -1,7 +1,7 @@ import { v4 as uuidv4 } from 'uuid'; import { AuthTestUtils } from '../../support/auth-utils'; import { TestTool } from '../../support/page-utils'; -import { PageSelectors, ModalSelectors, waitForReactUpdate } from '../../support/selectors'; +import { PageSelectors, ModalSelectors, SidebarSelectors, waitForReactUpdate } from '../../support/selectors'; describe('Page Create and Delete Tests', () => { const APPFLOWY_BASE_URL = Cypress.env('APPFLOWY_BASE_URL'); @@ -48,10 +48,10 @@ describe('Page Create and Delete Tests', () => { cy.get('body', { timeout: 30000 }).should('not.contain', 'Welcome!'); // Wait for the sidebar to be visible (indicates app is loaded) - cy.get('[data-testid="sidebar-page-header"]', { timeout: 30000 }).should('be.visible'); + SidebarSelectors.pageHeader().should('be.visible', { timeout: 30000 }); // Wait for at least one page to exist in the sidebar - cy.get('[data-testid="page-name"]', { timeout: 30000 }).should('exist'); + PageSelectors.names().should('exist', { timeout: 30000 }); // Additional wait for stability cy.wait(2000); diff --git a/cypress/e2e/page/more-page-action.cy.ts b/cypress/e2e/page/more-page-action.cy.ts index aff5beb1..32e25ed6 100644 --- a/cypress/e2e/page/more-page-action.cy.ts +++ b/cypress/e2e/page/more-page-action.cy.ts @@ -54,8 +54,8 @@ describe('More Page Actions', () => { cy.wait(1000); - // Look for any three-dot menu or more actions button - cy.get('[data-testid*="more"]').first().click({ force: true }); + // Look for the more actions button - using PageSelectors + PageSelectors.moreActionsButton().first().click({ force: true }); cy.task('log', 'Clicked more actions button'); @@ -108,8 +108,8 @@ describe('More Page Actions', () => { cy.wait(1000); - // Look for any three-dot menu or more actions button - cy.get('[data-testid*="more"]').first().click({ force: true }); + // Look for the more actions button - using PageSelectors + PageSelectors.moreActionsButton().first().click({ force: true }); cy.task('log', 'Clicked more actions button'); @@ -127,7 +127,7 @@ describe('More Page Actions', () => { cy.contains('Getting started').should('exist'); // Check if there's a duplicated page (might have a suffix like "(1)" or "(copy)") - cy.get('[data-testid="page-name"]').then($pages => { + PageSelectors.names().then($pages => { const pageCount = $pages.filter((index, el) => el.textContent?.includes('Getting started')).length; expect(pageCount).to.be.at.least(1); diff --git a/cypress/e2e/page/publish-page.cy.ts b/cypress/e2e/page/publish-page.cy.ts index bee30cdf..787fb553 100644 --- a/cypress/e2e/page/publish-page.cy.ts +++ b/cypress/e2e/page/publish-page.cy.ts @@ -1,6 +1,7 @@ import { v4 as uuidv4 } from 'uuid'; import { AuthTestUtils } from '../../support/auth-utils'; import { TestTool } from '../../support/page-utils'; +import { SidebarSelectors, PageSelectors, ModalSelectors, SpaceSelectors } from '../../support/selectors'; describe('Publish Page Test', () => { const APPFLOWY_BASE_URL = Cypress.env('APPFLOWY_BASE_URL'); @@ -37,8 +38,8 @@ describe('Publish Page Test', () => { // Wait for app to fully load cy.task('log', 'Waiting for app to fully load...'); - cy.get('[data-testid="sidebar-page-header"]', { timeout: 30000 }).should('be.visible'); - cy.get('[data-testid="page-name"]', { timeout: 30000 }).should('exist'); + SidebarSelectors.pageHeader().should('be.visible', { timeout: 30000 }); + PageSelectors.names().should('exist', { timeout: 30000 }); cy.wait(2000); // 2. create a new page called publish page @@ -47,13 +48,13 @@ describe('Publish Page Test', () => { cy.task('log', 'Creating page without content (template issue workaround)'); // Click new page button - cy.get('[data-testid="new-page-button"]').should('be.visible').click(); + PageSelectors.newPageButton().should('be.visible').click(); cy.wait(1000); // Handle the new page modal - cy.get('[data-testid="new-page-modal"]').should('be.visible').within(() => { + ModalSelectors.newPageModal().should('be.visible').within(() => { // Select the first available space - cy.get('[data-testid="space-item"]').first().click(); + SpaceSelectors.items().first().click(); cy.wait(500); // Click Add button cy.contains('button', 'Add').click(); diff --git a/cypress/e2e/user/user.cy.ts b/cypress/e2e/user/user.cy.ts index 346a2ccc..456494de 100644 --- a/cypress/e2e/user/user.cy.ts +++ b/cypress/e2e/user/user.cy.ts @@ -1,7 +1,7 @@ import { v4 as uuidv4 } from 'uuid'; import { AuthTestUtils } from '../../support/auth-utils'; import { TestTool } from '../../support/page-utils'; -import { WorkspaceSelectors } from '../../support/selectors'; +import { WorkspaceSelectors, SidebarSelectors, PageSelectors } from '../../support/selectors'; describe('User Feature Tests', () => { const APPFLOWY_BASE_URL = Cypress.env('APPFLOWY_BASE_URL'); @@ -59,13 +59,13 @@ describe('User Feature Tests', () => { cy.get('body', { timeout: 30000 }).should('not.contain', 'Welcome!'); // Wait for the sidebar to be visible (indicates app is loaded) - cy.get('[data-testid="sidebar-page-header"]', { timeout: 30000 }).should('be.visible'); + SidebarSelectors.pageHeader().should('be.visible', { timeout: 30000 }); // Wait for at least one page to exist in the sidebar - cy.get('[data-testid="page-name"]', { timeout: 30000 }).should('exist'); + PageSelectors.names().should('exist', { timeout: 30000 }); // Wait for workspace dropdown to be available - cy.get('[data-testid="workspace-dropdown-trigger"]', { timeout: 30000 }).should('be.visible'); + WorkspaceSelectors.dropdownTrigger().should('be.visible', { timeout: 30000 }); cy.task('log', 'App fully loaded'); diff --git a/package.json b/package.json index f59b2255..938b67ed 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,6 @@ "test:cy": "cypress run", "test:integration": "cypress run --spec 'cypress/e2e/**/*.cy.ts'", "test:integration:user": "cypress run --spec 'cypress/e2e/user/**/*.cy.ts' --headed --browser chrome", - "test:integration:page:create-delete": "cypress run --spec 'cypress/e2e/page/create-delete-page.cy.ts'", - "test:integration:page:edit": "cypress run --spec 'cypress/e2e/page/edit-page.cy.ts' --headed --browser chrome", - "test:integration:publish": "cypress run --spec 'cypress/e2e/publish/**/*.cy.ts'", "wait:backend": "APPFLOWY_BASE_URL=${APPFLOWY_BASE_URL:-http://localhost} node scripts/wait-for-backend.js", "coverage": "cross-env COVERAGE=true pnpm run test:unit && cross-env COVERAGE=true pnpm run test:components", "generate-tokens": "node scripts/system-token/convert-tokens.cjs",