test(Switch): add demo test

This commit is contained in:
nemo-shen 2021-12-01 22:35:29 +08:00 committed by neverland
parent 1a01c0eae8
commit 3edbcdce53
9 changed files with 279 additions and 70 deletions

View File

@ -104,6 +104,7 @@
"van-swipe-cell": "./dist/swipe-cell/index",
"van-uploader": "./dist/uploader/index",
"van-switch": "./dist/switch/index",
"van-switch-demo": "./dist/switch/demo/index",
"van-tab": "./dist/tab/index",
"van-tabs": "./dist/tabs/index",
"van-tabbar": "./dist/tabbar/index",

View File

@ -1,22 +1,3 @@
import Page from '../../common/page';
import Dialog from '../../dist/dialog/dialog';
Page({
data: {
checked: true,
checked2: true
},
onChange({ detail }) {
this.setData({ checked: detail });
},
onChange2({ detail }) {
Dialog.confirm({
title: '提示',
message: '是否切换开关?'
}).then((res) => {
this.setData({ checked2: detail });
});
}
});
Page();

View File

@ -1,49 +1 @@
<demo-block title="基础用法" padding>
<van-switch
checked="{{ checked }}"
bind:change="onChange"
/>
</demo-block>
<demo-block title="禁用状态" padding>
<van-switch
checked="{{ checked }}"
disabled
bind:change="onChange"
/>
</demo-block>
<demo-block title="加载状态" padding>
<van-switch
checked="{{ checked }}"
loading
bind:change="onChange"
/>
</demo-block>
<demo-block title="自定义大小" padding>
<van-switch
checked="{{ checked }}"
size="24px"
bind:change="onChange"
/>
</demo-block>
<demo-block title="自定义颜色" padding>
<van-switch
checked="{{ checked }}"
active-color="#07c160"
inactive-color="#ee0a24"
bind:change="onChange"
/>
</demo-block>
<demo-block title="异步控制" padding>
<van-switch
checked="{{ checked2 }}"
size="36px"
bind:change="onChange2"
/>
</demo-block>
<van-dialog id="van-dialog" />
<van-switch-demo />

View File

@ -1 +0,0 @@
/* pages/switch/index.wxss */

View File

@ -0,0 +1,8 @@
{
"component": true,
"usingComponents": {
"van-switch": "../../switch/index",
"van-dialog": "../../dialog/index",
"demo-block": "../../../example/components/demo-block/index"
}
}

View File

@ -0,0 +1,25 @@
import { VantComponent } from '../../common/component';
import Dialog from '../../dialog/dialog';
VantComponent({
data: {
checked: true,
checked2: true,
},
methods: {
onChange({ detail }) {
this.setData({ checked: detail });
},
onChange2({ detail }) {
Dialog.confirm({
context: this,
title: '提示',
message: '是否切换开关?',
}).then(() => {
this.setData({ checked2: detail });
});
},
},
});

View File

@ -0,0 +1,49 @@
<demo-block title="基础用法" padding>
<van-switch
checked="{{ checked }}"
bind:change="onChange"
/>
</demo-block>
<demo-block title="禁用状态" padding>
<van-switch
checked="{{ checked }}"
disabled
bind:change="onChange"
/>
</demo-block>
<demo-block title="加载状态" padding>
<van-switch
checked="{{ checked }}"
loading
bind:change="onChange"
/>
</demo-block>
<demo-block title="自定义大小" padding>
<van-switch
checked="{{ checked }}"
size="24px"
bind:change="onChange"
/>
</demo-block>
<demo-block title="自定义颜色" padding>
<van-switch
checked="{{ checked }}"
active-color="#07c160"
inactive-color="#ee0a24"
bind:change="onChange"
/>
</demo-block>
<demo-block title="异步控制" padding>
<van-switch
checked="{{ checked2 }}"
size="36px"
bind:change="onChange2"
/>
</demo-block>
<van-dialog id="van-dialog" />

View File

@ -0,0 +1,183 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`should render demo and match snapshot 1`] = `
<main>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
基础用法
</wx-view>
<van-switch
bind:change="onChange"
>
<wx-view
class="van-switch van-switch--on custom-class"
style="font-size:30px"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
/>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
禁用状态
</wx-view>
<van-switch
bind:change="onChange"
>
<wx-view
class="van-switch van-switch--on van-switch--disabled custom-class"
style="font-size:30px"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
/>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
加载状态
</wx-view>
<van-switch
bind:change="onChange"
>
<wx-view
class="van-switch van-switch--on custom-class"
style="font-size:30px"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
>
<van-loading
customClass="van-switch__loading"
>
<wx-view
class="custom-class van-loading"
>
<wx-view
class="van-loading__spinner van-loading__spinner--circular"
style="color:#1989fa"
/>
<wx-view
class="van-loading__text"
style=""
/>
</wx-view>
</van-loading>
</wx-view>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
自定义大小
</wx-view>
<van-switch
bind:change="onChange"
>
<wx-view
class="van-switch van-switch--on custom-class"
style="font-size:24px"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
/>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
自定义颜色
</wx-view>
<van-switch
bind:change="onChange"
>
<wx-view
class="van-switch van-switch--on custom-class"
style="font-size:30px;background-color:#07c160"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
/>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix demo-block--padding"
>
<wx-view
class="demo-block__title"
>
异步控制
</wx-view>
<van-switch
bind:change="onChange2"
>
<wx-view
class="van-switch van-switch--on custom-class"
style="font-size:36px"
bind:tap="onClick"
>
<wx-view
class="van-switch__node node-class"
/>
</wx-view>
</van-switch>
</wx-view>
</demo-block>
<van-dialog>
<van-popup
customClass="van-dialog van-dialog--default "
bind:close="onClickOverlay"
>
<van-overlay
bind:click="onClickOverlay"
>
<van-transition
customClass="van-overlay"
bind:tap="onClick"
catch:touchmove="noop"
/>
</van-overlay>
</van-popup>
</van-dialog>
</main>
`;

View File

@ -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();
});