test(SubmitBar): add demo test

This commit is contained in:
nemo-shen 2021-12-06 00:16:43 +08:00 committed by neverland
parent 3abd671715
commit efbc3a9ce6
9 changed files with 537 additions and 61 deletions

View File

@ -118,6 +118,7 @@
"van-sticky": "./dist/sticky/index",
"van-sticky-demo": "./dist/sticky/demo/index",
"van-submit-bar": "./dist/submit-bar/index",
"van-submit-bar-demo": "./dist/submit-bar/demo/index",
"van-swipe-cell": "./dist/swipe-cell/index",
"van-uploader": "./dist/uploader/index",
"van-switch": "./dist/switch/index",

View File

@ -1,11 +1,3 @@
import Page from '../../common/page';
import Toast from '../../dist/toast/toast';
Page({
onClickButton() {
Toast('点击按钮');
},
onClickLink() {
Toast('修改地址');
}
});
Page();

View File

@ -1,52 +1 @@
<demo-block title="基础用法">
<van-submit-bar
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="禁用状态">
<van-submit-bar
disabled
price="{{ 3050 }}"
button-text="提交订单"
tip="您的收货地址不支持同城送, 我们已为您推荐快递"
tip-icon="info-o"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="加载状态">
<van-submit-bar
loading
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="高级用法">
<van-submit-bar
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
tip="{{ true }}"
safe-area-inset-bottom="{{ false }}"
>
<van-tag type="primary" custom-class="submit-tag">标签</van-tag>
<view slot="tip">
您的收货地址不支持同城送
<text class="edit-address" bindtap="onClickLink">修改地址</text>
</view>
</van-submit-bar>
</demo-block>
<van-toast id="van-toast" />
<van-submit-bar-demo />

View File

@ -0,0 +1,9 @@
{
"component": true,
"usingComponents": {
"van-tag": "../../tag/index",
"van-toast": "../../toast/index",
"van-submit-bar": "../../submit-bar/index",
"demo-block": "../../../example/components/demo-block/index"
}
}

View File

@ -0,0 +1,19 @@
import { VantComponent } from '../../common/component';
import Toast from '../../toast/toast';
VantComponent({
methods: {
onClickButton() {
Toast({
context: this,
message: '点击按钮',
});
},
onClickLink() {
Toast({
context: this,
message: '修改地址',
});
},
},
});

View File

@ -0,0 +1,52 @@
<demo-block title="基础用法">
<van-submit-bar
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="禁用状态">
<van-submit-bar
disabled
price="{{ 3050 }}"
button-text="提交订单"
tip="您的收货地址不支持同城送, 我们已为您推荐快递"
tip-icon="info-o"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="加载状态">
<van-submit-bar
loading
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
safe-area-inset-bottom="{{ false }}"
/>
</demo-block>
<demo-block title="高级用法">
<van-submit-bar
price="{{ 3050 }}"
button-text="提交订单"
bind:submit="onClickButton"
custom-class="van-submit-bar"
tip="{{ true }}"
safe-area-inset-bottom="{{ false }}"
>
<van-tag type="primary" custom-class="submit-tag">标签</van-tag>
<view slot="tip">
您的收货地址不支持同城送
<text class="edit-address" bindtap="onClickLink">修改地址</text>
</view>
</van-submit-bar>
</demo-block>
<van-toast id="van-toast" />

View File

@ -0,0 +1,443 @@
// 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 "
>
<wx-view
class="demo-block__title"
>
基础用法
</wx-view>
<van-submit-bar
customClass="van-submit-bar"
bind:submit="onClickButton"
>
<wx-view
class="van-submit-bar custom-class"
>
<wx-view
class="van-submit-bar__tip"
/>
<wx-view
class="bar-class van-submit-bar__bar"
>
<wx-view
class="van-submit-bar__text"
>
<wx-text>
合计:
</wx-text>
<wx-text
class="van-submit-bar__price price-class"
>
<wx-text
class="van-submit-bar__currency"
>
¥
</wx-text>
<wx-text
class="van-submit-bar__price-integer"
>
30
</wx-text>
<wx-text>
.50
</wx-text>
</wx-text>
<wx-text
class="van-submit-bar__suffix-label"
>
</wx-text>
</wx-view>
<van-button
class="van-submit-bar__button"
customClass="button-class"
bind:click="onSubmit"
>
<wx-button
appParameter=""
ariaLabel=""
businessId="{{0}}"
class="custom-class van-button van-button--danger van-button--normal van-button--round "
data-detail="{{null}}"
formType=""
hoverClass="van-button--active hover-class"
id=""
lang=""
openType=""
sendMessageImg=""
sendMessagePath=""
sendMessageTitle=""
sessionFrom=""
showMessageCard="{{false}}"
style="width: 100%;"
bind:contact="onContact"
bind:error="onError"
bind:getphonenumber="onGetPhoneNumber"
bind:getuserinfo="onGetUserInfo"
bind:launchapp="onLaunchApp"
bind:opensetting="onOpenSetting"
bind:tap="onClick"
>
<wx-view
class="van-button__text"
>
提交订单
</wx-view>
</wx-button>
</van-button>
</wx-view>
</wx-view>
</van-submit-bar>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
禁用状态
</wx-view>
<van-submit-bar
customClass="van-submit-bar"
bind:submit="onClickButton"
>
<wx-view
class="van-submit-bar custom-class"
>
<wx-view
class="van-submit-bar__tip"
>
<van-icon
customClass="van-submit-bar__tip-icon"
>
<wx-view
class="custom-class van-icon van-icon-info-o"
style="font-size:12px"
bind:tap="onClick"
/>
</van-icon>
<wx-view
class="van-submit-bar__tip-text"
>
您的收货地址不支持同城送, 我们已为您推荐快递
</wx-view>
</wx-view>
<wx-view
class="bar-class van-submit-bar__bar"
>
<wx-view
class="van-submit-bar__text"
>
<wx-text>
合计:
</wx-text>
<wx-text
class="van-submit-bar__price price-class"
>
<wx-text
class="van-submit-bar__currency"
>
¥
</wx-text>
<wx-text
class="van-submit-bar__price-integer"
>
30
</wx-text>
<wx-text>
.50
</wx-text>
</wx-text>
<wx-text
class="van-submit-bar__suffix-label"
>
</wx-text>
</wx-view>
<van-button
class="van-submit-bar__button"
customClass="button-class"
bind:click="onSubmit"
>
<wx-button
appParameter=""
ariaLabel=""
businessId="{{0}}"
class="custom-class van-button van-button--danger van-button--normal van-button--round van-button--disabled van-button--unclickable "
data-detail="{{null}}"
formType=""
hoverClass="van-button--active hover-class"
id=""
lang=""
openType=""
sendMessageImg=""
sendMessagePath=""
sendMessageTitle=""
sessionFrom=""
showMessageCard="{{false}}"
style="width: 100%;"
bind:contact="onContact"
bind:error="onError"
bind:getphonenumber="onGetPhoneNumber"
bind:getuserinfo="onGetUserInfo"
bind:launchapp="onLaunchApp"
bind:opensetting="onOpenSetting"
bind:tap=""
>
<wx-view
class="van-button__text"
>
提交订单
</wx-view>
</wx-button>
</van-button>
</wx-view>
</wx-view>
</van-submit-bar>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
加载状态
</wx-view>
<van-submit-bar
customClass="van-submit-bar"
bind:submit="onClickButton"
>
<wx-view
class="van-submit-bar custom-class"
>
<wx-view
class="van-submit-bar__tip"
/>
<wx-view
class="bar-class van-submit-bar__bar"
>
<wx-view
class="van-submit-bar__text"
>
<wx-text>
合计:
</wx-text>
<wx-text
class="van-submit-bar__price price-class"
>
<wx-text
class="van-submit-bar__currency"
>
¥
</wx-text>
<wx-text
class="van-submit-bar__price-integer"
>
30
</wx-text>
<wx-text>
.50
</wx-text>
</wx-text>
<wx-text
class="van-submit-bar__suffix-label"
>
</wx-text>
</wx-view>
<van-button
class="van-submit-bar__button"
customClass="button-class"
bind:click="onSubmit"
>
<wx-button
appParameter=""
ariaLabel=""
businessId="{{0}}"
class="custom-class van-button van-button--danger van-button--normal van-button--round van-button--loading van-button--unclickable "
data-detail="{{null}}"
formType=""
hoverClass="van-button--active hover-class"
id=""
lang=""
openType=""
sendMessageImg=""
sendMessagePath=""
sendMessageTitle=""
sessionFrom=""
showMessageCard="{{false}}"
style="width: 100%;"
bind:contact="onContact"
bind:error="onError"
bind:getphonenumber="onGetPhoneNumber"
bind:getuserinfo="onGetUserInfo"
bind:launchapp="onLaunchApp"
bind:opensetting="onOpenSetting"
bind:tap=""
>
<van-loading
customClass="loading-class"
>
<wx-view
class="custom-class van-loading"
>
<wx-view
class="van-loading__spinner van-loading__spinner--circular"
style="color:#fff;width:20px;height:20px"
/>
<wx-view
class="van-loading__text"
style=""
/>
</wx-view>
</van-loading>
</wx-button>
</van-button>
</wx-view>
</wx-view>
</van-submit-bar>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
高级用法
</wx-view>
<van-submit-bar
customClass="van-submit-bar"
bind:submit="onClickButton"
>
<wx-view
class="van-submit-bar custom-class"
>
<wx-view
class="van-submit-bar__tip"
>
<wx-view
slot="tip"
>
您的收货地址不支持同城送
<wx-text
class="edit-address"
bind:tap="onClickLink"
>
修改地址
</wx-text>
</wx-view>
</wx-view>
<wx-view
class="bar-class van-submit-bar__bar"
>
<van-tag
customClass="submit-tag"
>
<wx-view
class="custom-class van-tag van-tag--primary"
style=""
>
标签
</wx-view>
</van-tag>
<wx-view
class="van-submit-bar__text"
>
<wx-text>
合计:
</wx-text>
<wx-text
class="van-submit-bar__price price-class"
>
<wx-text
class="van-submit-bar__currency"
>
¥
</wx-text>
<wx-text
class="van-submit-bar__price-integer"
>
30
</wx-text>
<wx-text>
.50
</wx-text>
</wx-text>
<wx-text
class="van-submit-bar__suffix-label"
>
</wx-text>
</wx-view>
<van-button
class="van-submit-bar__button"
customClass="button-class"
bind:click="onSubmit"
>
<wx-button
appParameter=""
ariaLabel=""
businessId="{{0}}"
class="custom-class van-button van-button--danger van-button--normal van-button--round "
data-detail="{{null}}"
formType=""
hoverClass="van-button--active hover-class"
id=""
lang=""
openType=""
sendMessageImg=""
sendMessagePath=""
sendMessageTitle=""
sessionFrom=""
showMessageCard="{{false}}"
style="width: 100%;"
bind:contact="onContact"
bind:error="onError"
bind:getphonenumber="onGetPhoneNumber"
bind:getuserinfo="onGetUserInfo"
bind:launchapp="onLaunchApp"
bind:opensetting="onOpenSetting"
bind:tap="onClick"
>
<wx-view
class="van-button__text"
>
提交订单
</wx-view>
</wx-button>
</van-button>
</wx-view>
</wx-view>
</van-submit-bar>
</wx-view>
</demo-block>
<van-toast
id="van-toast"
>
<van-transition
customClass="van-toast__container"
/>
</van-toast>
</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();
});