-
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.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/lexical-playground/__tests__/e2e/RetainSelection.spec.mjs
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,61 @@ | ||
/** | ||
* 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 {selectAll} from '../keyboardShortcuts/index.mjs'; | ||
import { | ||
evaluate, | ||
expect, | ||
focusEditor, | ||
initialize, | ||
locate, | ||
test, | ||
} from '../utils/index.mjs'; | ||
|
||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
test.describe('RetainSelection', () => { | ||
test.beforeEach(({isCollab, page}) => | ||
initialize({isCollab, page, retainSelection: true}), | ||
); | ||
test(`retain selection works`, async ({page, isPlainText, browserName}) => { | ||
await focusEditor(page); | ||
await page.keyboard.type('Lexical'); | ||
await selectAll(page); | ||
await locate(page, 'body').click(); | ||
const {distance, widthDifference, heightDifference} = await evaluate( | ||
page, | ||
() => { | ||
function compareNodeAlignment(node1, node2, tolerance = 0) { | ||
const rect1 = node1.getBoundingClientRect(); | ||
const rect2 = node2.getBoundingClientRect(); | ||
const distance_ = Math.sqrt( | ||
Math.pow(rect1.left - rect2.left, 2) + | ||
Math.pow(rect1.top - rect2.top, 2), | ||
); | ||
const widthDifference_ = Math.abs(rect1.width - rect2.width); | ||
const heightDifference_ = Math.abs(rect1.height - rect2.height); | ||
return { | ||
distance: distance_, | ||
widthDifference: widthDifference_, | ||
heightDifference: heightDifference_, | ||
}; | ||
} | ||
const editorSpan = document.querySelector( | ||
'[contenteditable="true"] span', | ||
); | ||
const fakeSelection = document.querySelector( | ||
'[style*="background: highlight"]', | ||
); | ||
return compareNodeAlignment(editorSpan, fakeSelection, 5); | ||
}, | ||
); | ||
await expect(distance).toBeLessThanOrEqual(5); | ||
await expect(widthDifference).toBeLessThanOrEqual(5); | ||
await expect(heightDifference).toBeLessThanOrEqual(5); | ||
}); | ||
}); | ||
/* eslint-enable sort-keys-fix/sort-keys-fix */ |
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