Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: renderPane exec twice #439

Merged
merged 1 commit into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/components/tabs/__tests__/__snapshots__/tabs.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,5 @@ exports[`The Tabs Components The snapshot 1`] = `
</a>
</div>
</div>
<div
className="mo-tabs__content"
>
<div
className="mo-tabs__content__item"
>
<div
data-testid="test1"
>
test1
</div>
</div>
<div
className="mo-tabs__content__item"
>
<div
data-testid="test2"
>
test2
</div>
</div>
</div>
</div>
`;
22 changes: 2 additions & 20 deletions src/components/tabs/__tests__/tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
import renderer from 'react-test-renderer';
import '@testing-library/jest-dom';
import { Tabs, tabsClassName, tabsContentActiveClassName } from '..';
import { Tabs, tabsClassName } from '..';
import { ITabProps, tabItemActiveClassName } from '../tab';
import { dragToTargetNode } from '@test/utils';

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

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

expect(content?.childElementCount).toBe(0);
expect(header?.childElementCount).toBe(0);
});

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

test('Should support to renderPane via function', () => {
const data = mockData.concat();
data.push({
id: '3',
name: 'test-title-3',
renderPane: () => <div data-testid="test3">test3</div>,
closable: true,
});
const { getByTestId } = render(<Tabs data={data} />);
expect(getByTestId('test3')).toBeInTheDocument();
});

test('Should render card type', () => {
const { container } = render(<Tabs type="card" data={mockData} />);

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

test('Should active specific tab', () => {
const { getByText, getByTestId } = render(
<Tabs activeTab="1" data={mockData} />
);
const { getByText } = render(<Tabs activeTab="1" data={mockData} />);
const testHeader = getByText('test-title-1');
const testContent = getByTestId('test1').parentElement;
expect(testHeader?.classList).toContain(tabItemActiveClassName);
expect(testContent?.classList).toContain(tabsContentActiveClassName);
});

test('Should trigger events', async () => {
Expand Down
26 changes: 1 addition & 25 deletions src/components/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
classNames,
} from 'mo/common/className';

import { Tab, ITabProps, tabItemClassName } from './tab';
import { Tab, ITabProps } from './tab';
import DragAndDrop from './dragAndDrop';

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

export const tabsClassName = prefixClaName('tabs');
export const tabsHeader = getBEMElement(tabsClassName, 'header');
export const tabsContent = getBEMElement(tabsClassName, 'content');
export const tabsContentItem = getBEMElement(tabsContent, 'item');
export const tabsContentActiveClassName = getBEMModifier(
tabsContentItem,
'active'
);
export const tabItemCloseClassName = getBEMElement(tabItemClassName, 'close');

export function Tabs<T>(props: ITabsProps<T>) {
const {
Expand Down Expand Up @@ -88,23 +81,6 @@ export function Tabs<T>(props: ITabsProps<T>) {
);
})}
</div>
<div className={tabsContent}>
{data?.map((tab: ITabProps<T>) => {
return (
<div
key={tab.id}
className={classNames(tabsContentItem, {
[tabsContentActiveClassName]:
activeTab === tab.id,
})}
>
{tab.renderPane instanceof Function
? tab.renderPane(tab)
: tab.renderPane}
</div>
);
})}
</div>
</div>
</DragAndDrop>
);
Expand Down
13 changes: 0 additions & 13 deletions src/workbench/__tests__/__snapshots__/workbench.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,6 @@ exports[`Test Workbench Component Match The WorkbenchView snapshot 1`] = `
问题
</div>
</div>
<div
class="mo-tabs__content"
>
<div
class="mo-tabs__content__item"
>
<div
style="margin: 0px 18px; user-select: none;"
>
未在工作区检测到问题
</div>
</div>
</div>
</div>
<div
class="mo-action-bar mo-panel__toolbar"
Expand Down
63 changes: 0 additions & 63 deletions src/workbench/panel/__tests__/__snapshots__/panel.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,6 @@ exports[`Test Panel Component Match the Panel snapshot 1`] = `
输出
</div>
</div>
<div
className="mo-tabs__content"
>
<div
className="mo-tabs__content__item"
/>
<div
className="mo-tabs__content__item mo-tabs__content__item--active"
>
<div
className="mo-output"
>
<div
className="mo-monaco-editor"
style={
Object {
"height": "100%",
"minHeight": "400px",
"position": "relative",
"width": "100%",
}
}
/>
</div>
</div>
</div>
</div>
<div
className="mo-action-bar mo-panel__toolbar"
Expand Down Expand Up @@ -145,43 +119,6 @@ exports[`Test Panel Component Match the PanelView snapshot 1`] = `
输出
</div>
</div>
<div
className="mo-tabs__content"
>
<div
className="mo-tabs__content__item"
>
<div
style={
Object {
"margin": "0 18px",
"userSelect": "none",
}
}
>
未在工作区检测到问题
</div>
</div>
<div
className="mo-tabs__content__item mo-tabs__content__item--active"
>
<div
className="mo-output"
>
<div
className="mo-monaco-editor"
style={
Object {
"height": "100%",
"minHeight": "400px",
"position": "relative",
"width": "100%",
}
}
/>
</div>
</div>
</div>
</div>
<div
className="mo-action-bar mo-panel__toolbar"
Expand Down
4 changes: 1 addition & 3 deletions src/workbench/panel/__tests__/panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ describe('Test Panel Component', () => {
expect(
container.querySelector('.mo-monaco-editor')
).not.toBeInTheDocument();
// The customizedPane element are rendered in two places(mo-panel__container/mo-tabs__content),
// so the expect value is 2
expect(getAllByText('customizedPane').length).toBe(2);
expect(getAllByText('customizedPane').length).toBe(1);
});

test('Sort the Panel ', () => {
Expand Down