Skip to content
Snippets Groups Projects
Commit 41c0fb2f authored by esikkala's avatar esikkala
Browse files

Remove jest folder

parent 280aaa30
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import ReactDOM from 'react-dom';
import IntegrationAutosuggest from '../components/IntegrationAutosuggest';
import renderer from 'react-test-renderer';
import { mount } from 'enzyme';
import { INITIAL_STATE } from '../reducers/search';
describe('IntegrationAutosuggest', () => {
let updateQuery, fetchSuggestions, clearSuggestions;
beforeEach(() => {
updateQuery = jest.fn();
fetchSuggestions = jest.fn();
clearSuggestions = jest.fn();
});
test('Renders with initial state without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(
<IntegrationAutosuggest search={INITIAL_STATE} updateQuery={updateQuery}
fetchSuggestions={fetchSuggestions} clearSuggestions={clearSuggestions} />,
div
);
});
test('Displays query string', () => {
const newState = { ...INITIAL_STATE, query: 'kivennapa' };
const component = renderer.create(
<IntegrationAutosuggest search={newState} updateQuery={updateQuery}
fetchSuggestions={fetchSuggestions} clearSuggestions={clearSuggestions} />,
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('Calls updateQuery and fetchSuggestions when user input changes', () => {
const component = mount(
<IntegrationAutosuggest search={INITIAL_STATE} updateQuery={updateQuery}
fetchSuggestions={fetchSuggestions} clearSuggestions={clearSuggestions} />,
);
expect(fetchSuggestions.mock.calls.length).toBe(0);
component.find('input').simulate('change', { target: { value: 'kivennapa' } });
expect(updateQuery.mock.calls.length).toBe(1);
expect(updateQuery.mock.calls[0][0]).toEqual('kivennapa');
expect(fetchSuggestions.mock.calls.length).toBe(1);
});
});
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`IntegrationAutosuggest Displays query string 1`] = `
<div
className="IntegrationAutosuggest-container-1"
>
<div
aria-describedby={undefined}
className="MuiFormControl-root-7 MuiFormControl-fullWidth-10"
onBlur={[Function]}
onFocus={[Function]}
>
<div
aria-activedescendant={null}
aria-autocomplete="list"
aria-expanded={false}
aria-owns="react-autowhatever-1"
className="MuiInput-root-11 MuiInput-fullWidth-18 MuiInput-formControl-12 MuiInput-underline-15"
role="combobox"
style={Object {}}
>
<input
aria-invalid={false}
aria-required={false}
autoComplete="off"
autoFocus={undefined}
className="MuiInput-input-19"
defaultValue={undefined}
disabled={false}
id={undefined}
name={undefined}
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={undefined}
placeholder="Search place names"
readOnly={undefined}
required={undefined}
rows={undefined}
type="text"
value="kivennapa"
/>
</div>
</div>
<div
className="MuiPaper-root-24 MuiPaper-elevation2-28"
id="react-autowhatever-1"
style={Object {}}
/>
</div>
`;
import { updateSuggestions } from '../reducers/suggestions';
describe('suggestions', () => {
describe('updateSuggestions', () => {
test('Adds short titles', () => {
const results = [
{
'label': 'Viipuri',
'datasets': [
{
datasetId: 'warsa_karelian_places',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '1'
}
},
{
datasetId: 'warsa_municipalities',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '1'
}
},
],
},
{
'label': 'Viipurinlahti',
'datasets': [
{
datasetId: 'warsa_karelian_places',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '2'
}
},
],
},
];
const expected = [
{
'label': 'Viipuri',
'datasets': [
{
datasetId: 'warsa_karelian_places',
shortTitle: 'wkp',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '1'
}
},
{
datasetId: 'warsa_municipalities',
shortTitle: 'wm',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '1'
}
},
],
},
{
'label': 'Viipurinlahti',
'datasets': [
{
datasetId: 'warsa_karelian_places',
shortTitle: 'wkp',
count: {
type: 'literal',
datatype: 'http://www.w3.org/2001/XMLSchema#integer',
value: '2'
}
},
],
},
];
expect(updateSuggestions({ results })).toEqual(expected);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment