Skip to content

Commit 5eb14a5

Browse files
authored
fix: renderPane exec twice (#439)
1 parent 3dc3f49 commit 5eb14a5

File tree

6 files changed

+4
-146
lines changed

6 files changed

+4
-146
lines changed

src/components/tabs/__tests__/__snapshots__/tabs.test.tsx.snap

-22
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,5 @@ exports[`The Tabs Components The snapshot 1`] = `
4444
</a>
4545
</div>
4646
</div>
47-
<div
48-
className="mo-tabs__content"
49-
>
50-
<div
51-
className="mo-tabs__content__item"
52-
>
53-
<div
54-
data-testid="test1"
55-
>
56-
test1
57-
</div>
58-
</div>
59-
<div
60-
className="mo-tabs__content__item"
61-
>
62-
<div
63-
data-testid="test2"
64-
>
65-
test2
66-
</div>
67-
</div>
68-
</div>
6947
</div>
7048
`;

src/components/tabs/__tests__/tabs.test.tsx

+2-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
33
import renderer from 'react-test-renderer';
44
import '@testing-library/jest-dom';
5-
import { Tabs, tabsClassName, tabsContentActiveClassName } from '..';
5+
import { Tabs, tabsClassName } from '..';
66
import { ITabProps, tabItemActiveClassName } from '../tab';
77
import { dragToTargetNode } from '@test/utils';
88

@@ -32,10 +32,8 @@ describe('The Tabs Components', () => {
3232

3333
test('Should render nothing', () => {
3434
const { container } = render(<Tabs />);
35-
const content = container.querySelector('.mo-tabs__content');
3635
const header = container.querySelector('.mo-tabs__header');
3736

38-
expect(content?.childElementCount).toBe(0);
3937
expect(header?.childElementCount).toBe(0);
4038
});
4139

@@ -49,18 +47,6 @@ describe('The Tabs Components', () => {
4947
expect(body.classList).toContain('test-tabs');
5048
});
5149

52-
test('Should support to renderPane via function', () => {
53-
const data = mockData.concat();
54-
data.push({
55-
id: '3',
56-
name: 'test-title-3',
57-
renderPane: () => <div data-testid="test3">test3</div>,
58-
closable: true,
59-
});
60-
const { getByTestId } = render(<Tabs data={data} />);
61-
expect(getByTestId('test3')).toBeInTheDocument();
62-
});
63-
6450
test('Should render card type', () => {
6551
const { container } = render(<Tabs type="card" data={mockData} />);
6652

@@ -69,13 +55,9 @@ describe('The Tabs Components', () => {
6955
});
7056

7157
test('Should active specific tab', () => {
72-
const { getByText, getByTestId } = render(
73-
<Tabs activeTab="1" data={mockData} />
74-
);
58+
const { getByText } = render(<Tabs activeTab="1" data={mockData} />);
7559
const testHeader = getByText('test-title-1');
76-
const testContent = getByTestId('test1').parentElement;
7760
expect(testHeader?.classList).toContain(tabItemActiveClassName);
78-
expect(testContent?.classList).toContain(tabsContentActiveClassName);
7961
});
8062

8163
test('Should trigger events', async () => {

src/components/tabs/index.tsx

+1-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
classNames,
1010
} from 'mo/common/className';
1111

12-
import { Tab, ITabProps, tabItemClassName } from './tab';
12+
import { Tab, ITabProps } from './tab';
1313
import DragAndDrop from './dragAndDrop';
1414

1515
export type TabsType = 'line' | 'card';
@@ -28,13 +28,6 @@ export interface ITabsProps<T> extends React.ComponentProps<any> {
2828

2929
export const tabsClassName = prefixClaName('tabs');
3030
export const tabsHeader = getBEMElement(tabsClassName, 'header');
31-
export const tabsContent = getBEMElement(tabsClassName, 'content');
32-
export const tabsContentItem = getBEMElement(tabsContent, 'item');
33-
export const tabsContentActiveClassName = getBEMModifier(
34-
tabsContentItem,
35-
'active'
36-
);
37-
export const tabItemCloseClassName = getBEMElement(tabItemClassName, 'close');
3831

3932
export function Tabs<T>(props: ITabsProps<T>) {
4033
const {
@@ -88,23 +81,6 @@ export function Tabs<T>(props: ITabsProps<T>) {
8881
);
8982
})}
9083
</div>
91-
<div className={tabsContent}>
92-
{data?.map((tab: ITabProps<T>) => {
93-
return (
94-
<div
95-
key={tab.id}
96-
className={classNames(tabsContentItem, {
97-
[tabsContentActiveClassName]:
98-
activeTab === tab.id,
99-
})}
100-
>
101-
{tab.renderPane instanceof Function
102-
? tab.renderPane(tab)
103-
: tab.renderPane}
104-
</div>
105-
);
106-
})}
107-
</div>
10884
</div>
10985
</DragAndDrop>
11086
);

src/workbench/__tests__/__snapshots__/workbench.test.tsx.snap

-13
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,6 @@ exports[`Test Workbench Component Match The WorkbenchView snapshot 1`] = `
433433
问题
434434
</div>
435435
</div>
436-
<div
437-
class="mo-tabs__content"
438-
>
439-
<div
440-
class="mo-tabs__content__item"
441-
>
442-
<div
443-
style="margin: 0px 18px; user-select: none;"
444-
>
445-
未在工作区检测到问题
446-
</div>
447-
</div>
448-
</div>
449436
</div>
450437
<div
451438
class="mo-action-bar mo-panel__toolbar"

src/workbench/panel/__tests__/__snapshots__/panel.test.tsx.snap

-63
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@ exports[`Test Panel Component Match the Panel snapshot 1`] = `
3232
输出
3333
</div>
3434
</div>
35-
<div
36-
className="mo-tabs__content"
37-
>
38-
<div
39-
className="mo-tabs__content__item"
40-
/>
41-
<div
42-
className="mo-tabs__content__item mo-tabs__content__item--active"
43-
>
44-
<div
45-
className="mo-output"
46-
>
47-
<div
48-
className="mo-monaco-editor"
49-
style={
50-
Object {
51-
"height": "100%",
52-
"minHeight": "400px",
53-
"position": "relative",
54-
"width": "100%",
55-
}
56-
}
57-
/>
58-
</div>
59-
</div>
60-
</div>
6135
</div>
6236
<div
6337
className="mo-action-bar mo-panel__toolbar"
@@ -145,43 +119,6 @@ exports[`Test Panel Component Match the PanelView snapshot 1`] = `
145119
输出
146120
</div>
147121
</div>
148-
<div
149-
className="mo-tabs__content"
150-
>
151-
<div
152-
className="mo-tabs__content__item"
153-
>
154-
<div
155-
style={
156-
Object {
157-
"margin": "0 18px",
158-
"userSelect": "none",
159-
}
160-
}
161-
>
162-
未在工作区检测到问题
163-
</div>
164-
</div>
165-
<div
166-
className="mo-tabs__content__item mo-tabs__content__item--active"
167-
>
168-
<div
169-
className="mo-output"
170-
>
171-
<div
172-
className="mo-monaco-editor"
173-
style={
174-
Object {
175-
"height": "100%",
176-
"minHeight": "400px",
177-
"position": "relative",
178-
"width": "100%",
179-
}
180-
}
181-
/>
182-
</div>
183-
</div>
184-
</div>
185122
</div>
186123
<div
187124
className="mo-action-bar mo-panel__toolbar"

src/workbench/panel/__tests__/panel.test.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ describe('Test Panel Component', () => {
8282
expect(
8383
container.querySelector('.mo-monaco-editor')
8484
).not.toBeInTheDocument();
85-
// The customizedPane element are rendered in two places(mo-panel__container/mo-tabs__content),
86-
// so the expect value is 2
87-
expect(getAllByText('customizedPane').length).toBe(2);
85+
expect(getAllByText('customizedPane').length).toBe(1);
8886
});
8987

9088
test('Sort the Panel ', () => {

0 commit comments

Comments
 (0)