WIP test hostsPage async proxy request calls

Co-authored-by: Jared Scheib <jared.scheib@gmail.com>
pull/10616/head
Iris Scholten 2018-04-16 18:29:16 -07:00
parent 21037ab55c
commit 035d61100c
7 changed files with 218 additions and 4 deletions

View File

@ -0,0 +1,7 @@
import {layout, hosts} from 'test/resources'
export const getCpuAndLoadForHosts = () => Promise.resolve(hosts)
export const getAllHosts = () => Promise.resolve()
export const getLayouts = () => Promise.resolve({data: {layouts: [layout]}})
export const getAppsForHosts = () => Promise.resolve(hosts)
export const getMeasurementsForHost = () => Promise.resolve()

View File

@ -0,0 +1 @@
export const getEnv = () => Promise.resolve({telegrafSystemInterval: ''})

View File

@ -178,7 +178,7 @@ export function getMeasurementsForHost(source, host) {
return []
}
const series = data.results[0].series[0]
const series = _.get(data, ['results', '0', 'series', '0'])
return series.values.map(measurement => {
return measurement[0]
})

View File

@ -20,7 +20,7 @@ import {
notifyUnableToGetApps,
} from 'shared/copy/notifications'
class HostsPage extends Component {
export class HostsPage extends Component {
constructor(props) {
super(props)
@ -73,8 +73,9 @@ class HostsPage extends Component {
const {notify, autoRefresh} = this.props
this.setState({hostsLoading: true}) // Only print this once
const {data} = await getLayouts()
this.layouts = data.layouts
const results = await getLayouts()
const data = _.get(results, 'data')
this.layouts = data && data.layouts
if (!this.layouts) {
const layoutError = notifyUnableToGetApps().message
notify(notifyUnableToGetApps())

View File

@ -0,0 +1,55 @@
import {generateTempVarsForHosts} from 'src/hosts/constants'
describe('hosts.constants.index', () => {
describe('generateTempVarsForHosts', () => {
it('should return template variables', () => {
const telegraf = 'bob'
const defaultRP = '1h10m'
const source = {telegraf, defaultRP}
const expected = [
{
tempVar: ':db:',
id: 'db',
type: 'constant',
values: [{value: telegraf, type: 'constant', selected: true}],
},
{
tempVar: ':rp:',
id: 'rp',
type: 'constant',
values: [{value: defaultRP, type: 'constant', selected: true}],
},
]
const actual = generateTempVarsForHosts(source)
expect(actual).toEqual(expected)
})
describe('if rp is an empty string', () => {
it('should return an empty rention policy variable', () => {
const telegraf = 'bob'
const defaultRP = ''
const source = {telegraf, defaultRP}
const expected = [
{
tempVar: ':db:',
id: 'db',
type: 'constant',
values: [{value: telegraf, type: 'constant', selected: true}],
},
{
tempVar: ':rp:',
id: 'rp',
type: 'constant',
values: [{value: '', type: 'constant', selected: true}],
},
]
const actual = generateTempVarsForHosts(source)
expect(actual).toEqual(expected)
})
})
})
})

View File

@ -0,0 +1,38 @@
import React from 'react'
import {shallow} from 'enzyme'
import {HostsPage} from 'src/hosts/containers/HostsPage'
jest.mock('src/hosts/apis', () => require('mocks/hosts/apis'))
jest.mock('src/shared/apis/env', () => require('mocks/shared/apis/env'))
// const getCpuAndLoadForHosts = jest.fn()
import {getCpuAndLoadForHosts} from 'src/hosts/apis'
const props = {
source: {
id: '',
name: '',
type: '',
links: {proxy: ''},
telegraf: '',
},
links: {environment: ''},
autoRefresh: 0,
manualRefresh: 0,
onChooseAutoRefresh: () => {},
onManualRefresh: () => {},
notify: () => {},
}
describe('hosts.containers.HostsPage', () => {
describe('ajax requests', () => {
it('fetches host data from proxy', async () => {
const wrapper = shallow(<HostsPage {...props} />)
const instance: HostsPage = wrapper.instance()
const spy = await jest.spyOn(instance, 'fetchHostsData')
expect(spy).toHaveBeenCalled()
// expect(getCpuAndLoadForHosts).toHaveBeenCalled()
})
})
})

View File

@ -451,3 +451,115 @@ export const authLinks = {
sources: '/chronograf/v1/sources',
users: '/chronograf/v1/organizations/default/users',
}
export const layout = {
id: '6dfb4d49-20dc-4157-9018-2b1b1cb75c2d',
app: 'apache',
measurement: 'apache',
autoflow: false,
cells: [
{
x: 0,
y: 0,
w: 4,
h: 4,
i: '0246e457-916b-43e3-be99-211c4cbc03e8',
name: 'Apache Bytes/Second',
queries: [
{
query:
'SELECT non_negative_derivative(max("BytesPerSec")) AS "bytes_per_sec" FROM ":db:".":rp:"."apache"',
groupbys: ['"server"'],
label: 'bytes/s',
},
],
axes: {
x: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y2: {
bounds: [],
label: '',
prefix: '',
suffix: '',
base: '',
scale: '',
},
},
type: '',
colors: [],
},
{
x: 4,
y: 0,
w: 4,
h: 4,
i: '37f2e4bb-9fa5-4891-a424-9df5ce7458bb',
name: 'Apache - Requests/Second',
queries: [
{
query:
'SELECT non_negative_derivative(max("ReqPerSec")) AS "req_per_sec" FROM ":db:".":rp:"."apache"',
groupbys: ['"server"'],
label: 'requests/s',
},
],
axes: {
x: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y2: {
bounds: [],
label: '',
prefix: '',
suffix: '',
base: '',
scale: '',
},
},
type: '',
colors: [],
},
{
x: 8,
y: 0,
w: 4,
h: 4,
i: 'ea9174b3-2b56-4e80-a37d-064507c6775a',
name: 'Apache - Total Accesses',
queries: [
{
query:
'SELECT non_negative_derivative(max("TotalAccesses")) AS "tot_access" FROM ":db:".":rp:"."apache"',
groupbys: ['"server"'],
label: 'accesses/s',
},
],
axes: {
x: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y: {bounds: [], label: '', prefix: '', suffix: '', base: '', scale: ''},
y2: {
bounds: [],
label: '',
prefix: '',
suffix: '',
base: '',
scale: '',
},
},
type: '',
colors: [],
},
],
link: {
href: '/chronograf/v1/layouts/6dfb4d49-20dc-4157-9018-2b1b1cb75c2d',
rel: 'self',
},
}
export const hosts = {
'MacBook-Pro.local': {
name: 'MacBook-Pro.local',
deltaUptime: -1,
cpu: 0,
load: 0,
},
}