/* * Copyright 2025 coze-dev Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { render, screen, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; import copy from 'copy-to-clipboard'; import { getSlardarInstance } from '@coze-arch/logger'; import { I18n } from '@coze-arch/i18n'; import { Toast } from '@coze-arch/coze-design'; import { withSlardarIdButton } from '../src/with-slardar-id-button'; const mockSlardarInstance = { config: vi.fn(() => ({ sessionId: 'test-session-id' })), }; vi.mock('@coze-arch/logger', () => ({ getSlardarInstance: vi.fn(() => mockSlardarInstance), })); // 模拟依赖 vi.mock('copy-to-clipboard', () => ({ default: vi.fn(), })); vi.mock('@coze-arch/coze-design', () => ({ // eslint-disable-next-line @typescript-eslint/naming-convention Button: ({ children, onClick, className, size, color }: any) => ( ), Toast: { success: vi.fn(), }, })); vi.mock('@coze-arch/i18n', () => ({ I18n: { t: vi.fn(key => { if (key === 'copy_session_id') { return '复制会话ID'; } if (key === 'error_id_copy_success') { return '复制成功'; } return key; }), }, })); describe('withSlardarIdButton', () => { beforeEach(() => { vi.clearAllMocks(); }); afterEach(() => { vi.resetAllMocks(); }); it('应该正确渲染传入的节点和按钮', () => { const testNode =