test: CRUD interval&stopAutoRefreshWhen

This commit is contained in:
meerkat 2022-07-12 11:29:08 +08:00
parent 1877ce78cb
commit 732fe128ed
2 changed files with 768 additions and 29 deletions

View File

@ -85,11 +85,11 @@ test('Renderer:crud basic interval', async () => {
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
await wait(1001); await wait(1001);
expect(mockFetcher.mock.calls.length).toEqual(2); expect(mockFetcher).toHaveBeenCalledTimes(2);
}); });
test('Renderer:crud stopAutoRefreshWhen', async () => { test('Renderer:crud stopAutoRefreshWhen', async () => {
const mockFetcher2 = jest.fn(fetcher); const mockFetcher = jest.fn(fetcher);
render( render(
amisRender( amisRender(
{ {
@ -109,16 +109,16 @@ test('Renderer:crud stopAutoRefreshWhen', async () => {
} }
}, },
{}, {},
makeEnv({fetcher: mockFetcher2}) makeEnv({fetcher: mockFetcher})
) )
); );
await wait(1500); await wait(1001);
expect(mockFetcher2.mock.calls.length).toEqual(1); expect(mockFetcher).toHaveBeenCalledTimes(1);
}); });
test('Renderer:crud loadDataOnce', async () => { test('Renderer:crud loadDataOnce', async () => {
const {container} = render( const {container, getByText, debug} = render(
amisRender( amisRender(
{ {
type: 'page', type: 'page',
@ -160,12 +160,12 @@ test('Renderer:crud loadDataOnce', async () => {
) )
); );
await wait(300); await waitFor(() => getByText('Internet Explorer 4.0'));
expect(container.querySelector('.cxd-Crud-pager')).not.toBeInTheDocument(); expect(container.querySelector('.cxd-Crud-pager')).not.toBeInTheDocument();
}); });
test('Renderer:crud list', async () => { test('Renderer:crud list', async () => {
const {container} = render( const {container, getByText} = render(
amisRender( amisRender(
{ {
type: 'page', type: 'page',
@ -187,12 +187,12 @@ test('Renderer:crud list', async () => {
) )
); );
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
await wait(300); await waitFor(() => getByText('Internet Explorer 4.0'));
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
test('Renderer:crud cards', async () => { test('Renderer:crud cards', async () => {
const {container} = render( const {container, getByText} = render(
amisRender( amisRender(
{ {
type: 'page', type: 'page',
@ -228,7 +228,9 @@ test('Renderer:crud cards', async () => {
); );
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
await wait(300); await waitFor(() =>
expect(container.querySelector('.cxd-Card-title')).toBeInTheDocument()
);
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
@ -266,9 +268,8 @@ test('Renderer:crud [source]', async () => {
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
test('Renderer:crud filter stopAutoRefreshWhen', async () => { test('Renderer:crud filter', async () => {
const mockFetcher = jest.fn(fetcher); const {container, getByText} = render(
const {container} = render(
amisRender( amisRender(
{ {
type: 'page', type: 'page',
@ -316,15 +317,11 @@ test('Renderer:crud filter stopAutoRefreshWhen', async () => {
} }
}, },
{}, {},
makeEnv({fetcher: mockFetcher}) makeEnv({fetcher})
) )
); );
await waitFor(() => { await waitFor(() => getByText('Internet Explorer 4.0'));
expect(
container.querySelector('[data-testid="spinner"]')
).not.toBeInTheDocument();
});
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
@ -375,6 +372,8 @@ test('Renderer:crud draggable & itemDraggableOn', async () => {
expect(container.querySelector('[icon="exchange"]')).toBeInTheDocument(); expect(container.querySelector('[icon="exchange"]')).toBeInTheDocument();
}); });
fireEvent.click(container.querySelector('[icon="exchange"]')!); fireEvent.click(container.querySelector('[icon="exchange"]')!);
await wait(50); await waitFor(() => {
expect(container.querySelector('[icon=drag]')).toBeInTheDocument();
});
expect(container.querySelectorAll('[icon=drag]').length).toBe(9); expect(container.querySelectorAll('[icon=drag]').length).toBe(9);
}); });

View File

@ -2365,7 +2365,7 @@ exports[`Renderer:crud cards 2`] = `
</div> </div>
`; `;
exports[`Renderer:crud filter stopAutoRefreshWhen 1`] = ` exports[`Renderer:crud filter 1`] = `
<div> <div>
<div <div
class="cxd-Page" class="cxd-Page"
@ -2665,16 +2665,603 @@ exports[`Renderer:crud filter stopAutoRefreshWhen 1`] = `
</thead> </thead>
<tbody> <tbody>
<tr <tr
class="cxd-Table-placeholder" class="cxd-Table-tr--odd cxd-Table-tr--1th"
data-id="1"
data-index="0"
> >
<td <td
colspan="6" class=""
> >
<icon-mock <span
classname="cxd-Table-placeholder-empty-icon icon icon-desk-empty" class="cxd-PlainField"
icon="desk-empty" >
/> 1
暂无数据 </span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Trident
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Internet Explorer 4.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 95+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
A
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--even cxd-Table-tr--1th"
data-id="2"
data-index="1"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
2
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Trident
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Internet Explorer 4.2
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 95+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
B
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--odd cxd-Table-tr--1th"
data-id="3"
data-index="2"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
3
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Trident
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
AOL browser (AOL desktop)
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 95+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
C
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--even cxd-Table-tr--1th"
data-id="4"
data-index="3"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Trident
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
AOL browser (AOL desktop)
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
3
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
A
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--odd cxd-Table-tr--1th"
data-id="5"
data-index="4"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
5
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Trident
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
AOL browser (AOL desktop)
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
A
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--even cxd-Table-tr--1th"
data-id="6"
data-index="5"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
6
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Gecko
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Firefox 1.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98+ / OSX.2+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
4
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
A
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--odd cxd-Table-tr--1th"
data-id="7"
data-index="6"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
7
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Gecko
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Firefox 1.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98+ / OSX.2+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
5
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
A
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--even cxd-Table-tr--1th"
data-id="8"
data-index="7"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
8
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Gecko
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Firefox 2.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98+ / OSX.2+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
5
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
B
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--odd cxd-Table-tr--1th"
data-id="9"
data-index="8"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
9
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Gecko
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Firefox 2.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98+ / OSX.2+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
5
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
C
</span>
</td>
</tr>
<tr
class="cxd-Table-tr--even cxd-Table-tr--1th"
data-id="10"
data-index="9"
>
<td
class=""
>
<span
class="cxd-PlainField"
>
10
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Gecko
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Firefox 2.0
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
Win 98+ / OSX.2+
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
5
</span>
</td>
<td
class=""
>
<span
class="cxd-PlainField"
>
D
</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -2919,6 +3506,159 @@ exports[`Renderer:crud filter stopAutoRefreshWhen 1`] = `
</table> </table>
</div> </div>
</div> </div>
<div
class="cxd-Table-toolbar cxd-Table-footToolbar"
>
<div
class="cxd-Crud-toolbar"
>
<div
class="cxd-Crud-toolbar-item cxd-Crud-toolbar-item--left"
>
<div
class="cxd-Crud-statistics"
>
1/15 总共144 项
</div>
</div>
<div
class="cxd-Crud-toolbar-item cxd-Crud-toolbar-item--right"
>
<div
class="cxd-Crud-pager"
>
<div
class="cxd-Pagination-wrap"
>
<ul
class="cxd-Pagination cxd-Pagination--sm cxd-Pagination-item"
>
<li
class="cxd-Pagination-prev is-disabled"
>
<span>
<icon-mock
classname="icon icon-left-arrow"
icon="left-arrow"
/>
</span>
</li>
<li
class="cxd-Pagination-pager-item is-active"
>
<a
role="button"
>
1
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
2
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
3
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
4
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
5
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
6
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
7
</a>
</li>
<li
class="ellipsis"
>
<a
role="button"
>
...
</a>
</li>
<li
class="cxd-Pagination-pager-item"
>
<a
role="button"
>
15
</a>
</li>
<li
class="cxd-Pagination-next"
>
<span>
<icon-mock
classname="icon icon-right-arrow"
icon="right-arrow"
/>
</span>
</li>
</ul>
<div
class="cxd-Pagination-inputGroup cxd-Pagination-item"
>
<span
class="cxd-Pagination-inputGroup-left"
>
跳转至
</span>
<input
class="cxd-Pagination-inputGroup-input"
type="text"
value=""
/>
<span
class="cxd-Pagination-inputGroup-right"
>
GO
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>