-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1621 from freedomofpress/frontend-testing
Add snapshot frontend testing
- Loading branch information
Showing
49 changed files
with
9,251 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ db.sqlite3* | |
/static/ | ||
/media/ | ||
/htmlcov/ | ||
/coverage/ | ||
/pressfreedom/settings/local.py | ||
*.pyc | ||
__pycache__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
// babel.config.js | ||
module.exports = api => { | ||
const isTest = api.env('test') | ||
if (isTest) { | ||
return { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
"targets": { | ||
"node": "current" | ||
}, | ||
}, | ||
], | ||
'@babel/preset-react', | ||
], | ||
plugins: [ | ||
"@babel/plugin-transform-modules-commonjs", | ||
], | ||
} | ||
} else { | ||
return { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
}, | ||
], | ||
'@babel/preset-react', | ||
], | ||
} | ||
} | ||
}; | ||
module.exports = (api) => { | ||
const isTest = api.env('test') | ||
if (isTest) { | ||
return { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
'@babel/preset-react', | ||
], | ||
plugins: [ | ||
'@babel/plugin-transform-modules-commonjs', | ||
], | ||
} | ||
} | ||
return { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
}, | ||
], | ||
'@babel/preset-react', | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
client/charts/js/components/__tests__/Autocomplete.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import Autocomplete from '../Autocomplete' | ||
|
||
test('renders Autocomplete with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<Autocomplete | ||
suggestions={[{label: "test label"}]} | ||
suggestionsLabelField={'label'} | ||
placeholder={'test'} | ||
name={'test autocomplete'} | ||
itemNamePlural={'tests'} | ||
handleSelect={() => {}} | ||
suggestionsSidenoteField={'sidenote'} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import BarChart from '../BarChart' | ||
|
||
test('renders BarChart with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<BarChart | ||
data={[{"month":10,"monthName":"Nov","numberOfIncidents":0},{"month":11,"monthName":"Dec","numberOfIncidents":0},{"month":0,"monthName":"Jan","numberOfIncidents":0},{"month":1,"monthName":"Feb","numberOfIncidents":0},{"month":2,"monthName":"Mar","numberOfIncidents":0},{"month":3,"monthName":"Apr","numberOfIncidents":0}]} | ||
x="monthName" | ||
y="numberOfIncidents" | ||
titleLabel="incidents" | ||
isMobileView={false} | ||
width={480} | ||
height={500} | ||
openSearchPage={() => {}} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
17 changes: 17 additions & 0 deletions
17
client/charts/js/components/__tests__/BarChartYears.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import BarChartYears from '../BarChartYears' | ||
|
||
test('renders BarChartYears with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<BarChartYears | ||
countYears={[{"year":2012,"count":2,"numberOfIncidents":0}]} | ||
x="monthName" | ||
y="numberOfIncidents" | ||
selectedYears={[2012]} | ||
width={480} | ||
height={500} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import Button from '../Button' | ||
|
||
test('renders Button with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<Button | ||
label="test" | ||
selected={false} | ||
onClick={() => {}} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import ButtonsRow from '../ButtonsRow' | ||
|
||
test('renders ButtonsRow with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<ButtonsRow | ||
label="test" | ||
buttonLabels={['test1', 'test2']} | ||
updateSelection={() => {}} | ||
isButtonSelectable={() => true} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
16 changes: 16 additions & 0 deletions
16
client/charts/js/components/__tests__/CategoryFilter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import CategoryFilter from '../CategoryFilter' | ||
|
||
test('renders CategoryFilter with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<CategoryFilter | ||
dataset={[{ categories: ['test'] }]} | ||
filterDefs={[{ title: 'test-def', id: 'test-def', symbol: 'test-def', filters: [] }]} | ||
filterParameters={{}} | ||
width={500} | ||
height={500} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
15 changes: 15 additions & 0 deletions
15
client/charts/js/components/__tests__/CategoryPageChart.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import * as d3 from 'd3' | ||
import Renderer from 'react-test-renderer' | ||
import CategoryPageChart from '../CategoryPageChart' | ||
|
||
test('renders CategoryPageChart with mocked data', () => { | ||
expect(Renderer.create( | ||
<CategoryPageChart | ||
data={[{ categories: ['test'], date: d3.timeParse("%m-%d-%Y")('1-1-2020') }]} | ||
category={'test'} | ||
width={500} | ||
categoryName={'test'} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
12 changes: 12 additions & 0 deletions
12
client/charts/js/components/__tests__/CategorySection.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import CategorySection from '../CategorySection' | ||
|
||
test('renders CategorySection with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<CategorySection symbol="test" label="test" count={2} isOpen={false} onClick={() => {}}> | ||
This is a test | ||
</CategorySection> | ||
)).toMatchSnapshot(); | ||
}); |
12 changes: 12 additions & 0 deletions
12
client/charts/js/components/__tests__/ChartDescription.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import ChartDescription from '../ChartDescription' | ||
|
||
test('renders ChartDescription with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<ChartDescription id="test"> | ||
This is a test | ||
</ChartDescription> | ||
)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import CheckBoxBar from '../CheckBoxBar' | ||
|
||
test('renders CheckBoxBar with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<CheckBoxBar | ||
label="test" | ||
count={2} | ||
isSelected={false} | ||
onClick={() => {}} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
15 changes: 15 additions & 0 deletions
15
client/charts/js/components/__tests__/CheckBoxesYear.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import ShallowRenderer from 'react-test-renderer/shallow' | ||
import CheckBoxesYear from '../CheckBoxesYear' | ||
|
||
test('renders CheckBoxesYear with mocked data', () => { | ||
const renderer = new ShallowRenderer(); | ||
expect(renderer.render( | ||
<CheckBoxesYear | ||
width={500} | ||
options={[{ year: 2020 }]} | ||
selectedYears={[2020]} | ||
onClick={() => {}} | ||
/> | ||
)).toMatchSnapshot(); | ||
}); |
Oops, something went wrong.