diff --git a/example/app.json b/example/app.json index 8c8c1e8c..b3ccf8e1 100644 --- a/example/app.json +++ b/example/app.json @@ -167,6 +167,7 @@ "van-grid-demo": "./dist/grid/demo/index", "van-grid-item": "./dist/grid-item/index", "van-dropdown-menu": "./dist/dropdown-menu/index", + "van-dropdown-menu-demo": "./dist/dropdown-menu/demo/index", "van-dropdown-item": "./dist/dropdown-item/index", "van-skeleton": "./dist/skeleton/index", "van-skeleton-demo": "./dist/skeleton/demo/index", diff --git a/example/pages/dropdown-menu/index.js b/example/pages/dropdown-menu/index.js index 0e0a1399..cc11dfda 100644 --- a/example/pages/dropdown-menu/index.js +++ b/example/pages/dropdown-menu/index.js @@ -1,35 +1,3 @@ import Page from '../../common/page'; -Page({ - data: { - switchTitle1: '包邮', - switchTitle2: '团购', - itemTitle: '筛选', - option1: [ - { text: '全部商品', value: 0 }, - { text: '新款商品', value: 1 }, - { text: '活动商品', value: 2 } - ], - option2: [ - { text: '默认排序', value: 'a' }, - { text: '好评排序', value: 'b' }, - { text: '销量排序', value: 'c' } - ], - switch1: true, - switch2: false, - value1: 0, - value2: 'a' - }, - - onConfirm () { - this.selectComponent('#item').toggle(); - }, - - onSwitch1Change ({ detail }) { - this.setData({ switch1: detail }); - }, - - onSwitch2Change ({ detail }) { - this.setData({ switch2: detail }); - } -}); +Page(); diff --git a/example/pages/dropdown-menu/index.wxml b/example/pages/dropdown-menu/index.wxml index c1dc606b..9f2813d0 100644 --- a/example/pages/dropdown-menu/index.wxml +++ b/example/pages/dropdown-menu/index.wxml @@ -1,61 +1 @@ - - - - - - - - - - - - - - - - - - - - 确认 - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/example/pages/dropdown-menu/index.wxss b/example/pages/dropdown-menu/index.wxss deleted file mode 100644 index 10df2838..00000000 --- a/example/pages/dropdown-menu/index.wxss +++ /dev/null @@ -1 +0,0 @@ -/** empty */ diff --git a/packages/dropdown-menu/demo/index.json b/packages/dropdown-menu/demo/index.json new file mode 100644 index 00000000..9a432700 --- /dev/null +++ b/packages/dropdown-menu/demo/index.json @@ -0,0 +1,11 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../../cell/index", + "van-switch": "../../switch/index", + "van-button": "../../button/index", + "van-dropdown-item": "../../dropdown-item/index", + "van-dropdown-menu": "../../dropdown-menu/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/packages/dropdown-menu/demo/index.ts b/packages/dropdown-menu/demo/index.ts new file mode 100644 index 00000000..87bf1782 --- /dev/null +++ b/packages/dropdown-menu/demo/index.ts @@ -0,0 +1,37 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: { + switchTitle1: '包邮', + switchTitle2: '团购', + itemTitle: '筛选', + option1: [ + { text: '全部商品', value: 0 }, + { text: '新款商品', value: 1 }, + { text: '活动商品', value: 2 }, + ], + option2: [ + { text: '默认排序', value: 'a' }, + { text: '好评排序', value: 'b' }, + { text: '销量排序', value: 'c' }, + ], + switch1: true, + switch2: false, + value1: 0, + value2: 'a', + }, + + methods: { + onConfirm() { + this.selectComponent('#item').toggle(); + }, + + onSwitch1Change({ detail }) { + this.setData({ switch1: detail }); + }, + + onSwitch2Change({ detail }) { + this.setData({ switch2: detail }); + }, + }, +}); diff --git a/packages/dropdown-menu/demo/index.wxml b/packages/dropdown-menu/demo/index.wxml new file mode 100644 index 00000000..a60cae2b --- /dev/null +++ b/packages/dropdown-menu/demo/index.wxml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + 确认 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap b/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..3836157f --- /dev/null +++ b/packages/dropdown-menu/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,293 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + + + 全部商品 + + + + + + + + + 默认排序 + + + + + + + + + + + + + + 自定义菜单内容 + + + + + + + + 全部商品 + + + + + + + + + 筛选 + + + + + + + + + + + + + + 自定义选中状态颜色 + + + + + + + + 全部商品 + + + + + + + + + 默认排序 + + + + + + + + + + + + + + 向上展开 + + + + + + + + 全部商品 + + + + + + + + + 默认排序 + + + + + + + + + + + + + + 禁用菜单 + + + + + + + + 全部商品 + + + + + + + + + 默认排序 + + + + + + + + + + +
+`; diff --git a/packages/dropdown-menu/test/demo.spec.ts b/packages/dropdown-menu/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/dropdown-menu/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(); +});