Skip to content

Commit

Permalink
Merge pull request neo4j#850 from oskarhane/no-init-cmd
Browse files Browse the repository at this point in the history
Let the configuration initCmd be empty
  • Loading branch information
oskarhane authored Oct 23, 2018
2 parents f6b2777 + bbeb37c commit b58410b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/browser/modules/Sidebar/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ const visualSettings = [
tooltip: 'Show sample scripts in favorites drawer.',
type: 'checkbox'
}
},
{
initCmd: {
displayName: 'Initial command to execute',
tooltip: 'This commands is executed once connected to a graph.',
type: 'input'
}
}
]
},
Expand Down
10 changes: 8 additions & 2 deletions src/shared/modules/commands/commandsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ export const handleSingleCommandEpic = (action$, store) =>
)
.mergeMap(({ action, interpreted, cmdchar }) => {
return new Promise((resolve, reject) => {
if (interpreted.name !== 'cypher') action.cmd = cleanCommand(action.cmd)
const res = interpreted.exec(action, cmdchar, store.dispatch, store)
const noop = { type: 'NOOP' }
if (!(action.cmd || '').trim().length) {
resolve(noop)
return
}
if (interpreted.name !== 'cypher') {
action.cmd = cleanCommand(action.cmd)
}
const res = interpreted.exec(action, cmdchar, store.dispatch, store)
if (!res || !res.then) {
resolve(noop)
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/shared/modules/commands/commandsDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ describe('commandsDuck', () => {
// See snoopOnActions above
})

test('emtpy SYSTEM_COMMAND_QUEUED gets ignored', done => {
// Given
const cmd = ' '
const id = 2
const action = commands.executeSystemCommand(cmd, id)
bus.take('NOOP', () => {
// Then
const actions = store.getActions()
expect(actions[0]).toEqual(action)
expect(actions[1]).toEqual({ type: 'NOOP' })
done()
})
// When
store.dispatch(action)
})

test('does the right thing for :param x: 2', done => {
// Given
const cmd = store.getState().settings.cmdchar + 'param'
Expand Down
2 changes: 1 addition & 1 deletion src/shared/modules/settings/settingsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const REPLACE = 'settings/REPLACE'
export const getSettings = state => state[NAME]
export const getMaxHistory = state =>
state[NAME].maxHistory || initialState.maxHistory
export const getInitCmd = state => state[NAME].initCmd || initialState.initCmd
export const getInitCmd = state => (state[NAME].initCmd || '').trim()
export const getTheme = state => state[NAME].theme || initialState.theme
export const getUseBoltRouting = state =>
state[NAME].useBoltRouting || initialState.useBoltRouting
Expand Down
30 changes: 29 additions & 1 deletion src/shared/modules/settings/settingsDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
*/

/* global describe, test, expect */
import reducer, { NAME, UPDATE, REPLACE, shouldReportUdc } from './settingsDuck'
import reducer, {
NAME,
UPDATE,
REPLACE,
shouldReportUdc,
getInitCmd
} from './settingsDuck'
import { dehydrate } from 'services/duckUtils'

describe('settings reducer', () => {
Expand Down Expand Up @@ -89,4 +95,26 @@ describe('Selectors', () => {
expect(shouldReportUdc(state)).toEqual(t.expect)
})
})
test("let getInitCmd be falsy and cast to empty string if that's the case", () => {
// Given
const tests = [
{ test: ':play start', expect: ':play start' },
{ test: null, expect: '' },
{ test: undefined, expect: '' },
{ test: '', expect: '' },
{ test: ' ', expect: '' },
{
test: '//Todays number is:\nRETURN rand()',
expect: '//Todays number is:\nRETURN rand()'
}
]

// When && Then
tests.forEach(t => {
const state = {
[NAME]: { initCmd: t.test }
}
expect(getInitCmd(state)).toEqual(t.expect)
})
})
})

0 comments on commit b58410b

Please sign in to comment.