fix: 修复客服权限与收件箱配置问题
This commit is contained in:
@@ -33,6 +33,7 @@ export const copyTextToClipboard = async data => {
|
||||
document.body.appendChild(textarea);
|
||||
|
||||
try {
|
||||
textarea.focus({ preventScroll: true });
|
||||
textarea.select();
|
||||
textarea.setSelectionRange(0, textarea.value.length);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { copyTextToClipboard, handleOtpPaste } from '../clipboard';
|
||||
|
||||
const mockWriteText = vi.fn();
|
||||
const mockExecCommand = vi.fn();
|
||||
const originalCreateElement = document.createElement.bind(document);
|
||||
|
||||
const setClipboard = clipboard => {
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
@@ -148,9 +149,16 @@ describe('copyTextToClipboard', () => {
|
||||
|
||||
it('falls back when clipboard API is not available', async () => {
|
||||
setClipboard(undefined);
|
||||
const focus = vi.fn();
|
||||
vi.spyOn(document, 'createElement').mockImplementation(tagName => {
|
||||
const element = originalCreateElement(tagName);
|
||||
if (tagName === 'textarea') element.focus = focus;
|
||||
return element;
|
||||
});
|
||||
|
||||
await copyTextToClipboard('test');
|
||||
|
||||
expect(focus).toHaveBeenCalledWith({ preventScroll: true });
|
||||
expect(mockExecCommand).toHaveBeenCalledWith('copy');
|
||||
expect(document.querySelector('textarea')).toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user