Skip to content

Commit

Permalink
Update after rebase conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarhane committed Dec 10, 2019
1 parent 1d4ad58 commit d08fa31
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`ConfirmationButton renders changes state on clicks and finally calls th
data-testid="confirmation-button-initial"
>
<i
class="IconContainer__I-sc-16whwc5-0 iJwbeZ sl-minus-circle"
class="sl-minus-circle IconContainer__I-sc-16whwc5-0 iJwbeZ"
/>
</button>
</div>
Expand All @@ -21,15 +21,15 @@ exports[`ConfirmationButton renders changes state on clicks and finally calls th
data-testid="confirmation-button-confirm"
>
<i
class="IconContainer__I-sc-16whwc5-0 iJwbeZ sl-arrow-circle-right"
class="sl-arrow-circle-right IconContainer__I-sc-16whwc5-0 iJwbeZ"
/>
</button>
<button
class="ConfirmationButton__IconButton-sc-1h0apyh-0 dvujiG"
data-testid="confirmation-button-cancel"
>
<i
class="IconContainer__I-sc-16whwc5-0 iJwbeZ sl-delete-circle"
class="sl-delete-circle IconContainer__I-sc-16whwc5-0 iJwbeZ"
/>
</button>
</span>
Expand All @@ -43,7 +43,7 @@ exports[`ConfirmationButton renders changes state on clicks and finally calls th
data-testid="confirmation-button-initial"
>
<i
class="IconContainer__I-sc-16whwc5-0 iJwbeZ sl-minus-circle"
class="sl-minus-circle IconContainer__I-sc-16whwc5-0 iJwbeZ"
/>
</button>
</div>
Expand All @@ -56,7 +56,7 @@ exports[`ConfirmationButton renders changes state on clicks and finally calls th
data-testid="confirmation-button-initial"
>
<i
class="IconContainer__I-sc-16whwc5-0 iJwbeZ sl-minus-circle"
class="sl-minus-circle IconContainer__I-sc-16whwc5-0 iJwbeZ"
/>
</button>
</div>
Expand Down
122 changes: 15 additions & 107 deletions src/browser/modules/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,17 @@ import {
import { FOCUS, EXPAND } from 'shared/modules/editor/editorDuck'
import { useBrowserSync } from 'shared/modules/features/featuresDuck'
import { getErrorMessage } from 'shared/modules/commands/commandsDuck'
import {
allowOutgoingConnections,
getVersion
} from 'shared/modules/dbMeta/dbMetaDuck'
import { allowOutgoingConnections } from 'shared/modules/dbMeta/dbMetaDuck'
import {
getActiveConnection,
getConnectionState,
getLastConnectionUpdate,
getActiveConnectionData,
isConnected,
getConnectionData,
SILENT_DISCONNECT,
SWITCH_CONNECTION,
SWITCH_CONNECTION_FAILED
getConnectionData
} from 'shared/modules/connections/connectionsDuck'
import { toggle } from 'shared/modules/sidebar/sidebarDuck'
import {
CONNECTION_ID,
INJECTED_DISCOVERY
} from 'shared/modules/discovery/discoveryDuck'
import { CONNECTION_ID } from 'shared/modules/discovery/discoveryDuck'
import {
StyledWrapper,
StyledApp,
Expand All @@ -66,24 +57,21 @@ import asTitleString from '../DocTitle/titleStringBuilder'
import Intercom from '../Intercom'
import Render from 'browser-components/Render'
import BrowserSyncInit from '../Sync/BrowserSyncInit'
import DesktopIntegration from 'browser-components/DesktopIntegration'
import {
getActiveGraph,
buildConnectionCredentialsObject
} from 'browser-components/DesktopIntegration/helpers'
import { getMetadata, getUserAuthStatus } from 'shared/modules/sync/syncDuck'
import ErrorBoundary from 'browser-components/ErrorBoundary'
import { getExperimentalFeatures } from 'shared/modules/experimentalFeatures/experimentalFeaturesDuck'
import FeatureToggleProvider from '../FeatureToggle/FeatureToggleProvider'
import { inWebEnv, URL_ARGUMENTS_CHANGE } from 'shared/modules/app/appDuck'
import { inWebEnv } from 'shared/modules/app/appDuck'
import useDerivedTheme from 'browser-hooks/useDerivedTheme'
import FileDrop from 'browser-components/FileDrop/FileDrop'
import RelateApi from 'browser-components/relate-api/relate-api'

export function App(props) {
const [derivedTheme, setEnvironmentTheme] = useDerivedTheme(
props.theme,
LIGHT_THEME
)
const themeData = themes[derivedTheme] || themes[LIGHT_THEME]

useEffect(() => {
document.addEventListener('keyup', focusEditorOnSlash)
Expand All @@ -95,15 +83,6 @@ export function App(props) {
}
}, [])

const detectDesktopThemeChanges = (_, newContext) => {
if (newContext.global.prefersColorScheme) {
setEnvironmentTheme(newContext.global.prefersColorScheme)
} else {
setEnvironmentTheme(null)
}
}
const themeData = themes[derivedTheme] || themes[LIGHT_THEME]

const focusEditorOnSlash = e => {
if (['INPUT', 'TEXTAREA'].indexOf(e.target.tagName) > -1) return
if (e.key !== '/') return
Expand All @@ -113,6 +92,7 @@ export function App(props) {
if (e.keyCode !== 27) return
props.bus && props.bus.send(EXPAND)
}

const {
drawer,
cmdchar,
Expand All @@ -129,7 +109,8 @@ export function App(props) {
browserSyncAuthStatus,
experimentalFeatures,
store,
codeFontLigatures
codeFontLigatures,
defaultConnectionData
} = props

const wrapperClassNames = []
Expand All @@ -139,33 +120,16 @@ export function App(props) {

return (
<ErrorBoundary>
<RelateApi
defaultConnectionData={defaultConnectionData}
setEnvironmentTheme={setEnvironmentTheme}
/>
<ThemeProvider theme={themeData}>
<FeatureToggleProvider features={experimentalFeatures}>
<FileDrop store={store}>
<StyledWrapper className={wrapperClassNames}>
<DocTitle titleString={props.titleString} />
<UserInteraction />
<DesktopIntegration
integrationPoint={props.desktopIntegrationPoint}
onArgumentsChange={props.onArgumentsChange}
onMount={(
activeGraph,
connectionsCredentials,
context,
getKerberosTicket
) => {
props.setInitialConnectionData(
activeGraph,
connectionsCredentials,
context,
getKerberosTicket
)
detectDesktopThemeChanges(null, context)
}}
onGraphActive={props.switchConnection}
onGraphInactive={props.closeConnectionMaybe}
onColorSchemeUpdated={detectDesktopThemeChanges}
/>
<Render if={loadExternalScripts}>
<Intercom appID="lq70afwx" />
</Render>
Expand Down Expand Up @@ -222,8 +186,7 @@ const mapStateToProps = state => {
browserSyncConfig: getBrowserSyncConfig(state),
browserSyncAuthStatus: getUserAuthStatus(state),
loadSync: useBrowserSync(state),
isWebEnv: inWebEnv(state),
neo4jVersion: getVersion(state)
isWebEnv: inWebEnv(state)
}
}

Expand All @@ -235,59 +198,4 @@ const mapDispatchToProps = dispatch => {
}
}

const mergeProps = (stateProps, dispatchProps, ownProps) => {
const switchConnection = async (
event,
newContext,
oldContext,
getKerberosTicket
) => {
const connectionCreds = await buildConnectionCredentialsObject(
newContext,
stateProps.defaultConnectionData,
getKerberosTicket,
stateProps.neo4jVersion
)
ownProps.bus.send(SWITCH_CONNECTION, connectionCreds)
}
const setInitialConnectionData = async (
graph,
credentials,
context,
getKerberosTicket
) => {
const connectionCreds = await buildConnectionCredentialsObject(
context,
stateProps.defaultConnectionData,
getKerberosTicket,
stateProps.neo4jVersion
)
// No connection. Probably no graph active.
if (!connectionCreds) {
ownProps.bus.send(SWITCH_CONNECTION_FAILED)
return
}
ownProps.bus.send(INJECTED_DISCOVERY, connectionCreds)
}
const closeConnectionMaybe = (event, newContext, oldContext) => {
const activeGraph = getActiveGraph(newContext)
if (activeGraph) return // We still got an active graph, do nothing
ownProps.bus.send(SILENT_DISCONNECT, {})
}
const onArgumentsChange = argsString => {
ownProps.bus.send(URL_ARGUMENTS_CHANGE, { url: `?${argsString}` })
}
return {
...stateProps,
...ownProps,
...dispatchProps,
switchConnection,
setInitialConnectionData,
closeConnectionMaybe,
onArgumentsChange
}
}

export default withBus(
connect(mapStateToProps, mapDispatchToProps, mergeProps)(App)
)
export default withBus(connect(mapStateToProps, mapDispatchToProps)(App))
83 changes: 6 additions & 77 deletions src/browser/modules/App/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,108 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global jest, test, expect */
import React from 'react'
import { render } from '@testing-library/react'
import configureMockStore from 'redux-mock-store'
import { App } from './App'
import { buildConnectionCredentialsObject } from 'browser-components/DesktopIntegration/helpers'
import { flushPromises } from 'services/utils'

const mockStore = configureMockStore()
const store = mockStore({})

jest.mock('../FeatureToggle/FeatureToggleProvider', () => {
const FT = ({ children }) => <div>{children}</div>
FT.displayName = 'FTMock'
return FT
return ({ children }) => <div>{children}</div>
})
jest.mock('./styled', () => {
const orig = require.requireActual('./styled')
return {
...orig,
StyledApp: () => null
StyledApp: () => <div>Loaded</div>
}
})

describe('App', () => {
test('App loads', async () => {
// Given
const getKerberosTicket = jest.fn(() => Promise.resolve('xxx'))
const desktopIntegrationPoint = getIntegrationPoint(true, getKerberosTicket)
let connectionCreds = null
const props = {
store,
desktopIntegrationPoint,
setInitialConnectionData: async (
graph,
credentials,
context,
getKerberosTicket
) => {
connectionCreds = await buildConnectionCredentialsObject(
context,
{},
getKerberosTicket
)
}
store
}

// When
render(<App {...props} />)
const { getByText } = render(<App {...props} />)

// Then
await flushPromises()
expect(connectionCreds).toMatchObject({
authenticationMethod: 'KERBEROS',
password: 'xxx'
})
expect(getKerberosTicket).toHaveBeenCalledTimes(1)
expect(getByText('Loaded'))
})
})

const getIntegrationPoint = (kerberosEnabled, getKerberosTicket) => {
const context = Promise.resolve(getDesktopContext(kerberosEnabled))
return {
getKerberosTicket: getKerberosTicket,
getContext: () => context
}
}

const getDesktopContext = (kerberosEnabled = false) => ({
projects: [
{
graphs: [
{
status: 'ACTIVE',
connection: {
type: 'REMOTE',
configuration: {
authenticationMethods: {
kerberos: {
enabled: kerberosEnabled,
servicePrincipal: 'KERBEROS'
}
},
protocols: {
bolt: {
enabled: true,
username: 'neo4j',
password: 'password',
tlsLevel: 'REQUIRED',
url: 'bolt://localhost:7687'
},
http: {
enabled: true,
username: 'neo4j',
password: 'password',
host: 'localhost',
port: '7474'
}
}
}
}
}
]
}
]
})
Loading

0 comments on commit d08fa31

Please sign in to comment.