test(Rate): add demo test

This commit is contained in:
nemo-shen 2021-12-02 23:48:03 +08:00 committed by neverland
parent 89d2cdbd2d
commit 293f372da5
10 changed files with 1095 additions and 93 deletions

View File

@ -128,6 +128,7 @@
"van-tree-select": "./dist/tree-select/index",
"van-datetime-picker": "./dist/datetime-picker/index",
"van-rate": "./dist/rate/index",
"van-rate-demo": "./dist/rate/demo/index",
"van-collapse": "./dist/collapse/index",
"van-collapse-item": "./dist/collapse-item/index",
"van-picker": "./dist/picker/index",

View File

@ -1,18 +1,3 @@
import Page from '../../common/page';
import Toast from '../../dist/toast/toast';
Page({
data: {
value1: 3,
value2: 3,
value3: 3,
value4: 2.5,
value5: 4,
value6: 3,
value8: 2,
},
onChange(event) {
Toast('当前值:' + event.detail);
},
});
Page();

View File

@ -1,70 +1 @@
<demo-block title="基础用法">
<van-rate
custom-class="rate-position"
model:value="{{ value1 }}"
/>
</demo-block>
<demo-block title="自定义图标">
<van-rate
custom-class="rate-position"
icon="like"
void-icon="like-o"
model:value="{{ value2 }}"
/>
</demo-block>
<demo-block title="自定义样式">
<van-rate
custom-class="rate-position"
model:value="{{ value3 }}"
size="{{ 25 }}"
color="#ffd21e"
void-icon="star"
void-color="#eee"
/>
</demo-block>
<demo-block title="半星">
<van-rate
custom-class="rate-position"
model:value="{{ value4 }}"
allow-half
void-icon="star"
void-color="#eee"
/>
</demo-block>
<demo-block title="自定义数量">
<van-rate
custom-class="rate-position"
model:value="{{ value5 }}"
count="{{ 6 }}"
/>
</demo-block>
<demo-block title="禁用状态">
<van-rate
custom-class="rate-position"
value="{{ value6 }}"
disabled
/>
</demo-block>
<demo-block title="只读状态">
<van-rate
custom-class="rate-position"
value="{{ value6 }}"
readonly
/>
</demo-block>
<demo-block title="监听 change 事件">
<van-rate
custom-class="rate-position"
value="{{ value8 }}"
bind:change="onChange"
/>
</demo-block>
<van-toast id="van-toast" />
<van-rate-demo />

View File

@ -1,7 +0,0 @@
page {
background-color: #fff;
}
.rate-position {
margin-left: 15px;
}

View File

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

View File

@ -0,0 +1,3 @@
.rate-position {
margin-left: 15px;
}

View File

@ -0,0 +1,23 @@
import { VantComponent } from '../../common/component';
import Toast from '../../toast/toast';
VantComponent({
data: {
value1: 3,
value2: 3,
value3: 3,
value4: 2.5,
value5: 4,
value6: 3,
value8: 2,
},
methods: {
onChange(event) {
Toast({
context: this,
message: '当前值:' + event.detail,
});
},
},
});

View File

@ -0,0 +1,70 @@
<demo-block title="基础用法">
<van-rate
custom-class="rate-position"
model:value="{{ value1 }}"
/>
</demo-block>
<demo-block title="自定义图标">
<van-rate
custom-class="rate-position"
icon="like"
void-icon="like-o"
model:value="{{ value2 }}"
/>
</demo-block>
<demo-block title="自定义样式">
<van-rate
custom-class="rate-position"
model:value="{{ value3 }}"
size="{{ 25 }}"
color="#ffd21e"
void-icon="star"
void-color="#eee"
/>
</demo-block>
<demo-block title="半星">
<van-rate
custom-class="rate-position"
model:value="{{ value4 }}"
allow-half
void-icon="star"
void-color="#eee"
/>
</demo-block>
<demo-block title="自定义数量">
<van-rate
custom-class="rate-position"
model:value="{{ value5 }}"
count="{{ 6 }}"
/>
</demo-block>
<demo-block title="禁用状态">
<van-rate
custom-class="rate-position"
value="{{ value6 }}"
disabled
/>
</demo-block>
<demo-block title="只读状态">
<van-rate
custom-class="rate-position"
value="{{ value6 }}"
readonly
/>
</demo-block>
<demo-block title="监听 change 事件">
<van-rate
custom-class="rate-position"
value="{{ value8 }}"
bind:change="onChange"
/>
</demo-block>
<van-toast id="van-toast" />

View File

@ -0,0 +1,977 @@
// 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-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
自定义图标
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-like"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-like"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-like"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-like-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-like-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
自定义样式
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style="font-size:25px"
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#ffd21e"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style="font-size:25px"
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#ffd21e"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style="font-size:25px"
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#ffd21e"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style="font-size:25px"
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style="font-size:25px"
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
半星
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
<van-icon
class="van-rate__icon van-rate__icon--half van-rate__icon--full"
customClass="icon-class"
data-score="{{-0.5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
<van-icon
class="van-rate__icon van-rate__icon--half van-rate__icon--full"
customClass="icon-class"
data-score="{{0.5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
<van-icon
class="van-rate__icon van-rate__icon--half van-rate__icon--full"
customClass="icon-class"
data-score="{{1.5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
<van-icon
class="van-rate__icon van-rate__icon--half"
customClass="icon-class"
data-score="{{2.5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
<van-icon
class="van-rate__icon van-rate__icon--half"
customClass="icon-class"
data-score="{{3.5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style="color:#eee"
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
自定义数量
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{5}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
禁用状态
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--disabled van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--disabled van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--disabled van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--disabled"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--disabled"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
只读状态
</wx-view>
<van-rate
customClass="rate-position"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</wx-view>
</demo-block>
<demo-block>
<wx-view
class="custom-class demo-block van-clearfix "
>
<wx-view
class="demo-block__title"
>
监听 change 事件
</wx-view>
<van-rate
customClass="rate-position"
bind:change="onChange"
>
<wx-view
class="van-rate custom-class"
bind:touchmove="onTouchMove"
>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{0}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon van-rate__icon--full"
customClass="icon-class"
data-score="{{1}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{2}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{3}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
<wx-view
class="van-rate__item"
style=""
>
<van-icon
class="van-rate__icon"
customClass="icon-class"
data-score="{{4}}"
style=""
bind:click="onSelect"
>
<wx-view
class="custom-class van-icon van-icon-star-o"
style=""
bind:tap="onClick"
/>
</van-icon>
</wx-view>
</wx-view>
</van-rate>
</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();
});