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(amis): table嵌套在crud下面,setValue时通过crud进行操作,解决crud的setValue动作失效的问题 Closes #11453 #11460

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
8 changes: 3 additions & 5 deletions packages/amis/__tests__/renderers/BarCode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {makeEnv, wait} from '../helper';
import 'jest-canvas-mock';

test('Renderer:bar-code', async () => {
const {container} = render(
const {findByTestId} = render(
amisRender(
{
type: 'page',
Expand All @@ -19,9 +19,7 @@ test('Renderer:bar-code', async () => {
makeEnv({})
)
);
await waitFor(() =>
expect(container.querySelector('.cxd-BarCode')).toBeInTheDocument()
);

expect(container).toMatchSnapshot();
const barcodeElement = await findByTestId('barcode');
expect(barcodeElement).toBeInTheDocument();
});
67 changes: 67 additions & 0 deletions packages/amis/__tests__/renderers/CRUD.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1896,3 +1896,70 @@ test('25. CRUD Table Cell sync data to store', async () => {
const listDoms2 = container.querySelectorAll('.cxd-ListItem-title');
expect(listDoms2.length).toEqual(0);
});

describe('26. setValue 动作', () => {
const renderCrud = (mode: string) =>
render(
amisRender({
type: 'crud',
id: 'crud',
mode,
data: {
label: '点击前'
},
headerToolbar: [
{
type: 'button',
label: '${label}',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'crud',
args: {
value: {label: '点击后'}
}
}
]
}
}
}
]
})
);

it('table模式下,设置值后,页面能够自动更新', async () => {
renderCrud('table');

await waitFor(() => {
expect(screen.getByText('点击前')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('点击前'));

await waitFor(() => {
expect(screen.getByText('点击后')).toBeInTheDocument();
});
});

it('cards模式下,设置值后,页面能够自动更新', () => {
renderCrud('cards');

expect(screen.getByText('点击前')).toBeInTheDocument();

fireEvent.click(screen.getByText('点击前'));

expect(screen.getByText('点击后')).toBeInTheDocument();
});

it('list模式下,设置值后,页面能够自动更新', () => {
renderCrud('list');

expect(screen.getByText('点击前')).toBeInTheDocument();

fireEvent.click(screen.getByText('点击前'));

expect(screen.getByText('点击后')).toBeInTheDocument();
});
});
14 changes: 5 additions & 9 deletions packages/amis/__tests__/renderers/JSON.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React = require('react');
import {render, waitFor} from '@testing-library/react';
import {findByText, render, waitFor, screen} from '@testing-library/react';
import '../../src';
import {render as amisRender} from '../../src';
import {makeEnv, wait} from '../helper';

test('Renderer:json', async () => {
const {container} = render(
const {findByText} = render(
amisRender(
{
type: 'page',
body: {
type: 'json',
value: {
a: 'a',
b: 'b',
c: {
d: 'd'
}
aKey: 'aValue'
}
}
},
Expand All @@ -25,6 +21,6 @@ test('Renderer:json', async () => {
)
);

await wait(1000);
expect(container).toMatchSnapshot();
const jsonElement = await findByText('aKey');
expect(jsonElement).toBeInTheDocument();
});

This file was deleted.

Loading
Loading