Add: Info tests, api doc
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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.'
|
||||
}
|
||||
];
|
||||
37
test/info.js
37
test/info.js
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user