Skip to content

Commit

Permalink
fix: table borded (#4534)
Browse files Browse the repository at this point in the history
* fix: table borded

* fix: unit test
  • Loading branch information
dream2023 committed May 30, 2024
1 parent 803ea80 commit 285f719
Show file tree
Hide file tree
Showing 28 changed files with 93 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('SchemaToolbar', () => {
});

describe('useSchemaToolbarRender()', () => {
const renderApp = (demoSchema: any, designable = true) => {
const renderAppOptions = (demoSchema: any, designable = true) => {
const Demo = () => <div data-testid="demo">Demo</div>;

const CustomToolbar = (props) => {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('SchemaToolbar', () => {
};

test('Render x-designer if x-designer has a value', () => {
renderApp({
renderAppOptions({
'x-designer': 'CustomToolbar',
});

Expand All @@ -91,15 +91,15 @@ describe('SchemaToolbar', () => {
});

test('Render x-toolbar if it has a value', () => {
renderApp({
renderAppOptions({
'x-toolbar': 'CustomToolbar',
});

expect(screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
});

test('Render x-toolbar if both x-toolbar and x-designer have values', () => {
renderApp({
renderAppOptions({
'x-toolbar': 'CustomToolbar',
'x-designer': 'CustomToolbar',
});
Expand All @@ -108,7 +108,7 @@ describe('SchemaToolbar', () => {
});

test('Render the default SchemaToolbar component if x-toolbar and x-designer have no values and x-settings has a value', () => {
renderApp({
renderAppOptions({
'x-settings': 'DemoSettings',
});

Expand All @@ -117,22 +117,22 @@ describe('SchemaToolbar', () => {
});

test('Do not render if x-toolbar and x-designer have no values and x-settings also has no value', () => {
renderApp({});
renderAppOptions({});

expect(screen.getByTestId('toolbar')).toHaveTextContent('');
expect(screen.getByTestId('toolbar-exists')).toHaveTextContent('false');
});

test('Do not render if the component corresponding to x-toolbar cannot be found', () => {
renderApp({
renderAppOptions({
'x-toolbar': 'NotFound',
});

expect(screen.getByTestId('toolbar')).toHaveTextContent('');
});

test('Do not render if designable is false', () => {
renderApp(
renderAppOptions(
{
'x-designer': 'CustomToolbar',
},
Expand All @@ -143,7 +143,7 @@ describe('SchemaToolbar', () => {
});

test('x-toolbar-props and custom Props', () => {
renderApp({
renderAppOptions({
'x-toolbar': 'CustomToolbar',
'x-toolbar-props': {
test: '123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { observer } from '@formily/reactive-react';
import { renderApp } from '@nocobase/test/client';
import { renderAppOptions } from '@nocobase/test/client';
import {
SchemaComponent,
SchemaInitializer,
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function createApp(options = {}, appOptions = {}) {
/>
);
};
await renderApp({
await renderAppOptions({
appOptions: {
providers: [Root],
schemaInitializers: [testInitializers],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { render, screen } from '@nocobase/test/client';
import React from 'react';
import collections from '../collections.json';

function renderApp(fieldName: string, components = {}) {
function renderAppOptions(fieldName: string, components = {}) {
const noUiSchema = {
key: 'no-ui-schema',
name: 'no-ui-schema',
Expand Down Expand Up @@ -99,7 +99,7 @@ function renderApp(fieldName: string, components = {}) {

describe('CollectionField', () => {
it('works', () => {
renderApp('nickname');
renderAppOptions('nickname');
expect(screen.getByText('Nickname')).toBeInTheDocument();
expect(screen.getByRole('textbox')).toHaveClass('ant-input');
});
Expand All @@ -109,18 +109,18 @@ describe('CollectionField', () => {
const field = useCollectionField();
return <div className={'input-test-1'}>{field?.name}</div>;
};
renderApp('nickname', { Input });
renderAppOptions('nickname', { Input });
expect(document.querySelector('.input-test-1')).toHaveTextContent('nickname');
});

it('useComponentProps', () => {
renderApp('dynamic-props');
renderAppOptions('dynamic-props');
expect(document.querySelector('.ant-input')).toHaveAttribute('placeholder', 'placeholder');
expect(screen.queryByText('addonBefore')).toBeInTheDocument();
});

it('no schema', () => {
renderApp('no-ui-schema');
renderAppOptions('no-ui-schema');
expect(document.querySelector('.ant-formily-item-control-content-component')).toHaveTextContent('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@nocobase/client';
import collections from '../collections.json';

function renderApp(Demo: ComponentType, name?: string) {
function renderAppOptions(Demo: ComponentType, name?: string) {
const app = new Application({
dataSourceManager: {
collections: collections as any,
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('CollectionFieldProvider', () => {
);
};

renderApp(Demo, 'nickname');
renderAppOptions(Demo, 'nickname');

expect(screen.getByTestId('demo')).toHaveTextContent('nickname');
});
Expand All @@ -61,7 +61,7 @@ describe('CollectionFieldProvider', () => {
return <div>children</div>;
};

renderApp(Demo, 'not-exists');
renderAppOptions(Demo, 'not-exists');

expect(document.body.innerHTML).toContain('ant-typography');
expect(document.body.innerHTML).not.toContain('children');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@nocobase/client';
import collections from '../collections.json';

function renderApp(Demo: ComponentType, props: any = {}) {
function renderAppOptions(Demo: ComponentType, props: any = {}) {
const app = new Application({
dataSourceManager: {
collections: collections as any,
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('AssociationProvider', () => {
);
};

renderApp(Demo, { name: 'users.roles' });
renderAppOptions(Demo, { name: 'users.roles' });

expect(screen.getByTestId('collection')).toHaveTextContent('roles');
expect(screen.getByTestId('parent-collection')).toHaveTextContent('users');
Expand All @@ -90,7 +90,7 @@ describe('AssociationProvider', () => {
);
};

renderApp(Demo, { name: 'users.roles', dataSource: 'a' });
renderAppOptions(Demo, { name: 'users.roles', dataSource: 'a' });

expect(screen.getByTestId('collection')).toHaveTextContent('roles');
expect(screen.getByTestId('parent-collection')).toHaveTextContent('users');
Expand All @@ -101,7 +101,7 @@ describe('AssociationProvider', () => {
const Demo = () => {
return <div>Demo</div>;
};
renderApp(Demo, { name: 'users.not-exists' });
renderAppOptions(Demo, { name: 'users.not-exists' });

expect(screen.getByText('Delete')).toBeInTheDocument();
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@nocobase/client';
import collections from '../collections.json';

function renderApp(Demo: ComponentType, dataSource?: string) {
function renderAppOptions(Demo: ComponentType, dataSource?: string) {
const app = new Application({
dataSourceManager: {
collections: collections as any,
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('CollectionManagerProvider', () => {
const users = cm.getCollection('users');
return <div data-testid="demo">{users.name}</div>;
};
renderApp(Demo);
renderAppOptions(Demo);

expect(screen.getByTestId('demo')).toHaveTextContent('users');
});
Expand All @@ -60,7 +60,7 @@ describe('CollectionManagerProvider', () => {
const collections = useCollections();
return <div data-testid="demo">{collections.length}</div>;
};
renderApp(Demo);
renderAppOptions(Demo);

expect(screen.getByTestId('demo')).toHaveTextContent('2');
});
Expand All @@ -70,7 +70,7 @@ describe('CollectionManagerProvider', () => {
const collections = useCollections((collection) => collection.name === 'users');
return <div data-testid="demo">{collections.length}</div>;
};
renderApp(Demo);
renderAppOptions(Demo);

expect(screen.getByTestId('demo')).toHaveTextContent('1');
});
Expand All @@ -80,7 +80,7 @@ describe('CollectionManagerProvider', () => {
const collections = useCollections();
return <div data-testid="demo">{collections.length}</div>;
};
renderApp(Demo, 'a');
renderAppOptions(Demo, 'a');

expect(screen.getByTestId('demo')).toHaveTextContent('1');
});
Expand All @@ -99,7 +99,7 @@ describe('CollectionManagerProvider', () => {
);
};

renderApp(Wrapper, 'a');
renderAppOptions(Wrapper, 'a');

expect(screen.getByTestId('demo')).toHaveTextContent('2');
});
Expand All @@ -120,7 +120,7 @@ describe('CollectionManagerProvider', () => {
);
};

renderApp(Wrapper, 'a');
renderAppOptions(Wrapper, 'a');

expect(screen.getByTestId('demo')).toHaveTextContent('2');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@nocobase/client';
import collections from '../collections.json';

function renderApp(Demo: ComponentType, props: any = {}) {
function renderAppOptions(Demo: ComponentType, props: any = {}) {
const app = new Application({
dataSourceManager: {
collections: collections as any,
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('CollectionProvider', () => {
);
};

renderApp(Demo, { name: 'users' });
renderAppOptions(Demo, { name: 'users' });

expect(screen.getByTestId('name')).toHaveTextContent('users');

Expand All @@ -74,7 +74,7 @@ describe('CollectionProvider', () => {
return <div data-testid="children">children</div>;
};

renderApp(Demo, { name: 'not-exists', allowNull: true });
renderAppOptions(Demo, { name: 'not-exists', allowNull: true });

expect(screen.getByTestId('children')).toHaveTextContent('children');
});
Expand All @@ -87,7 +87,7 @@ describe('CollectionProvider', () => {
return <div>children</div>;
};

renderApp(Demo, { name: 'not-exists', allowNull: false });
renderAppOptions(Demo, { name: 'not-exists', allowNull: false });

expect(screen.getByText('Delete')).toBeInTheDocument();
});
Expand All @@ -98,7 +98,7 @@ describe('CollectionProvider', () => {
return <div data-testid="fields">{fields.length}</div>;
};

renderApp(Demo, { name: 'users' });
renderAppOptions(Demo, { name: 'users' });

expect(screen.getByTestId('fields')).toHaveTextContent('1');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { render, screen, userEvent, waitFor } from '@nocobase/test/client';
import { CollectionDeletedPlaceholder, SchemaComponent, SchemaComponentProvider } from '@nocobase/client';
import { App } from 'antd';

function renderApp(name?: any, designable?: boolean) {
function renderAppOptions(name?: any, designable?: boolean) {
const schema = {
name: 'root',
type: 'void',
Expand All @@ -37,7 +37,7 @@ function renderApp(name?: any, designable?: boolean) {

describe('CollectionDeletedPlaceholder', () => {
test('name is undefined, render `Result` component', async () => {
renderApp(undefined, true);
renderAppOptions(undefined, true);

expect(screen.getByText('Delete')).toBeInTheDocument();
expect(screen.getByText('Collection name is required')).toBeInTheDocument();
Expand All @@ -55,15 +55,15 @@ describe('CollectionDeletedPlaceholder', () => {
});

test('designable: true, render `Result` component', () => {
renderApp('test', true);
renderAppOptions('test', true);
expect(screen.getByText('Delete')).toBeInTheDocument();
expect(
screen.getByText('The collection "test" may have been deleted. Please remove this block.'),
).toBeInTheDocument();
});

test('designable: false, render nothing', () => {
renderApp('test', false);
renderAppOptions('test', false);

expect(screen.queryByText('Delete')).not.toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const useTableBlockProps = () => {
}, [field, ctx?.service?.data, isLoading, ctx?.field?.data?.selectedRowKeys]);

return {
bordered: ctx.bordered,
childrenColumnName: ctx.childrenColumnName,
loading: ctx?.service?.loading,
showIndex: ctx.showIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import { ACLMenuItemProvider, AdminLayout, BlockSchemaComponentPlugin, CurrentUserProvider } from '@nocobase/client';
import { renderApp, waitFor, screen } from '@nocobase/test/client';
import { renderAppOptions, waitFor, screen } from '@nocobase/test/client';
import React from 'react';

describe('AdminLayout', () => {
it('should render correctly', async () => {
await renderApp({
await renderAppOptions({
designable: true,
noWrapperSchema: true,
appOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

import { RouteSchemaComponent } from '@nocobase/client';
import { renderApp, waitFor, screen } from '@nocobase/test/client';
import { renderAppOptions, waitFor, screen } from '@nocobase/test/client';
import React from 'react';

describe('route-schema-component', () => {
it('should render correctly', async () => {
await renderApp({
await renderAppOptions({
designable: true,
noWrapperSchema: true,
appOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/

import { renderApp, screen, userEvent, waitFor } from '@nocobase/test/client';
import { renderAppOptions, screen, userEvent, waitFor } from '@nocobase/test/client';
import { DataSourceCollectionCascader } from '../CollectionSelect';

describe('DataSourceCollectionCascader', () => {
test('should works', async () => {
await renderApp({
await renderAppOptions({
enableMultipleDataSource: true,
schema: {
type: 'string',
Expand Down
Loading

0 comments on commit 285f719

Please sign in to comment.