mirror of https://github.com/grafana/grafana
parent
8aff969f70
commit
5b91bb9163
@ -0,0 +1,24 @@ |
||||
import React from 'react'; |
||||
import renderer from 'react-test-renderer'; |
||||
import { ServerStats } from './ServerStats'; |
||||
import { RootStore } from 'app/stores/RootStore'; |
||||
|
||||
describe('ServerStats', () => { |
||||
it('Should render table with stats', done => { |
||||
let backendSrvMock = { |
||||
get: jest.fn().mockReturnValue( |
||||
Promise.resolve({ |
||||
dashboards: 10, |
||||
}) |
||||
), |
||||
}; |
||||
|
||||
const store = RootStore.create({}, { backendSrv: backendSrvMock }); |
||||
const page = renderer.create(<ServerStats store={store} />); |
||||
|
||||
setTimeout(() => { |
||||
expect(page.toJSON()).toMatchSnapshot(); |
||||
done(); |
||||
}); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,99 @@ |
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`ServerStats Should render table with stats 1`] = ` |
||||
<div> |
||||
// |
||||
<div |
||||
className="page-container page-body" |
||||
> |
||||
<table |
||||
className="filter-table form-inline" |
||||
> |
||||
<thead> |
||||
<tr> |
||||
<th> |
||||
Name |
||||
</th> |
||||
<th> |
||||
Value |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr> |
||||
<td> |
||||
Total dashboards |
||||
</td> |
||||
<td> |
||||
10 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total users |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Active users (seen last 30 days) |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total orgs |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total playlists |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total snapshots |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total dashboard tags |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total starred dashboards |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td> |
||||
Total alerts |
||||
</td> |
||||
<td> |
||||
0 |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
`; |
||||
@ -1,26 +0,0 @@ |
||||
export class BundleLoader { |
||||
lazy: any; |
||||
|
||||
constructor(bundleName) { |
||||
var defer = null; |
||||
|
||||
this.lazy = [ |
||||
'$q', |
||||
'$route', |
||||
'$rootScope', |
||||
($q, $route, $rootScope) => { |
||||
if (defer) { |
||||
return defer.promise; |
||||
} |
||||
|
||||
defer = $q.defer(); |
||||
|
||||
System.import(bundleName).then(() => { |
||||
defer.resolve(); |
||||
}); |
||||
|
||||
return defer.promise; |
||||
}, |
||||
]; |
||||
} |
||||
} |
||||
@ -0,0 +1,74 @@ |
||||
import { types } from 'mobx-state-tree'; |
||||
import config from 'app/core/config'; |
||||
import _ from 'lodash'; |
||||
|
||||
export const NavItem = types.model('NavItem', { |
||||
id: types.identifier(types.string), |
||||
text: types.string, |
||||
url: types.optional(types.string, ''), |
||||
description: types.optional(types.string, ''), |
||||
icon: types.optional(types.string, ''), |
||||
img: types.optional(types.string, ''), |
||||
active: types.optional(types.boolean, false), |
||||
children: types.optional(types.array(types.late(() => NavItem)), []), |
||||
}); |
||||
|
||||
export const NavStore = types |
||||
.model('NavStore', { |
||||
main: types.maybe(NavItem), |
||||
node: types.maybe(NavItem), |
||||
breadcrumbs: types.optional(types.array(NavItem), []), |
||||
}) |
||||
.actions(self => ({ |
||||
load(...args) { |
||||
var children = config.bootData.navTree; |
||||
let main, node; |
||||
let breadcrumbs = []; |
||||
|
||||
for (let id of args) { |
||||
// if its a number then it's the index to use for main
|
||||
if (_.isNumber(id)) { |
||||
main = breadcrumbs[id]; |
||||
break; |
||||
} |
||||
|
||||
let current = _.find(children, { id: id }); |
||||
breadcrumbs.push(current); |
||||
main = node; |
||||
node = current; |
||||
children = node.children; |
||||
} |
||||
|
||||
if (main.children) { |
||||
for (let item of main.children) { |
||||
item.active = false; |
||||
|
||||
if (item.url === node.url) { |
||||
item.active = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
self.main = NavItem.create(main); |
||||
self.node = NavItem.create(node); |
||||
|
||||
for (let item of breadcrumbs) { |
||||
self.breadcrumbs.push(NavItem.create(item)); |
||||
} |
||||
|
||||
// self.main = NavItem.create({
|
||||
// id: 'test',
|
||||
// text: 'test',
|
||||
// url: '/test';
|
||||
// children: [
|
||||
// {
|
||||
// id: 'test',
|
||||
// text: 'text',
|
||||
// url: '/test',
|
||||
// active: true,
|
||||
// children: []
|
||||
// }
|
||||
// ]
|
||||
// });
|
||||
}, |
||||
})); |
||||
Loading…
Reference in new issue