-
Notifications
You must be signed in to change notification settings - Fork 71
[LG-5100] feat(code-editor): add test harnesses #3103
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f8a2913
refactor(code-editor): reorganize testing utilities and enhance docum…
tsck f5aec34
refactor(code-editor): reorganize panel testing utilities and update …
tsck cd3b75c
feat(code-editor): move testing utilities for CodeMirror extensions
tsck bfa15f2
feat(code-editor): add test utilities for CodeEditor and Panel compon…
tsck 4f04106
feat(code-editor): enhance testing utilities and documentation for Co…
tsck 4be195c
feat(code-editor): enhance testing utilities and documentation for as…
tsck 364e64a
refactor(code-editor): remove unused testing utilities for CodeEditor
tsck 1024857
refactor(code-editor): remove compatibility documentation from testin…
tsck ae34a8c
feat(code-editor): enhance testing environment with additional mocks …
tsck 100170e
fix(tests): update data-lgid attributes in CodeEditor tests for consi…
tsck 80882c5
Merge branch 'integration/code-editor' of github.com:mongodb/leafygre…
tsck f70773f
refactor(Panel): revert inadvertent panel changes on base merge
tsck ba92455
test(getTestUtils): mock HTMLDialogElement methods and update test de…
tsck 552bf9d
feat(CodeEditor): integrate lgIds into context and panel components
tsck 2be69ad
refactor(getTestUtils): Simplify exposed utilities and rewrite tests
tsck be3c7a4
feat(Panel.testUtils): integrate lgIds into PanelTestContextConfig an…
tsck f43df90
refactor(getTestUtils): rename utility functions for consistency
tsck 39dd8de
refactor(README): streamline CodeEditor testing utilities documentation
tsck d2ec73a
refactor(getTestUtils): code review changes
tsck d316ddd
refactor(getTestUtils): code editor not progress bar =)
tsck 6184ef2
fix(getTestUtils): fix build
tsck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,70 @@ import { EditorState } from '@codemirror/state'; | |
import { act, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { renderCodeEditor } from '../testing/testUtils'; | ||
|
||
import { LanguageName } from './hooks/extensions/useLanguageExtension'; | ||
import { renderCodeEditor } from './CodeEditor.testUtils'; | ||
import { CopyButtonAppearance } from './CodeEditor.types'; | ||
import { CodeEditorSelectors } from '.'; | ||
|
||
// Enhanced MutationObserver mock for CodeMirror compatibility | ||
global.MutationObserver = jest.fn().mockImplementation(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
takeRecords: jest.fn().mockReturnValue([]), | ||
})); | ||
|
||
// Mock ResizeObserver which is used by CodeMirror | ||
global.ResizeObserver = jest.fn().mockImplementation(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
})); | ||
|
||
// Mock IntersectionObserver which may be used by CodeMirror | ||
global.IntersectionObserver = jest.fn().mockImplementation(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
root: null, | ||
rootMargin: '', | ||
thresholds: [], | ||
})); | ||
|
||
// Mock document.getSelection for CodeMirror | ||
if (!global.document.getSelection) { | ||
global.document.getSelection = jest.fn().mockReturnValue({ | ||
rangeCount: 0, | ||
getRangeAt: jest.fn(), | ||
removeAllRanges: jest.fn(), | ||
addRange: jest.fn(), | ||
toString: jest.fn().mockReturnValue(''), | ||
}); | ||
} | ||
|
||
// Mock createRange for CodeMirror | ||
if (!global.document.createRange) { | ||
global.document.createRange = jest.fn().mockReturnValue({ | ||
setStart: jest.fn(), | ||
setEnd: jest.fn(), | ||
collapse: jest.fn(), | ||
selectNodeContents: jest.fn(), | ||
insertNode: jest.fn(), | ||
surroundContents: jest.fn(), | ||
cloneRange: jest.fn(), | ||
detach: jest.fn(), | ||
getClientRects: jest.fn().mockReturnValue([]), | ||
getBoundingClientRect: jest.fn().mockReturnValue({ | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
width: 0, | ||
height: 0, | ||
}), | ||
}); | ||
} | ||
|
||
// Mock console methods to suppress expected warnings | ||
const originalConsoleWarn = console.warn; | ||
const originalConsoleError = console.error; | ||
|
@@ -320,24 +371,34 @@ describe('packages/code-editor', () => { | |
test('renders copy button when copyButtonAppearance is "hover"', async () => { | ||
const { container, editor } = renderCodeEditor({ | ||
copyButtonAppearance: CopyButtonAppearance.Hover, | ||
'data-lgid': 'lg-test-copy-hover', | ||
}); | ||
|
||
await editor.waitForEditorView(); | ||
|
||
// Wait a bit for copy button to be rendered | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
||
// The copy button selector looks for the specific lgid structure | ||
expect( | ||
container.querySelector(CodeEditorSelectors.CopyButton), | ||
container.querySelector('[data-lgid="lg-test-copy-hover-copy_button"]'), | ||
|
||
).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders copy button when copyButtonAppearance is "persist"', async () => { | ||
const { container, editor } = renderCodeEditor({ | ||
copyButtonAppearance: CopyButtonAppearance.Persist, | ||
'data-lgid': 'lg-test-copy-persist', | ||
}); | ||
|
||
await editor.waitForEditorView(); | ||
|
||
// Wait a bit for copy button to be rendered | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
||
// The copy button selector looks for the specific lgid structure | ||
expect( | ||
container.querySelector(CodeEditorSelectors.CopyButton), | ||
container.querySelector('[data-lgid="lg-test-copy-persist-copy_button"]'), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of the timeout, would this work?