From 7cc03790436049e40e18cdebff776c7c1925fdb0 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Sun, 12 Dec 2021 22:55:48 +0800 Subject: [PATCH] test(IndexBar): add demo test --- example/app.json | 1 + example/pages/index-bar/index.js | 27 +- example/pages/index-bar/index.wxml | 46 +- example/pages/index-bar/index.wxss | 0 packages/index-bar/demo/index.json | 11 + packages/index-bar/demo/index.ts | 30 + packages/index-bar/demo/index.wxml | 45 + .../test/__snapshots__/demo.spec.ts.snap | 2037 +++++++++++++++++ packages/index-bar/test/demo.spec.ts | 11 + 9 files changed, 2137 insertions(+), 71 deletions(-) delete mode 100644 example/pages/index-bar/index.wxss create mode 100644 packages/index-bar/demo/index.json create mode 100644 packages/index-bar/demo/index.ts create mode 100644 packages/index-bar/demo/index.wxml create mode 100644 packages/index-bar/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/index-bar/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 49367492..e36c95fa 100644 --- a/example/app.json +++ b/example/app.json @@ -154,6 +154,7 @@ "van-circle": "./dist/circle/index", "van-circle-demo": "./dist/circle/demo/index", "van-index-bar": "./dist/index-bar/index", + "van-index-bar-demo": "./dist/index-bar/demo/index", "van-index-anchor": "./dist/index-anchor/index", "van-grid": "./dist/grid/index", "van-grid-demo": "./dist/grid/demo/index", diff --git a/example/pages/index-bar/index.js b/example/pages/index-bar/index.js index 1189fb35..cc11dfda 100644 --- a/example/pages/index-bar/index.js +++ b/example/pages/index-bar/index.js @@ -1,28 +1,3 @@ import Page from '../../common/page'; -const indexList = []; -const charCodeOfA = 'A'.charCodeAt(0); -for (let i = 0; i < 26; i++) { - indexList.push(String.fromCharCode(charCodeOfA + i)); -} - -Page({ - data: { - activeTab: 0, - indexList, - customIndexList: [1, 2, 3, 4, 5, 6, 8, 9, 10], - scrollTop: 0, - }, - - onChange(event) { - this.setData({ - activeTab: event.detail.name - }); - }, - - onPageScroll(event) { - this.setData({ - scrollTop: event.scrollTop - }); - } -}); +Page(); diff --git a/example/pages/index-bar/index.wxml b/example/pages/index-bar/index.wxml index 60e94f7e..8b13a82a 100644 --- a/example/pages/index-bar/index.wxml +++ b/example/pages/index-bar/index.wxml @@ -1,45 +1 @@ - - - - - - - - - - - - - - - - - 标题{{ item }} - - - - - - - - \ No newline at end of file + diff --git a/example/pages/index-bar/index.wxss b/example/pages/index-bar/index.wxss deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/index-bar/demo/index.json b/packages/index-bar/demo/index.json new file mode 100644 index 00000000..c50a6d9c --- /dev/null +++ b/packages/index-bar/demo/index.json @@ -0,0 +1,11 @@ +{ + "component": true, + "usingComponents": { + "van-tab": "../../tab/index", + "van-tabs": "../../tabs/index", + "van-cell": "../../cell/index", + "van-index-bar": "../../index-bar/index", + "van-index-anchor": "../../index-anchor/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/packages/index-bar/demo/index.ts b/packages/index-bar/demo/index.ts new file mode 100644 index 00000000..1f7c62e6 --- /dev/null +++ b/packages/index-bar/demo/index.ts @@ -0,0 +1,30 @@ +import { VantComponent } from '../../common/component'; + +const indexList: string[] = []; +const charCodeOfA = 'A'.charCodeAt(0); +for (let i = 0; i < 26; i++) { + indexList.push(String.fromCharCode(charCodeOfA + i)); +} + +VantComponent({ + data: { + activeTab: 0, + indexList, + customIndexList: [1, 2, 3, 4, 5, 6, 8, 9, 10], + scrollTop: 0, + }, + + methods: { + onChange(event) { + this.setData({ + activeTab: event.detail.name, + }); + }, + + onPageScroll(event) { + this.setData({ + scrollTop: event.scrollTop, + }); + }, + }, +}); diff --git a/packages/index-bar/demo/index.wxml b/packages/index-bar/demo/index.wxml new file mode 100644 index 00000000..d8b798f8 --- /dev/null +++ b/packages/index-bar/demo/index.wxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + 标题{{ item }} + + + + + + + + diff --git a/packages/index-bar/test/__snapshots__/demo.spec.ts.snap b/packages/index-bar/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..5217165e --- /dev/null +++ b/packages/index-bar/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,2037 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + + + + + + + + + + 基础用法 + + + + + + + 自定义索引列表 + + + + + + + + + + + + + + + + + + + + + A + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + B + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + C + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + D + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + E + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + F + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + G + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + H + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + I + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + J + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + K + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + L + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + M + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + N + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + O + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + P + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + Q + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + R + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + S + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + T + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + U + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + V + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + W + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + X + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + Y + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + Z + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + 文本 + + + + + + + + + + + + + + + +
+`; diff --git a/packages/index-bar/test/demo.spec.ts b/packages/index-bar/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/index-bar/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(); +});