-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from Tencent/test/tab-bar/unit
test(tab-bar): add unit test
- Loading branch information
Showing
12 changed files
with
170 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
:: BASE_DOC :: | ||
|
||
## API | ||
### TabBar Props | ||
|
||
name | type | default | description | required | ||
-- | -- | -- | -- | -- | ||
bordered | Boolean | true | \- | N | ||
external-classes | Array | - | `['t-class']` | N | ||
fixed | Boolean | true | \- | N | ||
safe-area-inset-bottom | Boolean | true | \- | N | ||
split | Boolean | true | \- | N | ||
value | String / Number / Array | undefined | Typescript:`string | number | Array<string | number>` | N | ||
default-value | String / Number / Array | undefined | uncontrolled property。Typescript:`string | number | Array<string | number>` | N | ||
|
||
### TabBar Events | ||
|
||
name | params | description | ||
-- | -- | -- | ||
change | `(value: string | number)` | \- | ||
|
||
### TabBarItem Props | ||
|
||
name | type | default | description | required | ||
-- | -- | -- | -- | -- | ||
badge-props | Object | - | Typescript:`BadgeProps`,[Badge API Documents](./badge?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/tab-bar/type.ts) | N | ||
icon | String / Slot | - | \- | N | ||
sub-tab-bar | Array | - | Typescript:`SubTabBarItem[] ` `interface SubTabBarItem { value: string; label: string }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/tab-bar/type.ts) | N | ||
value | String / Number | - | \- | N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Component({ | ||
data: { | ||
value: 'label_1', | ||
list: [ | ||
{ value: 'label_1', label: 'value1', icon: 'app' }, | ||
{ value: 'label_2', label: 'value2', icon: 'app' }, | ||
{ | ||
value: 'label_3', | ||
label: 'value3', | ||
icon: 'app', | ||
children: [ | ||
{ | ||
value: 'spread_3', | ||
label: '展开项三', | ||
}, | ||
{ | ||
value: 'spread_2', | ||
label: '展开项二', | ||
}, | ||
{ | ||
value: 'spread_1', | ||
label: '展开项一', | ||
}, | ||
], | ||
}, | ||
{ value: undefined, label: 'value4', icon: 'app' }, | ||
], | ||
}, | ||
|
||
methods: { | ||
onChange(e) { | ||
this.setData({ | ||
value: e.detail.value, | ||
}); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"component": true, | ||
"usingComponents": { | ||
"t-tab-bar": "../tab-bar", | ||
"t-tab-bar-item": "../tab-bar-item" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import simulate from 'miniprogram-simulate'; | ||
import path from 'path'; | ||
|
||
describe('tab-bar', () => { | ||
const id = simulate.load(path.resolve(__dirname, `./index`), 't-tab-bar', { | ||
less: true, | ||
rootPath: path.resolve(__dirname, '../..'), | ||
}); | ||
|
||
it(':base', () => { | ||
const comp = simulate.render(id); | ||
comp.attach(document.createElement('parent-wrapper')); | ||
|
||
expect(comp.querySelector('#item1').instance.data.isChecked).toBeTruthy(); | ||
}); | ||
|
||
it(':events', async () => { | ||
const comp = simulate.render(id); | ||
comp.attach(document.createElement('parent-wrapper')); | ||
|
||
const $item2 = comp.querySelector('#item2'); | ||
const $content = $item2.querySelector('.t-tab-bar-item__content'); | ||
|
||
$content.dispatchEvent('tap'); | ||
|
||
await simulate.sleep(); | ||
|
||
expect($item2.instance.data.isChecked).toBeTruthy(); | ||
}); | ||
|
||
it(':sub', async () => { | ||
const comp = simulate.render(id); | ||
comp.attach(document.createElement('parent-wrapper')); | ||
|
||
const $item3 = comp.querySelector('#item3'); | ||
const $content = $item3.querySelector('.t-tab-bar-item__content'); | ||
|
||
$content.dispatchEvent('tap'); | ||
await simulate.sleep(); | ||
|
||
expect($item3.instance.data.isSpread).toBeTruthy(); | ||
|
||
const $spreadItem = $item3.querySelector('.t-tab-bar-item__spread-item'); | ||
|
||
$spreadItem.dispatchEvent('tap'); | ||
await simulate.sleep(); | ||
|
||
expect(comp.instance.data.value).toBe('spread_3'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<t-tab-bar id="base" value="{{value}}" bindchange="onChange"> | ||
<t-tab-bar-item | ||
wx:for="{{list}}" | ||
wx:key="index" | ||
id="item{{index+1}}" | ||
value="{{item.value}}" | ||
icon="{{item.icon}}" | ||
sub-tab-bar="{{item.children}}" | ||
> | ||
{{item.label}} | ||
</t-tab-bar-item> | ||
</t-tab-bar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters