From ce8955560e04cab25f66a7f8462e965cc0df4606 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Thu, 2 Dec 2021 23:59:47 +0800 Subject: [PATCH] test(Stepper): add demo test --- example/app.json | 1 + example/pages/stepper/index.js | 18 +- example/pages/stepper/index.wxml | 46 +- example/pages/stepper/index.wxss | 4 - packages/stepper/demo/index.json | 9 + packages/stepper/demo/index.ts | 22 + packages/stepper/demo/index.wxml | 45 ++ .../test/__snapshots__/demo.spec.ts.snap | 585 ++++++++++++++++++ packages/stepper/test/demo.spec.ts | 11 + 9 files changed, 675 insertions(+), 66 deletions(-) delete mode 100644 example/pages/stepper/index.wxss create mode 100644 packages/stepper/demo/index.json create mode 100644 packages/stepper/demo/index.ts create mode 100644 packages/stepper/demo/index.wxml create mode 100644 packages/stepper/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/stepper/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index de7e94ab..e96a0617 100644 --- a/example/app.json +++ b/example/app.json @@ -112,6 +112,7 @@ "van-sidebar-item": "./dist/sidebar-item/index", "van-slider": "./dist/slider/index", "van-stepper": "./dist/stepper/index", + "van-stepper-demo": "./dist/stepper/demo/index", "van-steps": "./dist/steps/index", "van-sticky": "./dist/sticky/index", "van-submit-bar": "./dist/submit-bar/index", diff --git a/example/pages/stepper/index.js b/example/pages/stepper/index.js index 27f22043..cc11dfda 100644 --- a/example/pages/stepper/index.js +++ b/example/pages/stepper/index.js @@ -1,19 +1,3 @@ import Page from '../../common/page'; -import Toast from '../../dist/toast/toast'; -Page({ - data: { - value: 1 - }, - - onChange(event) { - Toast.loading({ - forbidClick: true - }); - - setTimeout(() => { - Toast.clear(); - this.setData({ value: event.detail }); - }, 500); - } -}); +Page(); diff --git a/example/pages/stepper/index.wxml b/example/pages/stepper/index.wxml index 7d3d3de3..34ac9353 100644 --- a/example/pages/stepper/index.wxml +++ b/example/pages/stepper/index.wxml @@ -1,45 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/example/pages/stepper/index.wxss b/example/pages/stepper/index.wxss deleted file mode 100644 index f4ab9d80..00000000 --- a/example/pages/stepper/index.wxss +++ /dev/null @@ -1,4 +0,0 @@ -/* pages/stepper/index.wxss */ -page { - background-color: #fff; -} diff --git a/packages/stepper/demo/index.json b/packages/stepper/demo/index.json new file mode 100644 index 00000000..cbe9850f --- /dev/null +++ b/packages/stepper/demo/index.json @@ -0,0 +1,9 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../../cell/index", + "van-toast": "../../toast/index", + "van-stepper": "../../stepper/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/packages/stepper/demo/index.ts b/packages/stepper/demo/index.ts new file mode 100644 index 00000000..2ba5a038 --- /dev/null +++ b/packages/stepper/demo/index.ts @@ -0,0 +1,22 @@ +import { VantComponent } from '../../common/component'; +import Toast from '../../toast/toast'; + +VantComponent({ + data: { + value: 1, + }, + + methods: { + onChange(event) { + Toast.loading({ + context: this, + forbidClick: true, + }); + + setTimeout(() => { + Toast.clear(); + this.setData({ value: event.detail }); + }, 500); + }, + }, +}); diff --git a/packages/stepper/demo/index.wxml b/packages/stepper/demo/index.wxml new file mode 100644 index 00000000..3007ef89 --- /dev/null +++ b/packages/stepper/demo/index.wxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/stepper/test/__snapshots__/demo.spec.ts.snap b/packages/stepper/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..ba3d22a2 --- /dev/null +++ b/packages/stepper/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,585 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + + + + + + + + + + 步长设置 + + + + + + + + + + + + + + + + 限制输入范围 + + + + + + + + + + + + + + + + 限制输入整数 + + + + + + + + + + + + + + + + 禁用状态 + + + + + + + + + + + + + + + + 禁用长按 + + + + + + + + + + + + + + + + 固定小数位数 + + + + + + + + + + + + + + + + 异步变更 + + + + + + + + + + + + + + + + 自定义大小 + + + + + + + + + + + + + + + + 圆角风格 + + + + + + + + + + + + + + + +
+`; diff --git a/packages/stepper/test/demo.spec.ts b/packages/stepper/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/stepper/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(); +});