ITADN

Fix: Align data-testid values in tests after component refactoring

#7544Opencoderabbitai[bot] 创建于 2026-04-09
good first issueinvalidtestui/ux
## Summary Several test files are failing because `data-testid` attribute values used in test queries no longer match those set in the component source code. This is the most prevalent failure pattern across the CI shard runs. ## Root Cause A recent component refactoring renamed `data-testid` attributes (e.g. `searchBtn` ↔ `searchButton`, and others like `sortpost-select`, `page-header`, `talawa-logo`, `trigger-invalid-sort`) but the corresponding test files were not updated to reflect the new values. ## Affected Files (Known) - `src/shared-components/SortingButton/SortingButton.spec.tsx` - `src/screens/UserPortal/Organizations/Organizations.spec.tsx` - `src/screens/UserPortal/UserGlobalScreen/UserGlobalScreen.spec.tsx` - `src/shared-components/posts/posts.spec.tsx` ## Missing / Renamed Attributes | Old `data-testid` | New `data-testid` | Affected Shards | |---|---|---| | `searchBtn` | TBD | 2, 3, 4, 6, 9, 11 | | `searchButton` | TBD | 7, 8, 11, 12 | | `sortpost-select` | TBD | 10 | | `page-header` | TBD | 10 | | `talawa-logo` | TBD | 6 | | `trigger-invalid-sort` | TBD | 12 | ## Starter Code / Fix Approach **Step 1:** Find the current `data-testid` values in the component source: ```bash rg 'data-testid' src/shared-components/SortingButton/ rg 'data-testid' src/screens/UserPortal/ ``` **Step 2:** Update the test queries to match. For example, if `searchBtn` was renamed to `searchButton` in the component: ```diff // Organizations.spec.tsx (example) - const searchBtn = screen.getByTestId('searchBtn'); + const searchBtn = screen.getByTestId('searchButton'); ``` **Step 3:** Similarly for SortingButton: ```diff // SortingButton.spec.tsx (example) - const sortSelect = screen.getByTestId('sortpost-select'); + const sortSelect = screen.getByTestId('<new-testid-value>'); ``` **Step 4:** Run the affected tests locally to confirm: ```bash npx jest src/shared-components/SortingButton/SortingButton.spec.tsx --no-coverage npx jest src/screens/UserPortal/Organizations/Organizations.spec.tsx --no-coverage ``` ## References - PR: https://github.com/PalisadoesFoundation/talawa-admin/pull/7543 - Analysis comment: https://github.com/PalisadoesFoundation/talawa-admin/pull/7543#issuecomment-4210543487 - Requested by: @palisadoes
5 条评论