From 46a4c7c4f235ae13e1a218013793f5f453c83032 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Mon, 6 Dec 2021 23:54:25 +0800 Subject: [PATCH] test(GoodsAction): add demo test --- example/app.json | 1 + example/pages/goods-action/index.js | 11 +- example/pages/goods-action/index.wxml | 54 +- packages/goods-action/demo/index.json | 10 + .../goods-action/demo/index.less | 0 packages/goods-action/demo/index.ts | 14 + packages/goods-action/demo/index.wxml | 53 + .../test/__snapshots__/demo.spec.ts.snap | 1043 +++++++++++++++++ packages/goods-action/test/demo.spec.ts | 11 + 9 files changed, 1134 insertions(+), 63 deletions(-) create mode 100644 packages/goods-action/demo/index.json rename example/pages/goods-action/index.wxss => packages/goods-action/demo/index.less (100%) create mode 100644 packages/goods-action/demo/index.ts create mode 100644 packages/goods-action/demo/index.wxml create mode 100644 packages/goods-action/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/goods-action/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 73a0d48b..e0e49d53 100644 --- a/example/app.json +++ b/example/app.json @@ -88,6 +88,7 @@ "van-empty-demo": "./dist/empty/demo/index", "van-field": "./dist/field/index", "van-goods-action": "./dist/goods-action/index", + "van-goods-action-demo": "./dist/goods-action/demo/index", "van-goods-action-icon": "./dist/goods-action-icon/index", "van-goods-action-button": "./dist/goods-action-button/index", "van-icon": "./dist/icon/index", diff --git a/example/pages/goods-action/index.js b/example/pages/goods-action/index.js index dd9a1357..cc11dfda 100644 --- a/example/pages/goods-action/index.js +++ b/example/pages/goods-action/index.js @@ -1,12 +1,3 @@ import Page from '../../common/page'; -import Toast from '../../dist/toast/toast'; -Page({ - onClickIcon() { - Toast('点击图标'); - }, - - onClickButton() { - Toast('点击按钮'); - } -}); +Page(); diff --git a/example/pages/goods-action/index.wxml b/example/pages/goods-action/index.wxml index ce606803..d78cf234 100644 --- a/example/pages/goods-action/index.wxml +++ b/example/pages/goods-action/index.wxml @@ -1,53 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/packages/goods-action/demo/index.json b/packages/goods-action/demo/index.json new file mode 100644 index 00000000..6af9d2d4 --- /dev/null +++ b/packages/goods-action/demo/index.json @@ -0,0 +1,10 @@ +{ + "component": true, + "usingComponents": { + "van-toast": "../../toast/index", + "van-goods-action": "../../goods-action/index", + "van-goods-action-icon": "../../goods-action-icon/index", + "van-goods-action-button": "../../goods-action-button/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/goods-action/index.wxss b/packages/goods-action/demo/index.less similarity index 100% rename from example/pages/goods-action/index.wxss rename to packages/goods-action/demo/index.less diff --git a/packages/goods-action/demo/index.ts b/packages/goods-action/demo/index.ts new file mode 100644 index 00000000..7e2cc741 --- /dev/null +++ b/packages/goods-action/demo/index.ts @@ -0,0 +1,14 @@ +import { VantComponent } from '../../common/component'; +import Toast from '../../toast/toast'; + +VantComponent({ + methods: { + onClickIcon() { + Toast({ context: this, message: '点击图标' }); + }, + + onClickButton() { + Toast({ context: this, message: '点击按钮' }); + }, + }, +}); diff --git a/packages/goods-action/demo/index.wxml b/packages/goods-action/demo/index.wxml new file mode 100644 index 00000000..ce606803 --- /dev/null +++ b/packages/goods-action/demo/index.wxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/goods-action/test/__snapshots__/demo.spec.ts.snap b/packages/goods-action/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..90e7aaec --- /dev/null +++ b/packages/goods-action/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,1043 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + + + + + + + + 客服 + + + + + + + + + + + + + + + + 购物车 + + + + + + + + + + + 加入购物车 + + + + + + + + + + + 立即购买 + + + + + + + + + + + + + 提示信息 + + + + + + + + + + + + + + + + + + 客服 + + + + + + + + + + + + + + 5 + + + + + + 购物车 + + + + + + + + + + + + + + + + 店铺 + + + + + + + + + + + 加入购物车 + + + + + + + + + + + 立即购买 + + + + + + + + + + + + + 自定义按钮颜色 + + + + + + + + + + + + + + 客服 + + + + + + + + + + + + + + + + 店铺 + + + + + + + + + + + 加入购物车 + + + + + + + + + + + 立即购买 + + + + + + + + + + + + + 朴素按钮 + + + + + + + + + + + + + + 客服 + + + + + + + + + + + + + + + + 店铺 + + + + + + + + + + + 加入购物车 + + + + + + + + + + + 立即购买 + + + + + + + + + + + + +
+`; diff --git a/packages/goods-action/test/demo.spec.ts b/packages/goods-action/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/goods-action/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(); +});