-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add-keyboard-shortcuts
- Loading branch information
Showing
8 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
64 changes: 64 additions & 0 deletions
64
packages/lexical-react/src/__tests__/unit/useMenuAnchorRef.test.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import {createTestEditor} from 'lexical/src/__tests__/utils'; | ||
import * as React from 'react'; | ||
import {createRoot, Root} from 'react-dom/client'; | ||
import * as ReactTestUtils from 'shared/react-test-utils'; | ||
|
||
import {useMenuAnchorRef} from '../../shared/LexicalMenu'; | ||
|
||
jest.mock('@lexical/react/LexicalComposerContext', () => ({ | ||
useLexicalComposerContext: () => [createTestEditor()], | ||
})); | ||
|
||
jest.mock('shared/canUseDOM', () => ({ | ||
CAN_USE_DOM: false, | ||
})); | ||
|
||
describe('useMenuAnchorRef', () => { | ||
let container: HTMLDivElement | null = null; | ||
let reactRoot: Root; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
reactRoot = createRoot(container); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return null if CAN_USE_DOM is false', async () => { | ||
let anchorElementRef; | ||
|
||
function App() { | ||
const resolution = null; | ||
const setResolution = jest.fn(); | ||
const anchorClassName = 'some-class'; | ||
const parent = undefined; | ||
const shouldIncludePageYOffset__EXPERIMENTAL = true; | ||
|
||
anchorElementRef = useMenuAnchorRef( | ||
resolution, | ||
setResolution, | ||
anchorClassName, | ||
parent, | ||
shouldIncludePageYOffset__EXPERIMENTAL, | ||
); | ||
|
||
return null; | ||
} | ||
|
||
await ReactTestUtils.act(async () => { | ||
reactRoot.render(<App />); | ||
}); | ||
|
||
expect(anchorElementRef!.current).toBeNull(); | ||
}); | ||
}); |
This file contains 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