1
0
mirror of synced 2025-12-09 07:08:17 +08:00

Add: Info tests, api doc

This commit is contained in:
surunzi
2016-09-10 12:09:32 +08:00
parent b556df0e4a
commit 54902ae97b
4 changed files with 92 additions and 4 deletions

View File

@@ -74,6 +74,40 @@ console.html('<span style="color:red">Red</span>');
## Info
Display special information, could be used for displaying user info to track
user logs.
By default, page url and browser user agent is shown.
### clear
Clear infos.
### add
Add infos.
|Name |Type |Desc |
|-------|------|------------|
|name |string|Info name |
|content|string|Info content|
```javascript
info.add('title', 'content');
```
### remove
Remove specified info.
|Name|Type |Desc |
|----|------|---------|
|name|string|Info name|
```javascript
info.remove('title');
```
## Snippets
Allow you to register small function that can be triggered multiple times.

View File

@@ -28,6 +28,27 @@ export default class Info extends Tool
return this;
}
remove(name)
{
let msgs = this._msgs;
for (let i = 0, len = msgs.length; i < len; i++)
{
if (msgs[i].name === name) msgs.splice(i, 1);
}
this._render();
return this;
}
clear()
{
this._msgs = [];
this._render();
return this;
}
_addDefInfo()
{
util.each(defInfo, info => this.add(info.name, info.val));

View File

@@ -6,9 +6,5 @@ export default [
{
name: 'User Agent',
val: navigator.userAgent
},
{
name: 'Help',
val: 'Use eruda.get("info").add("name", "value") to add your own custom info.'
}
];

View File

@@ -0,0 +1,37 @@
var tool = eruda.get('info'),
$tool = $('.eruda-info');
describe('default', function ()
{
it('location', function ()
{
expect($tool.find('.eruda-content').eq(0)).toContainText(location.href);
});
it('user agent', function ()
{
expect($tool.find('.eruda-content').eq(1)).toContainText(navigator.userAgent);
});
});
describe('basic', function ()
{
it('clear', function ()
{
tool.clear();
expect($tool.find('li')).toHaveLength(0);
});
it('add', function ()
{
tool.add('test', 'eruda');
expect($tool.find('.eruda-title')).toContainText('test');
expect($tool.find('.eruda-content')).toContainText('eruda');
});
it('remove', function ()
{
tool.remove('test');
expect($tool.find('li')).toHaveLength(0);
});
});