Change tests and reducers to use value instead of name

pull/10616/head
Andrew Watkins 2017-10-17 13:19:08 -07:00
parent 73c93d2957
commit 77b3487bd2
2 changed files with 19 additions and 19 deletions

View File

@ -77,7 +77,7 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
const three = reducer(two, chooseMeasurement(queryId, 'disk'))
state = reducer(
three,
toggleField(queryId, {name: 'a great field', funcs: []})
toggleField(queryId, {value: 'a great field', funcs: []})
)
})
@ -124,11 +124,11 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
const newState = reducer(
state,
toggleField(queryId, {name: 'a different field', type: 'field'})
toggleField(queryId, {value: 'a different field', type: 'field'})
)
expect(newState[queryId].fields.length).to.equal(1)
expect(newState[queryId].fields[0].name).to.equal('a different field')
expect(newState[queryId].fields[0].value).to.equal('a different field')
})
})
@ -138,11 +138,11 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
const newState = reducer(
state,
toggleField(queryId, {name: 'a different field', type: 'field'})
toggleField(queryId, {value: 'a different field', type: 'field'})
)
expect(newState[queryId].fields.length).to.equal(1)
expect(newState[queryId].fields[0].name).to.equal('a different field')
expect(newState[queryId].fields[0].value).to.equal('a different field')
})
it('applies no funcs to newly selected fields', () => {
@ -150,7 +150,7 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
const newState = reducer(
state,
toggleField(queryId, {name: 'a different field', type: 'field'})
toggleField(queryId, {value: 'a different field', type: 'field'})
)
expect(newState[queryId].fields[0].type).to.equal('field')
@ -160,7 +160,7 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
describe('KAPA_APPLY_FUNCS_TO_FIELD', () => {
it('applies functions to a field without any existing functions', () => {
const f1 = {name: 'f1', type: 'field'}
const f1 = {value: 'f1', type: 'field'}
const initialState = {
[queryId]: {
id: 123,
@ -175,15 +175,15 @@ describe('Chronograf.Reducers.Kapacitor.queryConfigs', () => {
}
const action = applyFuncsToField(queryId, {
field: {name: 'f1', type: 'field'},
funcs: [{name: 'fn3', type: 'func'}, {name: 'fn4', type: 'func'}],
field: {value: 'f1', type: 'field'},
funcs: [{value: 'fn3', type: 'func'}, {value: 'fn4', type: 'func'}],
})
const nextState = reducer(initialState, action)
const actual = nextState[queryId].fields
const expected = [
{name: 'fn3', type: 'func', args: [f1], alias: `fn3_${f1.name}`},
{name: 'fn4', type: 'func', args: [f1], alias: `fn4_${f1.name}`},
{value: 'fn3', type: 'func', args: [f1], alias: `fn3_${f1.value}`},
{value: 'fn4', type: 'func', args: [f1], alias: `fn4_${f1.value}`},
]
expect(actual).to.eql(expected)

View File

@ -21,8 +21,8 @@ export const functions = fields => ofType(fields, 'func')
// numFunctions searches queryConfig fields for functions
export const numFunctions = fields => _.size(functions(fields))
// functionNames returns the names of all top-level functions
export const functionNames = fields => functions(fields).map(f => f.name)
// functionNames returns the value of all top-level functions
export const functionNames = fields => functions(fields).map(f => f.value)
// getFields returns all of the top-level fields of type field
export const getFields = fields => ofType(fields, 'field')
@ -30,13 +30,13 @@ export const getFields = fields => ofType(fields, 'field')
export const getFieldsDeep = fields =>
_.uniqBy(
fieldWalk(fields, f => (_.get(f, 'type') === 'field' ? f : null)),
'name'
'value'
)
export const fieldNamesDeep = fields =>
getFieldsDeep(fields).map(f => _.get(f, 'name'))
getFieldsDeep(fields).map(f => _.get(f, 'value'))
// firstFieldName returns the name of the first of type field
// firstFieldName returns the value of the first of type field
export const firstFieldName = fields => _.head(fieldNamesDeep(fields))
export const hasField = (fieldName, fields) =>
@ -44,7 +44,7 @@ export const hasField = (fieldName, fields) =>
// getAllFields and funcs with fieldName
export const getFieldsWithName = (fieldName, fields) =>
getFieldsDeep(fields).filter(f => f.name === fieldName)
getFieldsDeep(fields).filter(f => f.value === fieldName)
// everyOfType returns true if all top-level field types are type
export const everyOfType = (fields, type) =>
@ -58,14 +58,14 @@ export const everyFunction = fields => everyOfType(fields, 'func')
export const getFuncsByFieldName = (fieldName, fields) =>
functions(fields).filter(f =>
_.get(f, 'args', []).some(a => a.name === fieldName)
_.get(f, 'args', []).some(a => a.value === fieldName)
)
// removeField will remove the field or function from the field list with the
// given fieldName. Preconditions: only type field OR only type func
export const removeField = (fieldName, fields) => {
if (everyField(fields)) {
return fields.filter(f => f.name !== fieldName)
return fields.filter(f => f.value !== fieldName)
}
return fields.reduce((acc, f) => {