From e90eae2a9fa36b13ce4424d0941726575baf671f Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Sun, 12 Dec 2021 23:34:41 +0800 Subject: [PATCH] test(SwipeCell): add demo test --- example/app.json | 1 + example/pages/swipe-cell/index.js | 38 +-- example/pages/swipe-cell/index.wxml | 33 +-- packages/swipe-cell/demo/index.json | 11 + .../swipe-cell/demo/index.less | 0 packages/swipe-cell/demo/index.ts | 45 +++ packages/swipe-cell/demo/index.wxml | 32 +++ .../test/__snapshots__/demo.spec.ts.snap | 270 ++++++++++++++++++ packages/swipe-cell/test/demo.spec.ts | 11 + 9 files changed, 372 insertions(+), 69 deletions(-) create mode 100644 packages/swipe-cell/demo/index.json rename example/pages/swipe-cell/index.wxss => packages/swipe-cell/demo/index.less (100%) create mode 100644 packages/swipe-cell/demo/index.ts create mode 100644 packages/swipe-cell/demo/index.wxml create mode 100644 packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/swipe-cell/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index b3ccf8e1..ca9c7c9e 100644 --- a/example/app.json +++ b/example/app.json @@ -131,6 +131,7 @@ "van-submit-bar": "./dist/submit-bar/index", "van-submit-bar-demo": "./dist/submit-bar/demo/index", "van-swipe-cell": "./dist/swipe-cell/index", + "van-swipe-cell-demo": "./dist/swipe-cell/demo/index", "van-uploader": "./dist/uploader/index", "van-switch": "./dist/switch/index", "van-switch-demo": "./dist/switch/demo/index", diff --git a/example/pages/swipe-cell/index.js b/example/pages/swipe-cell/index.js index 2bce6e75..cc11dfda 100644 --- a/example/pages/swipe-cell/index.js +++ b/example/pages/swipe-cell/index.js @@ -1,39 +1,3 @@ import Page from '../../common/page'; -import Dialog from '../../dist/dialog/dialog'; -import Notify from '../../dist/notify/notify'; -Page({ - onClose(event) { - const { position, instance } = event.detail; - switch (position) { - case 'left': - case 'cell': - instance.close(); - break; - case 'right': - Dialog.confirm({ - message: '确定删除吗?' - }).then(() => { - instance.close(); - }); - break; - } - }, - onOpen(event) { - const { position, name } = event.detail; - switch (position) { - case 'left': - Notify({ - type: 'primary', - message: `${name}${position}部分展示open事件被触发` - }); - break; - case 'right': - Notify({ - type: 'primary', - message: `${name}${position}部分展示open事件被触发` - }); - break; - } - } -}); +Page(); diff --git a/example/pages/swipe-cell/index.wxml b/example/pages/swipe-cell/index.wxml index eab0b46a..317c98be 100644 --- a/example/pages/swipe-cell/index.wxml +++ b/example/pages/swipe-cell/index.wxml @@ -1,32 +1 @@ - - - 选择 - - - - 删除 - - - - - - 选择 - - - - 删除 - - - - - - 选择 - - - - 删除 - - - - - + diff --git a/packages/swipe-cell/demo/index.json b/packages/swipe-cell/demo/index.json new file mode 100644 index 00000000..d9be6118 --- /dev/null +++ b/packages/swipe-cell/demo/index.json @@ -0,0 +1,11 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../../cell/index", + "van-dialog": "../../dialog/index", + "van-notify": "../../notify/index", + "van-swipe-cell": "../../swipe-cell/index", + "van-cell-group": "../../cell-group/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/swipe-cell/index.wxss b/packages/swipe-cell/demo/index.less similarity index 100% rename from example/pages/swipe-cell/index.wxss rename to packages/swipe-cell/demo/index.less diff --git a/packages/swipe-cell/demo/index.ts b/packages/swipe-cell/demo/index.ts new file mode 100644 index 00000000..b5485f9e --- /dev/null +++ b/packages/swipe-cell/demo/index.ts @@ -0,0 +1,45 @@ +import { VantComponent } from '../../common/component'; +import Dialog from '../../dialog/dialog'; +import Notify from '../../notify/notify'; + +VantComponent({ + methods: { + onClose(event) { + const { position, instance } = event.detail; + switch (position) { + case 'left': + case 'cell': + instance.close(); + break; + case 'right': + Dialog.confirm({ + context: this, + message: '确定删除吗?', + }).then(() => { + instance.close(); + }); + break; + } + }, + + onOpen(event) { + const { position, name } = event.detail; + switch (position) { + case 'left': + Notify({ + context: this, + type: 'primary', + message: `${name}${position}部分展示open事件被触发`, + }); + break; + case 'right': + Notify({ + context: this, + type: 'primary', + message: `${name}${position}部分展示open事件被触发`, + }); + break; + } + }, + }, +}); diff --git a/packages/swipe-cell/demo/index.wxml b/packages/swipe-cell/demo/index.wxml new file mode 100644 index 00000000..eab0b46a --- /dev/null +++ b/packages/swipe-cell/demo/index.wxml @@ -0,0 +1,32 @@ + + + 选择 + + + + 删除 + + + + + + 选择 + + + + 删除 + + + + + + 选择 + + + + 删除 + + + + + diff --git a/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap b/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..56854a7f --- /dev/null +++ b/packages/swipe-cell/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,270 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + 选择 + + + + + + + + 单元格 + + + 内容 + + + + + + + + 删除 + + + + + + + + + + + 异步关闭 + + + + + + + 选择 + + + + + + + + 单元格 + + + 内容 + + + + + + + + 删除 + + + + + + + + + + + 主动打开 + + + + + + + 选择 + + + + + + + + 单元格 + + + 内容 + + + + + + + + 删除 + + + + + + + + + + + + + + + + + +
+`; diff --git a/packages/swipe-cell/test/demo.spec.ts b/packages/swipe-cell/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/swipe-cell/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(); +});