From efbc3a9ce6694c10706518c905212fd248760f03 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Mon, 6 Dec 2021 00:16:43 +0800 Subject: [PATCH] test(SubmitBar): add demo test --- example/app.json | 1 + example/pages/submit-bar/index.js | 10 +- example/pages/submit-bar/index.wxml | 53 +-- packages/submit-bar/demo/index.json | 9 + .../submit-bar/demo/index.less | 0 packages/submit-bar/demo/index.ts | 19 + packages/submit-bar/demo/index.wxml | 52 ++ .../test/__snapshots__/demo.spec.ts.snap | 443 ++++++++++++++++++ packages/submit-bar/test/demo.spec.ts | 11 + 9 files changed, 537 insertions(+), 61 deletions(-) create mode 100644 packages/submit-bar/demo/index.json rename example/pages/submit-bar/index.wxss => packages/submit-bar/demo/index.less (100%) create mode 100644 packages/submit-bar/demo/index.ts create mode 100644 packages/submit-bar/demo/index.wxml create mode 100644 packages/submit-bar/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/submit-bar/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 5570a108..c53dd123 100644 --- a/example/app.json +++ b/example/app.json @@ -118,6 +118,7 @@ "van-sticky": "./dist/sticky/index", "van-sticky-demo": "./dist/sticky/demo/index", "van-submit-bar": "./dist/submit-bar/index", + "van-submit-bar-demo": "./dist/submit-bar/demo/index", "van-swipe-cell": "./dist/swipe-cell/index", "van-uploader": "./dist/uploader/index", "van-switch": "./dist/switch/index", diff --git a/example/pages/submit-bar/index.js b/example/pages/submit-bar/index.js index 840f498c..cc11dfda 100644 --- a/example/pages/submit-bar/index.js +++ b/example/pages/submit-bar/index.js @@ -1,11 +1,3 @@ import Page from '../../common/page'; -import Toast from '../../dist/toast/toast'; -Page({ - onClickButton() { - Toast('点击按钮'); - }, - onClickLink() { - Toast('修改地址'); - } -}); +Page(); diff --git a/example/pages/submit-bar/index.wxml b/example/pages/submit-bar/index.wxml index e64650fe..634f3580 100644 --- a/example/pages/submit-bar/index.wxml +++ b/example/pages/submit-bar/index.wxml @@ -1,52 +1 @@ - - - - - - - - - - - - - - - 标签 - - 您的收货地址不支持同城送 - 修改地址 - - - - - + diff --git a/packages/submit-bar/demo/index.json b/packages/submit-bar/demo/index.json new file mode 100644 index 00000000..6156459c --- /dev/null +++ b/packages/submit-bar/demo/index.json @@ -0,0 +1,9 @@ +{ + "component": true, + "usingComponents": { + "van-tag": "../../tag/index", + "van-toast": "../../toast/index", + "van-submit-bar": "../../submit-bar/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/submit-bar/index.wxss b/packages/submit-bar/demo/index.less similarity index 100% rename from example/pages/submit-bar/index.wxss rename to packages/submit-bar/demo/index.less diff --git a/packages/submit-bar/demo/index.ts b/packages/submit-bar/demo/index.ts new file mode 100644 index 00000000..a23b9483 --- /dev/null +++ b/packages/submit-bar/demo/index.ts @@ -0,0 +1,19 @@ +import { VantComponent } from '../../common/component'; +import Toast from '../../toast/toast'; + +VantComponent({ + methods: { + onClickButton() { + Toast({ + context: this, + message: '点击按钮', + }); + }, + onClickLink() { + Toast({ + context: this, + message: '修改地址', + }); + }, + }, +}); diff --git a/packages/submit-bar/demo/index.wxml b/packages/submit-bar/demo/index.wxml new file mode 100644 index 00000000..e64650fe --- /dev/null +++ b/packages/submit-bar/demo/index.wxml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + 标签 + + 您的收货地址不支持同城送 + 修改地址 + + + + + diff --git a/packages/submit-bar/test/__snapshots__/demo.spec.ts.snap b/packages/submit-bar/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..787f758d --- /dev/null +++ b/packages/submit-bar/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,443 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + + 合计: + + + + ¥ + + + 30 + + + .50 + + + + + + + + + + + 提交订单 + + + + + + + + + + + + + 禁用状态 + + + + + + + + + + 您的收货地址不支持同城送, 我们已为您推荐快递 + + + + + + + 合计: + + + + ¥ + + + 30 + + + .50 + + + + + + + + + + + 提交订单 + + + + + + + + + + + + + 加载状态 + + + + + + + + 合计: + + + + ¥ + + + 30 + + + .50 + + + + + + + + + + + + + + + + + + + + + + + + + 高级用法 + + + + + + + 您的收货地址不支持同城送 + + + 修改地址 + + + + + + + 标签 + + + + + 合计: + + + + ¥ + + + 30 + + + .50 + + + + + + + + + + + 提交订单 + + + + + + + + + + + + +
+`; diff --git a/packages/submit-bar/test/demo.spec.ts b/packages/submit-bar/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/submit-bar/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(); +});