Skip to content

Commit eaabb87

Browse files
committed
test: actionsheet badge cells checkbox dialog
1 parent ac84c9e commit eaabb87

21 files changed

+342
-0
lines changed

test/actionsheet/actionsheet.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('actionsheet', () => {
5+
const id = simulate.load(path.join(__dirname, './index'))
6+
test('basic actionsheet', async () => {
7+
const container = simulate.render(id)
8+
const comp = container.querySelector('.comp')
9+
10+
const parent = document.createElement('parent-wrapper')
11+
container.attach(parent)
12+
13+
const title = comp.querySelector('.weui-actionsheet__title-text')
14+
const mask = comp.querySelector('.weui-mask')
15+
const menu = comp.querySelectorAll('.weui-actionsheet__menu .weui-actionsheet__cell')
16+
const cancel = comp.querySelector('.weui-actionsheet__action .weui-actionsheet__cell')
17+
18+
expect(title.dom.innerHTML).toBe('actionsheet title')
19+
expect(mask.dom.className.indexOf('weui-mask_hidden')).toBe(-1)
20+
expect(mask.dom.className.indexOf('customer-mask-class')).toBeGreaterThan(-1)
21+
expect(menu.length).toBe(3)
22+
expect(menu[2].dom.className.indexOf('weui-actionsheet__cell_warn')).toBeGreaterThan(-1)
23+
expect(cancel.dom.innerHTML).toBe('actionsheet cancel text')
24+
25+
menu[2].dispatchEvent('touchstart')
26+
menu[2].dispatchEvent('touchend')
27+
await simulate.sleep(10)
28+
expect(container.querySelector('.tapvalue').dom.innerHTML).toBe('3')
29+
30+
menu[1].dispatchEvent('touchstart')
31+
menu[1].dispatchEvent('touchend')
32+
await simulate.sleep(10)
33+
expect(container.querySelector('.tapvalue').dom.innerHTML).toBe('2')
34+
35+
cancel.dispatchEvent('touchstart')
36+
cancel.dispatchEvent('touchend')
37+
await simulate.sleep(10)
38+
expect(container.querySelector('.close').dom.innerHTML).toBe('true')
39+
})
40+
})

test/actionsheet/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Component({
2+
data: {
3+
tapValue: 0,
4+
actions: [
5+
{ text: 'item 1', value: 1 },
6+
{ text: 'item 2', value: 2 },
7+
{ text: 'item 3', type: 'warn', value: 3 }
8+
]
9+
},
10+
methods: {
11+
actiontap(event) {
12+
this.setData({
13+
tapValue: event.detail.value
14+
})
15+
},
16+
close() {
17+
this.setData({
18+
close: 'true'
19+
})
20+
}
21+
}
22+
})

test/actionsheet/index.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"mp-actionsheet": "../../miniprogram_dist/actionsheet/actionsheet"
5+
}
6+
}

test/actionsheet/index.wxml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<mp-actionsheet
2+
class="comp"
3+
title="actionsheet title"
4+
show-cancel="{{true}}"
5+
cancel-text="actionsheet cancel text"
6+
show="{{true}}"
7+
mask-class="customer-mask-class"
8+
actions="{{actions}}"
9+
bindactiontap="actiontap"
10+
bindclose="close"
11+
>
12+
</mp-actionsheet>
13+
<view class="tapvalue">{{tapValue}}</view>
14+
<view class="close">{{close}}</view>

test/badge/badge.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('badge', () => {
5+
const id = simulate.load(path.join(__dirname, '../../miniprogram_dist/badge/badge'))
6+
test('badge with content', () => {
7+
const content = 'badge content'
8+
const comp = simulate.render(id, {
9+
content: content
10+
})
11+
12+
const parent = document.createElement('parent-wrapper')
13+
comp.attach(parent)
14+
15+
const view = comp.querySelector('.weui-badge')
16+
expect(view.dom.innerHTML).toBe(content)
17+
})
18+
19+
test('badge without content', () => {
20+
const comp = simulate.render(id, {})
21+
22+
const parent = document.createElement('parent-wrapper')
23+
comp.attach(parent)
24+
25+
const view = comp.querySelector('.weui-badge')
26+
expect(view.dom.className.indexOf('weui-badge_dot')).toBeGreaterThan(-1)
27+
})
28+
})

test/cells/cells.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('cells & cell', () => {
5+
const id = simulate.load(path.join(__dirname, './index'))
6+
test('basic cells & cell', () => {
7+
const container = simulate.render(id)
8+
container.attach(document.createElement('parent-wrapper'))
9+
10+
const cells = container.querySelector('.cells')
11+
expect(cells.querySelector('.weui-cells__title').dom.innerHTML).toBe('带图标、说明的列表项')
12+
expect(cells.querySelector('.weui-cells__tips').dom.innerHTML).toBe('底部说明文字')
13+
14+
const cell1 = container.querySelector('.cell1')
15+
const cell2 = container.querySelector('.cell2')
16+
expect(cell1.querySelector('.weui-cell__bd').dom.innerHTML).toBe('标题文字')
17+
expect(cell1.querySelector('.weui-cell__ft').dom.innerHTML).toBe('说明文字')
18+
expect(cell1.querySelector('.weui-cell__icon').dom.innerHTML).toBe('')
19+
expect(cell2.querySelector('.weui-cell__icon')).toBe(undefined)
20+
})
21+
})

test/cells/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Component({
2+
data: {
3+
tapValue: 0,
4+
actions: [
5+
{ text: 'item 1', value: 1 },
6+
{ text: 'item 2', value: 2 },
7+
{ text: 'item 3', type: 'warn', value: 3 }
8+
]
9+
},
10+
methods: {
11+
actiontap(event) {
12+
this.setData({
13+
tapValue: event.detail.value
14+
})
15+
},
16+
close() {
17+
this.setData({
18+
close: 'true'
19+
})
20+
}
21+
}
22+
})

test/cells/index.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"mp-cells": "../../miniprogram_dist/cells/cells",
5+
"mp-cell": "../../miniprogram_dist/cell/cell"
6+
}
7+
}

test/cells/index.wxml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<mp-cells class="cells" title="带图标、说明的列表项" footer="底部说明文字">
2+
<mp-cell class="cell1" value="标题文字" footer="说明文字" icon="success"></mp-cell>
3+
<mp-cell class="cell2" value="标题文字" footer="说明文字"></mp-cell>
4+
</mp-cells>

test/checkbox/checkbox.test.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('checkbox-group & checkbox', () => {
5+
const id = simulate.load(path.join(__dirname, './index'))
6+
test('basic checkbox', async () => {
7+
const container = simulate.render(id)
8+
container.attach(document.createElement('parent-wrapper'))
9+
10+
const radioGroup = container.querySelector('.radio-group')
11+
const checkboxGroup = container.querySelector('.checkbox-group')
12+
13+
radioGroup.dispatchEvent('change', {
14+
detail: {
15+
value: '0'
16+
}
17+
})
18+
await simulate.sleep(10)
19+
expect(container.querySelector('.radio-value').dom.innerHTML).toBe('0')
20+
21+
radioGroup.dispatchEvent('change', {
22+
detail: {
23+
value: '1'
24+
}
25+
})
26+
await simulate.sleep(10)
27+
expect(container.querySelector('.radio-value').dom.innerHTML).toBe('1')
28+
29+
checkboxGroup.dispatchEvent('change', {
30+
detail: {
31+
value: ['0', '1']
32+
}
33+
})
34+
await simulate.sleep(10)
35+
expect(container.querySelector('.checkbox-value').dom.innerHTML).toBe('0,1')
36+
37+
checkboxGroup.dispatchEvent('change', {
38+
detail: {
39+
value: ['1']
40+
}
41+
})
42+
await simulate.sleep(10)
43+
expect(container.querySelector('.checkbox-value').dom.innerHTML).toBe('1')
44+
})
45+
})

test/checkbox/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Component({
2+
data: {
3+
radioItems: [
4+
{ name: 'cell standard', value: '0' },
5+
{ name: 'cell standard', value: '1' }
6+
],
7+
checkboxItems: [
8+
{ name: 'standard is dealt for u.', value: '0' },
9+
{ name: 'standard is dealicient for u.', value: '1' }
10+
],
11+
radioValue: '',
12+
checkboxValue: 0
13+
},
14+
methods: {
15+
radioChange(e) {
16+
this.setData({
17+
radioValue: e.detail.value
18+
})
19+
},
20+
checkboxChange(e) {
21+
this.setData({
22+
checkboxValue: e.detail.value.join(',')
23+
})
24+
}
25+
}
26+
})

test/checkbox/index.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"mp-checkbox-group": "../../miniprogram_dist/checkbox-group/checkbox-group",
5+
"mp-checkbox": "../../miniprogram_dist/checkbox/checkbox"
6+
}
7+
}

test/checkbox/index.wxml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<mp-cells title="单选列表项">
2+
<mp-checkbox-group class="radio-group" prop="radio" multi="{{false}}" bindchange="radioChange">
3+
<mp-checkbox class="test-radio" wx:for="{{radioItems}}" wx:key="value" label="{{item.name}}" value="{{item.value}}" checked="{{item.checked}}"></mp-checkbox>
4+
</mp-checkbox-group>
5+
</mp-cells>
6+
<view class="radio-value">{{radioValue}}</view>
7+
<mp-cells title="复选列表项">
8+
<mp-checkbox-group class="checkbox-group" prop="checkbox" multi="{{true}}" bindchange="checkboxChange">
9+
<mp-checkbox class="test-checkbox" wx:for="{{checkboxItems}}" wx:key="value" label="{{item.name}}" value="{{item.value}}" checked="{{item.checked}}"></mp-checkbox>
10+
</mp-checkbox-group>
11+
</mp-cells>
12+
<view class="checkbox-value">{{checkboxValue}}</view>

test/dialog/dialog.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('dialog', () => {
5+
const id = simulate.load(path.join(__dirname, './index'))
6+
test('basic dialog', async () => {
7+
const container = simulate.render(id)
8+
container.attach(document.createElement('parent-wrapper'))
9+
10+
const dialog = container.querySelector('.dialog')
11+
const buttons = dialog.querySelectorAll('.weui-dialog__btn')
12+
13+
buttons[0].dispatchEvent('tap')
14+
await simulate.sleep(10)
15+
expect(container.querySelector('.button-value').dom.innerHTML).toBe('取消')
16+
17+
buttons[1].dispatchEvent('tap')
18+
await simulate.sleep(10)
19+
expect(container.querySelector('.button-value').dom.innerHTML).toBe('确定')
20+
21+
dialog.querySelector('.weui-mask').dispatchEvent('tap')
22+
await simulate.sleep(10)
23+
expect(container.querySelector('.close').dom.innerHTML).toBe('true')
24+
// dialog.setData({
25+
// show: false
26+
// })
27+
await simulate.sleep(200)
28+
expect(dialog.querySelector('.weui-dialog')).toBe(undefined)
29+
})
30+
})

test/dialog/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Component({
2+
data: {
3+
buttonValue: '',
4+
closed: '',
5+
buttons: [{ text: '取消' }, { text: '确定' }]
6+
},
7+
methods: {
8+
buttontap(e) {
9+
this.setData({
10+
buttonValue: e.detail.item.text
11+
})
12+
},
13+
close(e) {
14+
this.setData({
15+
closed: 'true'
16+
})
17+
}
18+
}
19+
})

test/dialog/index.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"mp-dialog": "../../miniprogram_dist/dialog/dialog"
5+
}
6+
}

test/dialog/index.wxml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<mp-dialog
2+
class="dialog"
3+
title="dialog title"
4+
show="{{true}}"
5+
buttons="{{buttons}}"
6+
bindbuttontap="buttontap"
7+
bindclose="close"
8+
>
9+
</mp-dialog>
10+
<view class="button-value">{{buttonValue}}</view>
11+
<view class="close">{{closed}}</view>

test/template/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Component({
2+
data: {},
3+
methods: {}
4+
})

test/template/index.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"component": true,
3+
"usingComponents": {
4+
"mp-actionsheet": "../../miniprogram_dist/actionsheet/actionsheet"
5+
}
6+
}

test/template/index.wxml

Whitespace-only changes.

test/template/test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import path from 'path'
2+
import simulate from 'miniprogram-simulate'
3+
4+
describe('', () => {
5+
const id = simulate.load(path.join(__dirname, './index'))
6+
test('', () => {
7+
const container = simulate.render(id)
8+
container.attach(document.createElement('parent-wrapper'))
9+
10+
// TODO: xxx
11+
})
12+
})

0 commit comments

Comments
 (0)