From 689c5d82ed0cfc1ae6ffcd1716fdcd8b135a5028 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Thu, 2 Dec 2021 23:51:17 +0800 Subject: [PATCH] test(Search): add demo test --- example/app.json | 1 + example/pages/search/index.js | 44 +- example/pages/search/index.wxml | 57 +- example/pages/search/index.wxss | 0 packages/search/demo/index.json | 7 + packages/search/demo/index.ts | 47 ++ packages/search/demo/index.wxml | 56 ++ .../test/__snapshots__/demo.spec.ts.snap | 679 ++++++++++++++++++ packages/search/test/demo.spec.ts | 11 + 9 files changed, 803 insertions(+), 99 deletions(-) delete mode 100644 example/pages/search/index.wxss create mode 100644 packages/search/demo/index.json create mode 100644 packages/search/demo/index.ts create mode 100644 packages/search/demo/index.wxml create mode 100644 packages/search/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/search/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 0656fb8a..f10d1c23 100644 --- a/example/app.json +++ b/example/app.json @@ -107,6 +107,7 @@ "van-radio-group": "./dist/radio-group/index", "van-row": "./dist/row/index", "van-search": "./dist/search/index", + "van-search-demo": "./dist/search/demo/index", "van-sidebar": "./dist/sidebar/index", "van-sidebar-item": "./dist/sidebar-item/index", "van-slider": "./dist/slider/index", diff --git a/example/pages/search/index.js b/example/pages/search/index.js index bb7cf7a4..cc11dfda 100644 --- a/example/pages/search/index.js +++ b/example/pages/search/index.js @@ -1,45 +1,3 @@ import Page from '../../common/page'; -Page({ - data: { - value: '' - }, - - onChange(e) { - this.setData({ - value: e.detail - }); - }, - - onSearch() { - if (this.data.value) { - wx.showToast({ - title: '搜索:' + this.data.value, - icon: 'none' - }); - } - }, - - onClick() { - if (this.data.value) { - wx.showToast({ - title: '搜索:' + this.data.value, - icon: 'none' - }); - } - }, - - onCancel() { - wx.showToast({ - title: '取消', - icon: 'none' - }); - }, - - onClear() { - wx.showToast({ - title: '清空', - icon: 'none' - }); - } -}); +Page(); diff --git a/example/pages/search/index.wxml b/example/pages/search/index.wxml index 4c60d927..8079da56 100644 --- a/example/pages/search/index.wxml +++ b/example/pages/search/index.wxml @@ -1,56 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - 搜索 - - + diff --git a/example/pages/search/index.wxss b/example/pages/search/index.wxss deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/search/demo/index.json b/packages/search/demo/index.json new file mode 100644 index 00000000..d8396d84 --- /dev/null +++ b/packages/search/demo/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-search": "../../search/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/packages/search/demo/index.ts b/packages/search/demo/index.ts new file mode 100644 index 00000000..372149ba --- /dev/null +++ b/packages/search/demo/index.ts @@ -0,0 +1,47 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: { + value: '', + }, + + methods: { + onChange(e) { + this.setData({ + value: e.detail, + }); + }, + + onSearch() { + if (this.data.value) { + wx.showToast({ + title: '搜索:' + this.data.value, + icon: 'none', + }); + } + }, + + onClick() { + if (this.data.value) { + wx.showToast({ + title: '搜索:' + this.data.value, + icon: 'none', + }); + } + }, + + onCancel() { + wx.showToast({ + title: '取消', + icon: 'none', + }); + }, + + onClear() { + wx.showToast({ + title: '清空', + icon: 'none', + }); + }, + }, +}); diff --git a/packages/search/demo/index.wxml b/packages/search/demo/index.wxml new file mode 100644 index 00000000..4c60d927 --- /dev/null +++ b/packages/search/demo/index.wxml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + 搜索 + + diff --git a/packages/search/test/__snapshots__/demo.spec.ts.snap b/packages/search/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..cc72ecb9 --- /dev/null +++ b/packages/search/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,679 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基本用法 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 事件监听 + + + + + + + + + + + + + + + + + + + + + + + + + + 取消 + + + + + + + + + + 搜索框内容对齐 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 禁用搜索框 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 自定义背景色 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 自定义按钮 + + + + + + 地址 + + + + + + + + + + + + + + + + + + + + + + + 搜索 + + + + + + +
+`; diff --git a/packages/search/test/demo.spec.ts b/packages/search/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/search/test/demo.spec.ts @@ -0,0 +1,11 @@ +import path from 'path'; +import simulate from 'miniprogram-simulate'; + +test('should render demo and match snapshot', () => { + const id = simulate.load(path.resolve(__dirname, '../demo/index'), { + rootPath: path.resolve(__dirname, '../../'), + }); + const comp = simulate.render(id); + comp.attach(document.createElement('parent-wrapper')); + expect(comp.toJSON()).toMatchSnapshot(); +});