-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix/broken tests on develop #7548
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
base: develop
Are you sure you want to change the base?
Changes from all commits
1814d0d
97e29ea
9247693
cfd42e7
b6652d7
bf8d114
4eb2f3d
6f080aa
c2679ed
ef38d4e
6ec899b
f0ad58b
6e1714c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| import React from 'react'; | ||
| import { MockedProvider } from '@apollo/react-testing'; | ||
| import type { RenderResult } from '@testing-library/react'; | ||
| import { act, cleanup, render, screen, waitFor } from '@testing-library/react'; | ||
| import { | ||
| act, | ||
| cleanup, | ||
| fireEvent, | ||
| render, | ||
| screen, | ||
| waitFor, | ||
| } from '@testing-library/react'; | ||
|
Comment on lines
+4
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify restricted fireEvent usage in spec files and inspect Enter-triggered search sites
rg -n --type tsx '\bfireEvent\b|keyboard\(\s*[`'\'']\{Enter\}[`'\'']\s*\)'Repository: PalisadoesFoundation/talawa-admin Length of output: 104 🏁 Script executed: fd SubTags.spec.tsx --type fRepository: PalisadoesFoundation/talawa-admin Length of output: 125 🏁 Script executed: cat -n src/screens/AdminPortal/SubTags/SubTags.spec.tsx | head -50Repository: PalisadoesFoundation/talawa-admin Length of output: 1963 🏁 Script executed: sed -n '240,260p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 826 🏁 Script executed: sed -n '235,265p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 1184 🏁 Script executed: rg -n 'fireEvent' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 167 🏁 Script executed: sed -n '1,30p' src/screens/AdminPortal/SubTags/SubTags.spec.tsx | grep -E 'import.*user|fireEvent'Repository: PalisadoesFoundation/talawa-admin Length of output: 142 🏁 Script executed: rg -n 'afterEach|cleanup\(\)|vi.restoreAllMocks|vi.clearAllMocks' src/screens/AdminPortal/SubTags/SubTags.spec.tsx | head -20Repository: PalisadoesFoundation/talawa-admin Length of output: 299 🏁 Script executed: sed -n '135,150p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 466 🏁 Script executed: sed -n '235,275p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 1602 🏁 Script executed: grep -n 'wait()' src/screens/AdminPortal/SubTags/SubTags.spec.tsx | head -5Repository: PalisadoesFoundation/talawa-admin Length of output: 186 🏁 Script executed: sed -n '80,100p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 583 🏁 Script executed: sed -n '139,145p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 261 🏁 Script executed: grep -n "^const wait\|^function wait\|^export.*wait" src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 59 🏁 Script executed: rg -n "import.*wait|const wait|function wait" src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 126 🏁 Script executed: sed -n '61,65p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 220 🏁 Script executed: sed -n '245,260p' src/screens/AdminPortal/SubTags/SubTags.spec.tsxRepository: PalisadoesFoundation/talawa-admin Length of output: 707 ❌ Critical: Replace hardcoded Two issues compound test flakiness in CI sharding:
Proposed fixesFix 1 (line 61-66): Replace hardcoded wait helper: -async function wait(ms = 500): Promise<void> {
- await act(() => {
- return new Promise((resolve) => {
- setTimeout(resolve, ms);
- });
- });
-}
+// Removed: Use waitFor/findBy queries instead for deterministic waitsThen replace all Fix 2 (lines 249-251): Replace fireEvent with userEvent: - const input = screen.getByPlaceholderText(translations.searchByName);
- fireEvent.change(input, { target: { value: ' searchSubTag ' } });
+ const input = await screen.findByPlaceholderText(translations.searchByName);
+ await user.click(input);
+ await user.clear(input);
+ await user.paste(' searchSubTag ');
await user.keyboard('{Enter}');Also remove Also applies to: All 🧰 Tools🪛 ESLint[error] 7-7: 'fireEvent' import from '@testing-library/react' is restricted. Tests in this file use fireEvent for user interactions; use userEvent from (no-restricted-imports) 🤖 Prompt for AI Agents |
||
| import userEvent from '@testing-library/user-event'; | ||
| import { I18nextProvider } from 'react-i18next'; | ||
| import { Provider } from 'react-redux'; | ||
|
|
@@ -239,10 +246,9 @@ describe('Organisation Tags Page', () => { | |
| ).toBeInTheDocument(); | ||
| }); | ||
| const input = screen.getByPlaceholderText(translations.searchByName); | ||
| // Test trimming: add spaces that should be trimmed by the component | ||
| await user.clear(input); | ||
| await user.type(input, ' searchSubTag '); | ||
| await user.click(screen.getByTestId('searchBtn')); | ||
| // Set value at once to avoid intermediate unmatched queries | ||
| fireEvent.change(input, { target: { value: ' searchSubTag ' } }); | ||
| await user.keyboard('{Enter}'); | ||
|
|
||
| // should render the two searched tags from the mock data | ||
| // where name starts with "searchSubTag" (mocks are configured for this) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.