pull/1560/head
Andrew Watkins 2017-05-30 13:38:50 -07:00
parent 3e074b45b7
commit 8acdd3a377
1 changed files with 42 additions and 21 deletions

View File

@ -43,10 +43,13 @@ describe('Chronograf.Reducers.queryConfig', () => {
}) })
it('sets the db and rp', () => { it('sets the db and rp', () => {
const newState = reducer(state, chooseNamespace(queryId, { const newState = reducer(
database: 'telegraf', state,
retentionPolicy: 'monitor', chooseNamespace(queryId, {
})) database: 'telegraf',
retentionPolicy: 'monitor',
})
)
expect(newState[queryId].database).to.equal('telegraf') expect(newState[queryId].database).to.equal('telegraf')
expect(newState[queryId].retentionPolicy).to.equal('monitor') expect(newState[queryId].retentionPolicy).to.equal('monitor')
@ -63,23 +66,33 @@ describe('Chronograf.Reducers.queryConfig', () => {
let state let state
beforeEach(() => { beforeEach(() => {
const one = reducer({}, fakeAddQueryAction('any', queryId)) const one = reducer({}, fakeAddQueryAction('any', queryId))
const two = reducer(one, chooseNamespace(queryId, { const two = reducer(
database: '_internal', one,
retentionPolicy: 'daily', chooseNamespace(queryId, {
})) database: '_internal',
retentionPolicy: 'daily',
})
)
const three = reducer(two, chooseMeasurement(queryId, 'disk')) const three = reducer(two, chooseMeasurement(queryId, 'disk'))
state = reducer(three, toggleField(queryId, {field: 'a great field', funcs: []})) state = reducer(
three,
toggleField(queryId, {field: 'a great field', funcs: []})
)
}) })
describe('choosing a new namespace', () => { describe('choosing a new namespace', () => {
it('clears out the old measurement and fields', () => { // what about tags? it('clears out the old measurement and fields', () => {
// what about tags?
expect(state[queryId].measurement).to.exist expect(state[queryId].measurement).to.exist
expect(state[queryId].fields.length).to.equal(1) expect(state[queryId].fields.length).to.equal(1)
const newState = reducer(state, chooseNamespace(queryId, { const newState = reducer(
database: 'newdb', state,
retentionPolicy: 'newrp', chooseNamespace(queryId, {
})) database: 'newdb',
retentionPolicy: 'newrp',
})
)
expect(newState[queryId].measurement).not.to.exist expect(newState[queryId].measurement).not.to.exist
expect(newState[queryId].fields.length).to.equal(0) expect(newState[queryId].fields.length).to.equal(0)
@ -87,13 +100,19 @@ describe('Chronograf.Reducers.queryConfig', () => {
}) })
describe('choosing a new measurement', () => { describe('choosing a new measurement', () => {
it('leaves the namespace and clears out the old fields', () => { // what about tags? it('leaves the namespace and clears out the old fields', () => {
// what about tags?
expect(state[queryId].fields.length).to.equal(1) expect(state[queryId].fields.length).to.equal(1)
const newState = reducer(state, chooseMeasurement(queryId, 'newmeasurement')) const newState = reducer(
state,
chooseMeasurement(queryId, 'newmeasurement')
)
expect(state[queryId].database).to.equal(newState[queryId].database) expect(state[queryId].database).to.equal(newState[queryId].database)
expect(state[queryId].retentionPolicy).to.equal(newState[queryId].retentionPolicy) expect(state[queryId].retentionPolicy).to.equal(
newState[queryId].retentionPolicy
)
expect(newState[queryId].fields.length).to.equal(0) expect(newState[queryId].fields.length).to.equal(0)
}) })
}) })
@ -230,7 +249,7 @@ describe('Chronograf.Reducers.queryConfig', () => {
}) })
}) })
it('creates a new entry if it\'s the first key', () => { it("creates a new entry if it's the first key", () => {
const initialState = { const initialState = {
[queryId]: buildInitialState(queryId, { [queryId]: buildInitialState(queryId, {
tags: {}, tags: {},
@ -321,7 +340,9 @@ describe('Chronograf.Reducers.queryConfig', () => {
const nextState = reducer(initialState, action) const nextState = reducer(initialState, action)
expect(nextState[queryId].areTagsAccepted).to.equal(!initialState[queryId].areTagsAccepted) expect(nextState[queryId].areTagsAccepted).to.equal(
!initialState[queryId].areTagsAccepted
)
}) })
}) })
@ -352,7 +373,7 @@ describe('Chronograf.Reducers.queryConfig', () => {
expect(nextState[queryId]).to.deep.equal(expected) expect(nextState[queryId]).to.deep.equal(expected)
}) })
it('updates a query\'s raw text', () => { it("updates a query's raw text", () => {
const initialState = { const initialState = {
[queryId]: buildInitialState(queryId), [queryId]: buildInitialState(queryId),
} }
@ -364,7 +385,7 @@ describe('Chronograf.Reducers.queryConfig', () => {
expect(nextState[queryId].rawText).to.equal('foo') expect(nextState[queryId].rawText).to.equal('foo')
}) })
it('updates a query\'s raw status', () => { it("updates a query's raw status", () => {
const initialState = { const initialState = {
[queryId]: buildInitialState(queryId), [queryId]: buildInitialState(queryId),
} }