补了点用例,以及一些小问题

This commit is contained in:
rickcole 2019-06-04 17:09:40 +08:00
parent a24047c6f6
commit 6d82c84827
5 changed files with 131 additions and 4 deletions

View File

@ -0,0 +1,77 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`api:cache 1`] = `
<div>
<div
class="a-Page"
>
<div
class="a-Page-content"
>
<div
class="a-Page-main"
>
<div
class="a-Page-toolbar"
>
<button
class="a-Button a-Button--default"
type="button"
>
<span>
Reload
</span>
</button>
</div>
<div
class="a-Page-body"
>
<span
class="a-TplField"
>
The variable value is 1
</span>
</div>
</div>
</div>
</div>
</div>
`;
exports[`api:cache 2`] = `
<div>
<div
class="a-Page"
>
<div
class="a-Page-content"
>
<div
class="a-Page-main"
>
<div
class="a-Page-toolbar"
>
<button
class="a-Button a-Button--default"
type="button"
>
<span>
Reload
</span>
</button>
</div>
<div
class="a-Page-body"
>
<span
class="a-TplField"
>
The variable value is 1
</span>
</div>
</div>
</div>
</div>
</div>
`;

View File

@ -1,3 +1,8 @@
import {
render as amisRender
} from '../../src/index';
import {wait, makeEnv} from '../helper';
import {render, fireEvent, cleanup} from 'react-testing-library';
import { import {
buildApi, buildApi,
isApiOutdated isApiOutdated
@ -143,4 +148,47 @@ test('api:isApiOutdated', () => {
a: 2, a: 2,
b: 2, b: 2,
})).toBeFalsy(); })).toBeFalsy();
});
test('api:cache', async () => {
let count = 1;
const fetcher = jest.fn().mockImplementation(() => Promise.resolve({
data: {
status: 0,
msg: 'ok',
data: {
a: count++
}
}
}));
const {
container,
getByText
} = render(amisRender({
type: 'page',
name: 'thepage',
initApi: {
method: 'get',
url: '/api/xxx?id=${id}',
cache: 2000
},
toolbar: {
type: 'button',
label: 'Reload',
actionType: 'reload',
target: 'thepage'
},
body: 'The variable value is ${a}'
}, {}, makeEnv({
fetcher
})));
await wait(100);
expect(container).toMatchSnapshot();
fireEvent.click(getByText(/Reload/));
await wait(100);
expect(fetcher).toHaveBeenCalledTimes(1); // 只请求一次,第二次请求从缓存中取
expect(container).toMatchSnapshot();
}); });

View File

@ -55,7 +55,7 @@ test('validation:isInt valid', () => {
expect(validate(1, {}, { expect(validate(1, {}, {
isInt: true isInt: true
}, { }, {
isInt: '请输入整数字' isInt: '请输入整数字'
})).toMatchObject([]); })).toMatchObject([]);
}); });
@ -63,8 +63,8 @@ test('validation:isInt invalid', () => {
expect(validate(1.1, {}, { expect(validate(1.1, {}, {
isInt: true isInt: true
}, { }, {
isInt: '请输入整数字' isInt: '请输入整数字'
})).toMatchObject(['请输入整数字']); })).toMatchObject(['请输入整数字']);
}); });
test('validation:isAlpha valid', () => { test('validation:isAlpha valid', () => {
@ -323,7 +323,7 @@ test('validation:multipleRules invalid', () => {
expect(validate('abc', {}, { expect(validate('abc', {}, {
isUrl: true, isUrl: true,
isInt: true isInt: true
})).toMatchObject(['Url 格式不正确', '请输入整数字']); })).toMatchObject(['Url 格式不正确', '请输入整数字']);
}); });
test('validation:matchRegexp valid', () => { test('validation:matchRegexp valid', () => {

View File

@ -120,6 +120,7 @@
font-size: $fontSizeSm; font-size: $fontSizeSm;
line-height: $fontSizeSm; line-height: $fontSizeSm;
text-align: center; text-align: center;
user-select: none;
} }
} }

View File

@ -31,6 +31,7 @@
flex-grow: 1; flex-grow: 1;
line-height: 1; line-height: 1;
max-width: 100%; max-width: 100%;
overflow: hidden;
} }
&-placeholder { &-placeholder {