Fix FuncSelectorTest

Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com>
Co-authored-by: Brandon Farmer <bthesorceror@gmail.com>
pull/10616/head
Brandon Farmer 2018-03-28 15:56:43 -07:00
parent 3ef6af82f6
commit debfff5050
6 changed files with 57 additions and 18 deletions

View File

@ -1,3 +1,4 @@
jest.mock('src/utils/ajax', () => require('mocks/utils/ajax'))
export const getSuggestions = jest.fn(() => Promise.resolve([]))
export const getAST = jest.fn(() => Promise.resolve({}))

View File

@ -1,5 +1,5 @@
// Texas Ranger
import {get} from 'lodash'
import _ from 'lodash'
interface Expression {
expression: object
@ -32,6 +32,10 @@ export default class Walker {
}
private walk = currentNode => {
if (_.isEmpty(currentNode)) {
return []
}
let name
let args
if (currentNode.call) {
@ -57,11 +61,15 @@ export default class Walker {
private getProperties = props => {
return props.map(prop => ({
key: prop.key.name,
value: get(prop, 'value.value', get(prop, 'value.location.source', '')),
value: _.get(
prop,
'value.value',
_.get(prop, 'value.location.source', '')
),
}))
}
private get baseExpression() {
return this.ast.body[0].expression
return _.get(this.ast, 'body.0.expression', {})
}
}

View File

@ -24,7 +24,6 @@ export class FuncSelector extends PureComponent<Props, State> {
}
public render() {
const {onAddNode} = this.props
const {isOpen, inputText} = this.state
return (

View File

@ -12,7 +12,7 @@ describe('IFQL.AST.Walker', () => {
name: 'from',
arguments: [
{
name: 'db',
key: 'db',
value: 'telegraf',
},
],
@ -27,20 +27,20 @@ describe('IFQL.AST.Walker', () => {
expect(walker.functions).toEqual([
{
name: 'from',
arguments: [{name: 'db', value: 'telegraf'}],
arguments: [{key: 'db', value: 'telegraf'}],
},
{
name: 'filter',
arguments: [
{
name: 'fn',
key: 'fn',
value: '(r) => r["_measurement"] == "cpu"',
},
],
},
{
name: 'range',
arguments: [{name: 'start', value: '-1m'}],
arguments: [{key: 'start', value: '-1m'}],
},
])
})

View File

@ -2,6 +2,8 @@ import React from 'react'
import {shallow} from 'enzyme'
import {FuncSelector} from 'src/ifql/components/FuncSelector'
import DropdownInput from 'src/shared/components/DropdownInput'
import FuncListItem from 'src/ifql/components/FuncListItem'
import FuncList from 'src/ifql/components/FuncList'
const setup = (override = {}) => {
const props = {
@ -44,11 +46,17 @@ describe('IFQL.Components.FuncsButton', () => {
const dropdownButton = wrapper.find('button')
dropdownButton.simulate('click')
const list = wrapper.find('.func')
const list = wrapper
.find(FuncList)
.dive()
.find(FuncListItem)
const first = list.first().dive()
const last = list.last().dive()
expect(list.length).toBe(2)
expect(list.first().text()).toBe('f1')
expect(list.last().text()).toBe('f2')
expect(first.text()).toBe('f1')
expect(last.text()).toBe('f2')
})
})
@ -59,13 +67,21 @@ describe('IFQL.Components.FuncsButton', () => {
const dropdownButton = wrapper.find('button')
dropdownButton.simulate('click')
let list = wrapper.find('.func')
let list = wrapper
.find(FuncList)
.dive()
.find(FuncListItem)
const first = list.first().dive()
const last = list.last().dive()
expect(list.length).toBe(2)
expect(list.first().text()).toBe('f1')
expect(list.last().text()).toBe('f2')
expect(first.text()).toBe('f1')
expect(last.text()).toBe('f2')
const input = wrapper
.find(FuncList)
.dive()
.find(DropdownInput)
.dive()
.find('input')
@ -73,10 +89,15 @@ describe('IFQL.Components.FuncsButton', () => {
input.simulate('change', {target: {value: '2'}})
wrapper.update()
list = wrapper.find('.func')
list = wrapper
.find(FuncList)
.dive()
.find(FuncListItem)
const func = list.first().dive()
expect(list.length).toBe(1)
expect(list.first().text()).toBe('f2')
expect(func.text()).toBe('f2')
})
})
@ -86,11 +107,17 @@ describe('IFQL.Components.FuncsButton', () => {
const dropdownButton = wrapper.find('button')
dropdownButton.simulate('click')
let list = wrapper.find('.func')
let list = wrapper
.find(FuncList)
.dive()
.find(FuncListItem)
expect(list.exists()).toBe(true)
const input = wrapper
.find(FuncList)
.dive()
.find(DropdownInput)
.dive()
.find('input')
@ -98,7 +125,10 @@ describe('IFQL.Components.FuncsButton', () => {
input.simulate('keyDown', {key: 'Escape'})
wrapper.update()
list = wrapper.find('.func')
list = wrapper
.find(FuncList)
.dive()
.find(FuncListItem)
expect(list.exists()).toBe(false)
})

View File

@ -6,6 +6,7 @@ const setup = () => {
const props = {
funcs: [],
ast: {},
nodes: [],
}
const wrapper = shallow(<TimeMachine {...props} />)