2017-03-30 22:29:43 +00:00
|
|
|
import reducer from 'src/data_explorer/reducers/queryConfigs'
|
|
|
|
import defaultQueryConfig from 'src/utils/defaultQueryConfig'
|
2016-09-15 21:53:29 +00:00
|
|
|
import {
|
2017-10-12 17:48:36 +00:00
|
|
|
fill,
|
2016-09-15 21:53:29 +00:00
|
|
|
chooseTag,
|
|
|
|
groupByTag,
|
|
|
|
groupByTime,
|
2017-10-12 17:48:36 +00:00
|
|
|
toggleField,
|
|
|
|
removeFuncs,
|
2016-09-15 21:53:29 +00:00
|
|
|
updateRawQuery,
|
2017-04-07 19:51:18 +00:00
|
|
|
editQueryStatus,
|
2017-10-12 17:48:36 +00:00
|
|
|
chooseNamespace,
|
|
|
|
chooseMeasurement,
|
|
|
|
applyFuncsToField,
|
2017-10-13 23:56:18 +00:00
|
|
|
addInitialField,
|
2017-10-12 17:48:36 +00:00
|
|
|
updateQueryConfig,
|
|
|
|
toggleTagAcceptance,
|
2017-04-04 21:46:55 +00:00
|
|
|
} from 'src/data_explorer/actions/view'
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-09-07 19:47:25 +00:00
|
|
|
import {LINEAR, NULL_STRING} from 'shared/constants/queryFillOptions'
|
2017-09-07 19:43:03 +00:00
|
|
|
|
2017-02-06 19:41:42 +00:00
|
|
|
const fakeAddQueryAction = (panelID, queryID) => {
|
2016-09-15 21:53:29 +00:00
|
|
|
return {
|
2017-07-25 04:34:29 +00:00
|
|
|
type: 'DE_ADD_QUERY',
|
2017-02-06 19:41:42 +00:00
|
|
|
payload: {panelID, queryID},
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
function buildInitialState(queryId, params) {
|
2017-09-06 15:27:16 +00:00
|
|
|
return Object.assign({}, defaultQueryConfig({id: queryId}), params)
|
2016-09-15 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('Chronograf.Reducers.DataExplorer.queryConfigs', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
const queryId = 123
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
it('can add a query', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
const state = reducer({}, fakeAddQueryAction('blah', queryId))
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const actual = state[queryId]
|
2017-09-06 15:27:16 +00:00
|
|
|
const expected = defaultQueryConfig({id: queryId})
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(actual).to.deep.equal(expected)
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
describe('choosing db, rp, and measurement', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
let state
|
2016-09-15 21:53:29 +00:00
|
|
|
beforeEach(() => {
|
2017-03-30 22:29:43 +00:00
|
|
|
state = reducer({}, fakeAddQueryAction('any', queryId))
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
it('sets the db and rp', () => {
|
2017-05-30 20:38:50 +00:00
|
|
|
const newState = reducer(
|
|
|
|
state,
|
|
|
|
chooseNamespace(queryId, {
|
|
|
|
database: 'telegraf',
|
|
|
|
retentionPolicy: 'monitor',
|
|
|
|
})
|
|
|
|
)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(newState[queryId].database).to.equal('telegraf')
|
|
|
|
expect(newState[queryId].retentionPolicy).to.equal('monitor')
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
it('sets the measurement', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
const newState = reducer(state, chooseMeasurement(queryId, 'mem'))
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(newState[queryId].measurement).to.equal('mem')
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-11 19:13:25 +00:00
|
|
|
describe('a query has measurements and fields', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
let state
|
2016-09-15 21:53:29 +00:00
|
|
|
beforeEach(() => {
|
2017-03-30 22:29:43 +00:00
|
|
|
const one = reducer({}, fakeAddQueryAction('any', queryId))
|
2017-05-30 20:38:50 +00:00
|
|
|
const two = reducer(
|
|
|
|
one,
|
|
|
|
chooseNamespace(queryId, {
|
|
|
|
database: '_internal',
|
|
|
|
retentionPolicy: 'daily',
|
|
|
|
})
|
|
|
|
)
|
2017-03-30 22:29:43 +00:00
|
|
|
const three = reducer(two, chooseMeasurement(queryId, 'disk'))
|
2017-10-10 23:46:56 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
state = reducer(
|
|
|
|
three,
|
2017-10-13 23:56:18 +00:00
|
|
|
addInitialField(queryId, {
|
2017-10-17 19:44:16 +00:00
|
|
|
value: 'a great field',
|
2017-10-10 21:09:06 +00:00
|
|
|
type: 'field',
|
|
|
|
})
|
2017-05-30 20:38:50 +00:00
|
|
|
)
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-12 17:48:36 +00:00
|
|
|
describe('choosing a new namespace', () => {
|
2017-05-30 20:38:50 +00:00
|
|
|
it('clears out the old measurement and fields', () => {
|
|
|
|
// what about tags?
|
2017-10-11 22:10:20 +00:00
|
|
|
expect(state[queryId].measurement).to.equal('disk')
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(state[queryId].fields.length).to.equal(1)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
const newState = reducer(
|
|
|
|
state,
|
|
|
|
chooseNamespace(queryId, {
|
|
|
|
database: 'newdb',
|
|
|
|
retentionPolicy: 'newrp',
|
|
|
|
})
|
|
|
|
)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-11 22:10:20 +00:00
|
|
|
expect(newState[queryId].measurement).to.be.null
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(newState[queryId].fields.length).to.equal(0)
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
describe('choosing a new measurement', () => {
|
2017-05-30 20:38:50 +00:00
|
|
|
it('leaves the namespace and clears out the old fields', () => {
|
|
|
|
// what about tags?
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(state[queryId].fields.length).to.equal(1)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
const newState = reducer(
|
|
|
|
state,
|
|
|
|
chooseMeasurement(queryId, 'newmeasurement')
|
|
|
|
)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(state[queryId].database).to.equal(newState[queryId].database)
|
2017-05-30 20:38:50 +00:00
|
|
|
expect(state[queryId].retentionPolicy).to.equal(
|
|
|
|
newState[queryId].retentionPolicy
|
|
|
|
)
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(newState[queryId].fields.length).to.equal(0)
|
|
|
|
})
|
|
|
|
})
|
2016-11-02 18:50:01 +00:00
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('DE_TOGGLE_FIELD', () => {
|
2017-05-30 20:36:47 +00:00
|
|
|
it('can toggle multiple fields', () => {
|
|
|
|
expect(state[queryId].fields.length).to.equal(1)
|
|
|
|
|
|
|
|
const newState = reducer(
|
|
|
|
state,
|
2017-10-10 23:46:56 +00:00
|
|
|
toggleField(queryId, {
|
2017-10-17 19:44:16 +00:00
|
|
|
value: 'f2',
|
2017-10-10 23:46:56 +00:00
|
|
|
type: 'field',
|
|
|
|
})
|
2017-05-30 20:36:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(newState[queryId].fields.length).to.equal(2)
|
2017-10-10 23:46:56 +00:00
|
|
|
expect(newState[queryId].fields[1].alias).to.deep.equal('mean_f2')
|
|
|
|
expect(newState[queryId].fields[1].args).to.deep.equal([
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'f2', type: 'field'},
|
2017-10-10 23:46:56 +00:00
|
|
|
])
|
2017-10-17 19:44:16 +00:00
|
|
|
expect(newState[queryId].fields[1].value).to.deep.equal('mean')
|
2017-05-30 20:36:47 +00:00
|
|
|
})
|
|
|
|
|
2017-10-10 23:46:56 +00:00
|
|
|
it('applies a func to newly selected fields', () => {
|
2017-06-14 17:12:36 +00:00
|
|
|
expect(state[queryId].fields.length).to.equal(1)
|
2017-10-10 23:46:56 +00:00
|
|
|
expect(state[queryId].fields[0].type).to.equal('func')
|
2017-10-17 19:44:16 +00:00
|
|
|
expect(state[queryId].fields[0].value).to.equal('mean')
|
2017-06-14 17:12:36 +00:00
|
|
|
|
|
|
|
const newState = reducer(
|
2017-10-10 23:46:56 +00:00
|
|
|
state,
|
2017-10-10 21:09:06 +00:00
|
|
|
toggleField(queryId, {
|
2017-10-17 19:44:16 +00:00
|
|
|
value: 'f2',
|
2017-10-10 21:09:06 +00:00
|
|
|
type: 'field',
|
|
|
|
})
|
2017-06-14 17:12:36 +00:00
|
|
|
)
|
|
|
|
|
2017-10-17 19:44:16 +00:00
|
|
|
expect(newState[queryId].fields[1].value).to.equal('mean')
|
2017-10-10 23:46:56 +00:00
|
|
|
expect(newState[queryId].fields[1].alias).to.equal('mean_f2')
|
|
|
|
expect(newState[queryId].fields[1].args).to.deep.equal([
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'f2', type: 'field'},
|
2017-10-10 23:46:56 +00:00
|
|
|
])
|
2017-10-10 21:09:06 +00:00
|
|
|
expect(newState[queryId].fields[1].type).to.equal('func')
|
2017-06-14 17:12:36 +00:00
|
|
|
})
|
2017-08-30 21:09:24 +00:00
|
|
|
|
|
|
|
it('adds the field property to query config if not found', () => {
|
|
|
|
delete state[queryId].fields
|
|
|
|
expect(state[queryId].fields).to.equal(undefined)
|
|
|
|
|
|
|
|
const newState = reducer(
|
|
|
|
state,
|
2017-10-17 19:44:16 +00:00
|
|
|
toggleField(queryId, {value: 'fk1', type: 'field'})
|
2017-08-30 21:09:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(newState[queryId].fields.length).to.equal(1)
|
|
|
|
})
|
2017-05-30 20:36:47 +00:00
|
|
|
})
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-11 19:13:25 +00:00
|
|
|
describe('DE_APPLY_FUNCS_TO_FIELD', () => {
|
2017-10-10 23:46:56 +00:00
|
|
|
it('applies new functions to a field', () => {
|
2017-10-17 19:44:16 +00:00
|
|
|
const f1 = {value: 'f1', type: 'field'}
|
|
|
|
const f2 = {value: 'f2', type: 'field'}
|
|
|
|
const f3 = {value: 'f3', type: 'field'}
|
|
|
|
const f4 = {value: 'f4', type: 'field'}
|
2017-10-10 23:46:56 +00:00
|
|
|
|
2016-09-15 21:53:29 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: {
|
|
|
|
id: 123,
|
|
|
|
database: 'db1',
|
|
|
|
measurement: 'm1',
|
|
|
|
fields: [
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'fn1', type: 'func', args: [f1], alias: `fn1_${f1.value}`},
|
|
|
|
{value: 'fn1', type: 'func', args: [f2], alias: `fn1_${f2.value}`},
|
|
|
|
{value: 'fn2', type: 'func', args: [f1], alias: `fn2_${f1.value}`},
|
2016-09-15 21:53:29 +00:00
|
|
|
],
|
2017-03-30 22:29:43 +00:00
|
|
|
},
|
|
|
|
}
|
2017-10-10 23:46:56 +00:00
|
|
|
|
2016-09-15 21:53:29 +00:00
|
|
|
const action = applyFuncsToField(queryId, {
|
2017-10-17 19:44:16 +00:00
|
|
|
field: {value: 'f1', type: 'field'},
|
2017-10-10 23:46:56 +00:00
|
|
|
funcs: [
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'fn3', type: 'func', args: []},
|
|
|
|
{value: 'fn4', type: 'func', args: []},
|
2017-10-10 23:46:56 +00:00
|
|
|
],
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-10 23:46:56 +00:00
|
|
|
expect(nextState[queryId].fields).to.deep.equal([
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'fn3', type: 'func', args: [f1], alias: `fn3_${f1.value}`},
|
|
|
|
{value: 'fn4', type: 'func', args: [f1], alias: `fn4_${f1.value}`},
|
|
|
|
{value: 'fn1', type: 'func', args: [f2], alias: `fn1_${f2.value}`},
|
2017-03-30 22:29:43 +00:00
|
|
|
])
|
|
|
|
})
|
2017-10-12 17:48:36 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-12 17:48:36 +00:00
|
|
|
describe('DE_REMOVE_FUNCS', () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
it('removes all functions and group by time when one field has no funcs applied', () => {
|
2017-10-17 19:44:16 +00:00
|
|
|
const f1 = {value: 'f1', type: 'field'}
|
|
|
|
const f2 = {value: 'f2', type: 'field'}
|
2017-10-12 17:48:36 +00:00
|
|
|
const fields = [
|
2017-10-17 19:44:16 +00:00
|
|
|
{value: 'fn1', type: 'func', args: [f1], alias: `fn1_${f1.value}`},
|
|
|
|
{value: 'fn1', type: 'func', args: [f2], alias: `fn1_${f2.value}`},
|
2017-10-12 17:48:36 +00:00
|
|
|
]
|
|
|
|
const groupBy = {time: '1m', tags: []}
|
|
|
|
|
2016-09-15 21:53:29 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: {
|
|
|
|
id: 123,
|
|
|
|
database: 'db1',
|
|
|
|
measurement: 'm1',
|
2017-10-12 17:48:36 +00:00
|
|
|
fields,
|
|
|
|
groupBy,
|
2017-03-30 22:29:43 +00:00
|
|
|
},
|
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-12 17:48:36 +00:00
|
|
|
const action = removeFuncs(queryId, fields, groupBy)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2017-10-11 19:13:25 +00:00
|
|
|
const actual = nextState[queryId].fields
|
|
|
|
const expected = [f1, f2]
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-10-11 19:13:25 +00:00
|
|
|
expect(actual).to.eql(expected)
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(nextState[queryId].groupBy.time).to.equal(null)
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('DE_CHOOSE_TAG', () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
it('adds a tag key/value to the query', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId, {
|
|
|
|
tags: {
|
|
|
|
k1: ['v0'],
|
|
|
|
k2: ['foo'],
|
|
|
|
},
|
|
|
|
}),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
const action = chooseTag(queryId, {
|
|
|
|
key: 'k1',
|
|
|
|
value: 'v1',
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
expect(nextState[queryId].tags).to.eql({
|
|
|
|
k1: ['v0', 'v1'],
|
|
|
|
k2: ['foo'],
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
it("creates a new entry if it's the first key", () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId, {
|
|
|
|
tags: {},
|
|
|
|
}),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
const action = chooseTag(queryId, {
|
|
|
|
key: 'k1',
|
|
|
|
value: 'v1',
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
expect(nextState[queryId].tags).to.eql({
|
|
|
|
k1: ['v1'],
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
it('removes a value that is already in the list', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId, {
|
|
|
|
tags: {
|
|
|
|
k1: ['v1'],
|
|
|
|
},
|
|
|
|
}),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
const action = chooseTag(queryId, {
|
|
|
|
key: 'k1',
|
|
|
|
value: 'v1',
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
// TODO: this should probably remove the `k1` property entirely from the tags object
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(nextState[queryId].tags).to.eql({})
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('DE_GROUP_BY_TAG', () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
it('adds a tag key/value to the query', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: {
|
|
|
|
id: 123,
|
|
|
|
database: 'db1',
|
|
|
|
measurement: 'm1',
|
|
|
|
fields: [],
|
|
|
|
tags: {},
|
|
|
|
groupBy: {tags: [], time: null},
|
2017-03-30 22:29:43 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
const action = groupByTag(queryId, 'k1')
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
expect(nextState[queryId].groupBy).to.eql({
|
|
|
|
time: null,
|
|
|
|
tags: ['k1'],
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
it('removes a tag if the given tag key is already in the GROUP BY list', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: {
|
|
|
|
id: 123,
|
|
|
|
database: 'db1',
|
|
|
|
measurement: 'm1',
|
|
|
|
fields: [],
|
|
|
|
tags: {},
|
|
|
|
groupBy: {tags: ['k1'], time: null},
|
2017-03-30 22:29:43 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
const action = groupByTag(queryId, 'k1')
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
|
|
|
expect(nextState[queryId].groupBy).to.eql({
|
|
|
|
time: null,
|
|
|
|
tags: [],
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('DE_TOGGLE_TAG_ACCEPTANCE', () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
it('it toggles areTagsAccepted', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
|
|
|
const action = toggleTagAcceptance(queryId)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
expect(nextState[queryId].areTagsAccepted).to.equal(
|
|
|
|
!initialState[queryId].areTagsAccepted
|
|
|
|
)
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-07-25 04:34:29 +00:00
|
|
|
describe('DE_GROUP_BY_TIME', () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
it('applys the appropriate group by time', () => {
|
2017-03-30 22:29:43 +00:00
|
|
|
const time = '100y'
|
2016-09-15 21:53:29 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const action = groupByTime(queryId, time)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(nextState[queryId].groupBy.time).to.equal(time)
|
|
|
|
})
|
|
|
|
})
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-04-10 18:01:36 +00:00
|
|
|
it('updates entire config', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
2017-09-06 15:27:16 +00:00
|
|
|
const expected = defaultQueryConfig({id: queryId}, {rawText: 'hello'})
|
2017-04-10 18:01:36 +00:00
|
|
|
const action = updateQueryConfig(expected)
|
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
|
|
|
expect(nextState[queryId]).to.deep.equal(expected)
|
|
|
|
})
|
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
it("updates a query's raw text", () => {
|
2016-09-15 21:53:29 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
2017-03-30 22:29:43 +00:00
|
|
|
}
|
|
|
|
const text = 'foo'
|
|
|
|
const action = updateRawQuery(queryId, text)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
const nextState = reducer(initialState, action)
|
2016-09-15 21:53:29 +00:00
|
|
|
|
2017-03-30 22:29:43 +00:00
|
|
|
expect(nextState[queryId].rawText).to.equal('foo')
|
|
|
|
})
|
2017-03-29 21:36:06 +00:00
|
|
|
|
2017-05-30 20:38:50 +00:00
|
|
|
it("updates a query's raw status", () => {
|
2017-03-29 21:36:06 +00:00
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
|
|
|
const status = 'your query was sweet'
|
2017-04-07 19:51:18 +00:00
|
|
|
const action = editQueryStatus(queryId, status)
|
2017-03-29 21:36:06 +00:00
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
2017-04-07 19:51:18 +00:00
|
|
|
expect(nextState[queryId].status).to.equal(status)
|
2017-03-29 21:36:06 +00:00
|
|
|
})
|
2017-09-07 19:43:03 +00:00
|
|
|
|
|
|
|
describe('DE_FILL', () => {
|
|
|
|
it('applies an explicit fill when group by time is used', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
|
|
|
const time = '10s'
|
|
|
|
const action = groupByTime(queryId, time)
|
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
|
|
|
expect(nextState[queryId].fill).to.equal(NULL_STRING)
|
|
|
|
})
|
2017-09-07 19:47:25 +00:00
|
|
|
|
|
|
|
it('updates fill to non-null-string non-number string value', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
|
|
|
const action = fill(queryId, LINEAR)
|
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
|
|
|
expect(nextState[queryId].fill).to.equal(LINEAR)
|
|
|
|
})
|
2017-09-07 19:50:50 +00:00
|
|
|
|
|
|
|
it('updates fill to string integer value', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
|
|
|
const INT_STRING = '1337'
|
|
|
|
const action = fill(queryId, INT_STRING)
|
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
|
|
|
expect(nextState[queryId].fill).to.equal(INT_STRING)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('updates fill to string float value', () => {
|
|
|
|
const initialState = {
|
|
|
|
[queryId]: buildInitialState(queryId),
|
|
|
|
}
|
|
|
|
const FLOAT_STRING = '1.337'
|
|
|
|
const action = fill(queryId, FLOAT_STRING)
|
|
|
|
|
|
|
|
const nextState = reducer(initialState, action)
|
|
|
|
|
|
|
|
expect(nextState[queryId].fill).to.equal(FLOAT_STRING)
|
|
|
|
})
|
2017-09-07 19:43:03 +00:00
|
|
|
})
|
2017-03-30 22:29:43 +00:00
|
|
|
})
|