elstat/priv/frontend/src/components/__tests__/Service.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-07-22 19:26:14 +00:00
import React from 'react'
import { shallow } from 'enzyme'
import Service, { getServiceState } from '../Service'
2018-08-08 23:43:53 +00:00
const graph = [[1000, 50], [2000, 30], [3000, 60]]
2018-07-22 19:26:14 +00:00
const props = {
name: 'sample service',
description: 'a cool service',
latency: 50.5,
2018-08-09 00:06:35 +00:00
uptime: 99.9994,
2018-07-22 19:26:14 +00:00
}
describe('<Service/>', () => {
it('renders without crashing', () => {
2018-08-08 23:43:53 +00:00
shallow(<Service graph={null} status {...props} />)
2018-07-22 19:26:14 +00:00
})
it('omits information', () => {
2018-08-08 23:43:53 +00:00
const comp = shallow(
<Service graph={null} status {...props} latency={null} />
)
2018-07-22 19:26:14 +00:00
expect(comp.find('h2.title').text()).toEqual('sample service ')
})
it('renders proper information', () => {
2018-08-08 23:43:53 +00:00
const comp = shallow(<Service graph={graph} status {...props} />)
2018-07-22 19:26:14 +00:00
expect(comp.prop('className')).toEqual('service service-alive')
2018-08-09 00:06:35 +00:00
expect(comp.find('h2.title').text()).toEqual(
'sample service 51ms (99.9994%)'
)
2018-08-08 23:43:53 +00:00
expect(
comp.contains(<p className="description">a cool service</p>)
).toEqual(true)
2018-08-09 00:06:35 +00:00
expect(
comp.contains(<span className="information">51ms (99.9994%)</span>)
).toEqual(true)
2018-07-22 19:26:14 +00:00
})
})
describe('getServiceState', () => {
it('returns alive', () => {
expect(getServiceState(true, 10, 5000)).toEqual('alive')
})
it('returns slow', () => {
expect(getServiceState(true, 8000, 5000)).toEqual('slow')
})
it('returns dead', () => {
expect(getServiceState(false, 0, 5000)).toEqual('dead')
})
})