Skip to content

Commit 2500e0d

Browse files
committed
Add tests to make sure CypherFrame toggles views correctly
1 parent a2bff43 commit 2500e0d

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

src/browser/components/icons/Icons.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ export const EditIcon = () => (
309309
/>
310310
)
311311
export const Spinner = () => (
312-
<IconContainer className='fa fa-spinner fa-spin fa-2x' />
312+
<IconContainer
313+
data-testid='spinner'
314+
className='fa fa-spinner fa-spin fa-2x'
315+
/>
313316
)
314317
export const SmallSpinner = () => (
315318
<IconContainer className='fa fa-spinner fa-spin ' />
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2002-2018 "Neo4j, Inc"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/* global describe, test, expect */
22+
import React from 'react'
23+
import { render } from 'react-testing-library'
24+
import { Provider } from 'react-redux'
25+
26+
import { CypherFrame } from './index.jsx'
27+
28+
const createProps = (status, result) => ({
29+
recentView: undefined,
30+
frame: {},
31+
request: {
32+
status,
33+
updated: Math.random(),
34+
result
35+
}
36+
})
37+
const withProvider = (store, children) => {
38+
return <Provider store={store}>{children}</Provider>
39+
}
40+
41+
describe('CypherFrame', () => {
42+
const store = {
43+
subscribe: () => {},
44+
dispatch: () => {},
45+
getState: () => ({})
46+
}
47+
test('renders accordingly from pending to success to error to success', () => {
48+
// Given
49+
const pendingProps = createProps('pending', undefined)
50+
const successProps = createProps('success', {
51+
records: [{ keys: ['name'], _fields: ['Molly'], get: () => 'Molly' }]
52+
})
53+
const errorProps = createProps('error', { code: 'Test.Error' })
54+
55+
// When
56+
const { queryByText, getByText, getByTestId, rerender } = render(
57+
withProvider(store, <CypherFrame {...pendingProps} />)
58+
)
59+
60+
// Then
61+
expect(getByTestId('spinner')).not.toBeNull()
62+
expect(getByText(/Table/i)).not.toBeNull()
63+
expect(getByText(/Code/i)).not.toBeNull()
64+
expect(queryByText(/Error/)).toBeNull()
65+
66+
// When successful request
67+
rerender(withProvider(store, <CypherFrame {...successProps} />))
68+
69+
// Then
70+
expect(getByText(/Molly/i)).not.toBeNull()
71+
expect(getByText(/Table/i)).not.toBeNull()
72+
expect(getByText(/Code/i)).not.toBeNull()
73+
expect(queryByText(/Error/)).toBeNull()
74+
75+
// When error request
76+
rerender(withProvider(store, <CypherFrame {...errorProps} />))
77+
78+
// Then
79+
expect(queryByText(/Table/i)).toBeNull()
80+
expect(queryByText(/Code/i)).toBeNull()
81+
expect(getByText(/Error/)).not.toBeNull()
82+
expect(getByText(/Test.Error/)).not.toBeNull()
83+
84+
// When successful request again
85+
rerender(withProvider(store, <CypherFrame {...successProps} />))
86+
87+
// Then
88+
expect(getByText(/Molly/i)).not.toBeNull()
89+
expect(getByText(/Table/i)).not.toBeNull()
90+
expect(getByText(/Code/i)).not.toBeNull()
91+
expect(queryByText(/Error/)).toBeNull()
92+
})
93+
})

0 commit comments

Comments
 (0)