From 338f90d5c55a749a37dde97bfa358615150c3be7 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Sun, 12 Dec 2021 23:03:19 +0800 Subject: [PATCH] test(Slider): add demo test --- example/app.json | 1 + example/pages/slider/index.js | 19 +- example/pages/slider/index.wxml | 84 +--- packages/slider/demo/index.json | 7 + .../slider/demo/index.less | 0 packages/slider/demo/index.ts | 22 + packages/slider/demo/index.wxml | 83 ++++ .../test/__snapshots__/demo.spec.ts.snap | 442 ++++++++++++++++++ packages/slider/test/demo.spec.ts | 11 + 9 files changed, 568 insertions(+), 101 deletions(-) create mode 100644 packages/slider/demo/index.json rename example/pages/slider/index.wxss => packages/slider/demo/index.less (100%) create mode 100644 packages/slider/demo/index.ts create mode 100644 packages/slider/demo/index.wxml create mode 100644 packages/slider/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/slider/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index be640f33..f90a52c6 100644 --- a/example/app.json +++ b/example/app.json @@ -119,6 +119,7 @@ "van-sidebar": "./dist/sidebar/index", "van-sidebar-item": "./dist/sidebar-item/index", "van-slider": "./dist/slider/index", + "van-slider-demo": "./dist/slider/demo/index", "van-stepper": "./dist/stepper/index", "van-stepper-demo": "./dist/stepper/demo/index", "van-steps": "./dist/steps/index", diff --git a/example/pages/slider/index.js b/example/pages/slider/index.js index 673c7a08..cc11dfda 100644 --- a/example/pages/slider/index.js +++ b/example/pages/slider/index.js @@ -1,20 +1,3 @@ import Page from '../../common/page'; -Page({ - data: { - currentValue: 50, - }, - - onChange(event) { - wx.showToast({ - icon: 'none', - title: `当前值:${event.detail}`, - }); - }, - - onDrag(event) { - this.setData({ - currentValue: event.detail.value, - }); - }, -}); +Page(); diff --git a/example/pages/slider/index.wxml b/example/pages/slider/index.wxml index 0a35ef8d..7e03ef7f 100644 --- a/example/pages/slider/index.wxml +++ b/example/pages/slider/index.wxml @@ -1,83 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{ currentValue }} - - - - - - - - - - + diff --git a/packages/slider/demo/index.json b/packages/slider/demo/index.json new file mode 100644 index 00000000..bdfd18ec --- /dev/null +++ b/packages/slider/demo/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-slider": "../../slider/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/slider/index.wxss b/packages/slider/demo/index.less similarity index 100% rename from example/pages/slider/index.wxss rename to packages/slider/demo/index.less diff --git a/packages/slider/demo/index.ts b/packages/slider/demo/index.ts new file mode 100644 index 00000000..3f8673d1 --- /dev/null +++ b/packages/slider/demo/index.ts @@ -0,0 +1,22 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: { + currentValue: 50, + }, + + methods: { + onChange(event) { + wx.showToast({ + icon: 'none', + title: `当前值:${event.detail}`, + }); + }, + + onDrag(event) { + this.setData({ + currentValue: event.detail.value, + }); + }, + }, +}); diff --git a/packages/slider/demo/index.wxml b/packages/slider/demo/index.wxml new file mode 100644 index 00000000..0a35ef8d --- /dev/null +++ b/packages/slider/demo/index.wxml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ currentValue }} + + + + + + + + + + diff --git a/packages/slider/test/__snapshots__/demo.spec.ts.snap b/packages/slider/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..47bbc3c0 --- /dev/null +++ b/packages/slider/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,442 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + + + + + + + + + + 双滑块 + + + + + + + + + + + + + + + + + + + 指定选择范围 + + + + + + + + + + + + + + + + 禁用 + + + + + + + + + + + + + + + + 指定步长 + + + + + + + + + + + + + + + + 自定义样式 + + + + + + + + + + + + + + + + 自定义按钮 + + + + + + + + 50 + + + + + + + + + + + + 垂直方向 + + + + + + + + + + + + + + + + + + + + + + + + + + +
+`; diff --git a/packages/slider/test/demo.spec.ts b/packages/slider/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/slider/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(); +});