From f83192bb613091f9b49b1fa15a5ef9ed1aebb613 Mon Sep 17 00:00:00 2001 From: rickcole Date: Tue, 4 Jun 2019 17:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E4=BA=86=E7=82=B9=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E4=B8=80=E4=BA=9B=E5=B0=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/__snapshots__/api.test.ts.snap | 77 +++++++++++++++++++ __tests__/utils/api.test.ts | 48 ++++++++++++ __tests__/utils/validations.test.ts | 8 +- scss/components/_drawer.scss | 1 + scss/components/form/_select.scss | 1 + 5 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 __tests__/utils/__snapshots__/api.test.ts.snap diff --git a/__tests__/utils/__snapshots__/api.test.ts.snap b/__tests__/utils/__snapshots__/api.test.ts.snap new file mode 100644 index 00000000..3add3c24 --- /dev/null +++ b/__tests__/utils/__snapshots__/api.test.ts.snap @@ -0,0 +1,77 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`api:cache 1`] = ` +
+
+
+
+
+ +
+
+ + The variable value is 1 + +
+
+
+
+
+`; + +exports[`api:cache 2`] = ` +
+
+
+
+
+ +
+
+ + The variable value is 1 + +
+
+
+
+
+`; diff --git a/__tests__/utils/api.test.ts b/__tests__/utils/api.test.ts index c3221bde..ffcfc90c 100644 --- a/__tests__/utils/api.test.ts +++ b/__tests__/utils/api.test.ts @@ -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 { buildApi, isApiOutdated @@ -143,4 +148,47 @@ test('api:isApiOutdated', () => { a: 2, b: 2, })).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(); }); \ No newline at end of file diff --git a/__tests__/utils/validations.test.ts b/__tests__/utils/validations.test.ts index f84ca4db..ffacddee 100644 --- a/__tests__/utils/validations.test.ts +++ b/__tests__/utils/validations.test.ts @@ -55,7 +55,7 @@ test('validation:isInt valid', () => { expect(validate(1, {}, { isInt: true }, { - isInt: '请输入整形数字' + isInt: '请输入整型数字' })).toMatchObject([]); }); @@ -63,8 +63,8 @@ test('validation:isInt invalid', () => { expect(validate(1.1, {}, { isInt: true }, { - isInt: '请输入整形数字' - })).toMatchObject(['请输入整形数字']); + isInt: '请输入整型数字' + })).toMatchObject(['请输入整型数字']); }); test('validation:isAlpha valid', () => { @@ -323,7 +323,7 @@ test('validation:multipleRules invalid', () => { expect(validate('abc', {}, { isUrl: true, isInt: true - })).toMatchObject(['Url 格式不正确', '请输入整形数字']); + })).toMatchObject(['Url 格式不正确', '请输入整型数字']); }); test('validation:matchRegexp valid', () => { diff --git a/scss/components/_drawer.scss b/scss/components/_drawer.scss index b6e90224..4f74eaa9 100644 --- a/scss/components/_drawer.scss +++ b/scss/components/_drawer.scss @@ -120,6 +120,7 @@ font-size: $fontSizeSm; line-height: $fontSizeSm; text-align: center; + user-select: none; } } diff --git a/scss/components/form/_select.scss b/scss/components/form/_select.scss index d3e7d84d..6e947327 100644 --- a/scss/components/form/_select.scss +++ b/scss/components/form/_select.scss @@ -31,6 +31,7 @@ flex-grow: 1; line-height: 1; max-width: 100%; + overflow: hidden; } &-placeholder {