feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
/*
* 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 React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { CaseBlock } from '../../src/components/setting-tips/case-block';
describe('CaseBlock', () => {
const mockLabel = 'Test Label';
const mockContent = 'Test Content';
it('renders label correctly', () => {
render(<CaseBlock label={mockLabel} content={mockContent} />);
expect(screen.getByText(mockLabel)).toBeInTheDocument();
});
it('renders content correctly', () => {
render(<CaseBlock label={mockLabel} content={mockContent} />);
expect(screen.getByText(mockContent)).toBeInTheDocument();
});
it('renders complex content correctly', () => {
const complexContent = (
<div data-testid="complex-content">
<span>Child 1</span>
<span>Child 2</span>
</div>
);
render(<CaseBlock label={mockLabel} content={complexContent} />);
expect(screen.getByTestId('complex-content')).toBeInTheDocument();
expect(screen.getByText('Child 1')).toBeInTheDocument();
expect(screen.getByText('Child 2')).toBeInTheDocument();
});
it('applies correct CSS classes', () => {
render(<CaseBlock label={mockLabel} content={mockContent} />);
// Check for flex container classes
const container = screen.getByText(mockLabel).parentElement;
expect(container).toHaveClass('flex', 'flex-col');
// Check for gap class
expect(container).toHaveClass('gap-[4px]');
});
});

View File

@@ -0,0 +1,85 @@
/*
* 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 React from 'react';
import { render, screen, within } from '@testing-library/react';
import '@testing-library/jest-dom';
import { RerankTips } from '../../src/components/setting-tips/rerank-tips';
// Mock I18n.t function
vi.mock('@coze-arch/i18n', () => ({
I18n: {
t: (key: string, params?: { index?: string }) => {
if (params?.index) {
return `${key}-${params.index}`;
}
return key;
},
},
}));
describe('RerankTips', () => {
it('renders headline correctly', () => {
render(<RerankTips />);
expect(screen.getByText('kl_write_034')).toBeInTheDocument();
});
it('renders case block labels correctly', () => {
render(<RerankTips />);
expect(screen.getByText('kl_write_046')).toBeInTheDocument();
expect(screen.getByText('kl_write_047')).toBeInTheDocument();
});
it('renders first case block content correctly', () => {
render(<RerankTips />);
// Check if all labels and content in first block are rendered
const firstBlock = screen.getAllByRole('article')[0];
expect(firstBlock).toBeInTheDocument();
// Check labels and content within the first block
within(firstBlock).getByText('kl_write_041-A');
within(firstBlock).getByText('kl_write_042');
within(firstBlock).getByText('kl_write_041-B');
within(firstBlock).getByText('kl_write_043');
within(firstBlock).getByText('kl_write_041-C');
within(firstBlock).getByText('kl_write_044');
within(firstBlock).getByText('kl_write_041-D');
within(firstBlock).getByText('kl_write_045');
});
it('renders second case block content correctly', () => {
render(<RerankTips />);
// Second block has the same content but in different order
expect(screen.getAllByText('kl_write_041-A')).toHaveLength(2);
expect(screen.getAllByText('kl_write_042')).toHaveLength(2);
expect(screen.getAllByText('kl_write_041-B')).toHaveLength(2);
expect(screen.getAllByText('kl_write_043')).toHaveLength(2);
expect(screen.getAllByText('kl_write_041-C')).toHaveLength(2);
expect(screen.getAllByText('kl_write_044')).toHaveLength(2);
expect(screen.getAllByText('kl_write_041-D')).toHaveLength(2);
expect(screen.getAllByText('kl_write_045')).toHaveLength(2);
});
it('renders correct number of case blocks', () => {
render(<RerankTips />);
const caseBlocks = screen.getAllByRole('article');
expect(caseBlocks).toHaveLength(2);
});
});

View File

@@ -0,0 +1,56 @@
/*
* 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 React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { RewriteTips } from '../../src/components/setting-tips/rewrite-tips';
// Mock I18n.t function
vi.mock('@coze-arch/i18n', () => ({
I18n: {
t: (key: string) => key,
},
}));
describe('RewriteTips', () => {
it('renders headline correctly', () => {
render(<RewriteTips />);
expect(screen.getByText('kl_write_034')).toBeInTheDocument();
});
it('renders all case blocks with correct content', () => {
render(<RewriteTips />);
// Check if all labels are rendered
expect(screen.getByText('kl_write_035')).toBeInTheDocument();
expect(screen.getByText('kl_write_037')).toBeInTheDocument();
expect(screen.getByText('kl_write_039')).toBeInTheDocument();
// Check if all descriptions are rendered
expect(screen.getByText('kl_write_036')).toBeInTheDocument();
expect(screen.getByText('kl_write_038')).toBeInTheDocument();
expect(screen.getByText('kl_write_040')).toBeInTheDocument();
});
it('renders correct number of case blocks', () => {
render(<RewriteTips />);
const caseBlocks = screen.getAllByRole('article'); // Assuming CaseBlock has role="article"
expect(caseBlocks).toHaveLength(3);
});
});