Skip to content

Commit

Permalink
Merge pull request neo4j#793 from pe4cey/force-single-statement-mode
Browse files Browse the repository at this point in the history
Add toggle for multi statement cypher editor
  • Loading branch information
pe4cey authored Jul 10, 2018
2 parents 8cae0c6 + e279b9d commit 5cac4c1
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
43 changes: 40 additions & 3 deletions e2e_tests/integration/multistatements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before, after */

describe('Multi statements', () => {
const validQuery = 'RETURN 1; :config; RETURN 2;'

before(() => {
cy.get('[data-test-id="drawerSettings"]').click()
cy.get('[data-test-id="enableMultiStatementMode"]').click()
cy.get('[data-test-id="drawerSettings"]').click()
})
after(() => {
cy.get('[data-test-id="drawerSettings"]').click()
cy.get('[data-test-id="enableMultiStatementMode"]').click()
cy.get('[data-test-id="drawerSettings"]').click()
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
cy.connect(
Expand All @@ -30,8 +42,7 @@ describe('Multi statements', () => {
})
it('can run multiple statements (non open by default)', () => {
cy.executeCommand(':clear')
const query = 'RETURN 1; :config; RETURN 2;'
cy.executeCommand(query)
cy.executeCommand(validQuery)
cy.get('[data-test-id="frame"]', { timeout: 10000 }).should(
'have.length',
1
Expand All @@ -45,6 +56,32 @@ describe('Multi statements', () => {
.get('[data-test-id="multi-statement-list-content"]')
.should('have.length', 0)
})

it('can force run multiple statements to be executed as one statement', () => {
// Given
cy.executeCommand(':clear')
cy.get('[data-test-id="drawerSettings"]').click()
cy.get('[data-test-id="enableMultiStatementMode"]').click()
cy.get('[data-test-id="drawerSettings"]').click()

// When
cy.executeCommand(validQuery)
cy.waitForCommandResult()

// Then
// Error expected
cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
.first()
.should('contain', validQuery)
cy.get('[data-test-id="frameStatusbar"]', { timeout: 10000 })
.first()
.should('contain', 'Error')

cy.get('[data-test-id="drawerSettings"]').click()
cy.get('[data-test-id="enableMultiStatementMode"]').click()
cy.get('[data-test-id="drawerSettings"]').click()
})

it('can run multiple statements with error open', () => {
cy.executeCommand(':clear')
const query = 'RETURN 1; RETURN $nonsetparam; RETURN 2;'
Expand Down
8 changes: 8 additions & 0 deletions src/browser/modules/Sidebar/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ const visualSettings = [
tooltip: 'Autocomplete and syntax highlighting in query editor',
type: 'checkbox'
}
},
{
enableMultiStatementMode: {
displayName: 'Enable multi statement query editor',
tooltip: 'Allows query editor to execute multiple statements',
type: 'checkbox'
}
}
]
},
Expand Down Expand Up @@ -193,6 +200,7 @@ export const Settings = ({
onSettingsSave(settings)
}}
checked={settings[setting]}
data-test-id={setting}
/>
<StyledSettingLabel title={tooltip}>{visual}</StyledSettingLabel>
</StyledSetting>
Expand Down
11 changes: 9 additions & 2 deletions src/shared/modules/commands/commandsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ import {
} from 'services/utils'
import helper from 'services/commandInterpreterHelper'
import { addHistory } from '../history/historyDuck'
import { getCmdChar, getMaxHistory } from '../settings/settingsDuck'
import {
getCmdChar,
getMaxHistory,
shouldEnableMultiStatementMode
} from '../settings/settingsDuck'
import { fetchRemoteGuide } from './helpers/play'
import { CONNECTION_SUCCESS } from '../connections/connectionsDuck'
import {
Expand Down Expand Up @@ -137,7 +141,10 @@ export const handleCommandEpic = (action$, store) =>
store.dispatch(clearErrorMessage())
const maxHistory = getMaxHistory(store.getState())
store.dispatch(addHistory(action.cmd, maxHistory))
const statements = extractStatementsFromString(action.cmd)
const statements = shouldEnableMultiStatementMode(store.getState())
? extractStatementsFromString(action.cmd)
: [action.cmd]

if (!statements.length || !statements[0]) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/modules/commands/multiCommands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ describe('handleCommandEpic', () => {
store = mockStore({
settings: {
cmdchar: ':',
maxHistory: maxHistory
maxHistory: maxHistory,
enableMultiStatementMode: true
},
history: [':xxx'],
connections: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Object {
"cmdchar": ":",
"editorAutocomplete": true,
"editorLint": false,
"enableMultiStatementMode": false,
"initCmd": ":play start",
"initialNodeDisplay": 300,
"maxFrames": 30,
Expand Down
5 changes: 4 additions & 1 deletion src/shared/modules/settings/settingsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const getScrollToTop = state => state[NAME].scrollToTop
export const shouldReportUdc = state => state[NAME].shouldReportUdc !== false
export const shouldAutoComplete = state => state[NAME].autoComplete !== false
export const shouldEditorLint = state => state[NAME].editorLint === true
export const shouldEnableMultiStatementMode = state =>
state[NAME].enableMultiStatementMode

const browserSyncConfig = (host = 'https://auth.neo4j.com') => ({
authWindowUrl: `${host}/indexNewBrowser.html`,
Expand Down Expand Up @@ -79,7 +81,8 @@ const initialState = {
maxFrames: 30,
editorAutocomplete: true,
editorLint: false,
useCypherThread: true
useCypherThread: true,
enableMultiStatementMode: false
}

export default function settings (state = initialState, action) {
Expand Down

0 comments on commit 5cac4c1

Please sign in to comment.