Skip to content

Commit

Permalink
bla
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeG committed Sep 1, 2019
1 parent a9b1580 commit 0b44f58
Show file tree
Hide file tree
Showing 31 changed files with 972 additions and 118 deletions.
1 change: 1 addition & 0 deletions eventol/front/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"files": [
"src/**/*.{spec,test}.{js,jsx}",
"src/**/__mocks__/*.{js,jsx}",
"config/jest/setupTests.jsx",
"src/setupTests.js"
],
"globals": {
Expand Down
26 changes: 25 additions & 1 deletion eventol/front/config/jest/setupTests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,28 @@ const matchMedia = () => ({
});

window.matchMedia = window.matchMedia || matchMedia;
jest.mock('react-sizes', () => () => Component => props => <Component {...props} />);
jest.mock('react-sizes', () => () => Component => props => (
<Component {...props} />
));

global.L = {
map: jest.fn(() => ({
setView: jest.fn(() => ({
attributionControl: {
setPrefix: jest.fn(),
},
})),
})),
tileLayer: jest.fn(() => ({
addTo: jest.fn(),
})),
marker: jest.fn(() => ({
addTo: jest.fn(),
})),
};

jest.mock('../../src/utils/logger', () => ({
error: jest.fn(),
warning: jest.fn(),
log: jest.fn(),
}));
3 changes: 2 additions & 1 deletion eventol/front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"<rootDir>/config/jest/setupTests.jsx"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
"src/**/*.{js,jsx}",
"!src/utils/__mock__/**/*.{js,jsx}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
Expand Down
1 change: 0 additions & 1 deletion eventol/front/src/components/Item/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jest.mock('../../utils/urls', () => ({
import ItemMap from '../ItemMap';

import {event1} from '../../utils/__mock__/data';
import {getTagUrl, goToUrl} from '../../utils/urls';

import Item from '.';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ItemMap Default Snapshot 1`] = `undefined`;
exports[`ItemMap Default Snapshot 1`] = `
<div
className="item max-size"
id="1event1slug"
>
<a
href="event1Url"
>
<div
className="overlay"
>
<div
className="title"
>
event 1
</div>
<div
className="rating"
>
Attendees: 10
</div>
<div
className="plot"
>
event1overview
</div>
</div>
</a>
</div>
`;
10 changes: 7 additions & 3 deletions eventol/front/src/components/ItemMap/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import renderer from 'react-test-renderer';

import ItemMap from '.';

import {event1} from '../../utils/__mock__/data';

describe('ItemMap', () => {
let component;
let instance;
let sliderId;
let tree;

const getComponent = () => {
component = renderer.create(<ItemMap />);
component = renderer.create(<ItemMap sliderId={sliderId} {...event1} />);
return component;
};

beforeEach(() => {
sliderId = event1.id.toString();
const id = `${sliderId}${event1.eventSlug}`;
document.body.innerHTML = `<div><div id="${id}">Map</div></div>`;
component = getComponent();
instance = renderer.root;
tree = component.toJSON();
});

Expand Down
2 changes: 0 additions & 2 deletions eventol/front/src/components/ListToggle/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ListToggle from '.';

describe('ListToggle', () => {
let component;
let instance;
let tree;

const getComponent = () => {
Expand All @@ -15,7 +14,6 @@ describe('ListToggle', () => {

beforeEach(() => {
component = getComponent();
instance = renderer.root;
tree = component.toJSON();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ exports[`Logo Default Snapshot 1`] = `
</a>
</div>
`;

exports[`Logo With custom logo Snapshot 1`] = `
<div
className="logo-component"
id="logo"
>
<a
href="/"
>
<img
alt="header logo"
src="http://logoHeader/"
/>
</a>
</div>
`;
15 changes: 12 additions & 3 deletions eventol/front/src/components/Logo/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import Logo from '.';

describe('Logo', () => {
let component;
let instance;
let logoHeader;
let tree;

const getComponent = () => {
component = renderer.create(<Logo />);
component = renderer.create(<Logo logoHeader={logoHeader} />);
return component;
};

beforeEach(() => {
logoHeader = undefined;
component = getComponent();
instance = renderer.root;
tree = component.toJSON();
});

Expand All @@ -24,4 +24,13 @@ describe('Logo', () => {
expect(tree).toMatchSnapshot();
});
});

describe('With custom logo', () => {
test('Snapshot', () => {
logoHeader = 'http://logoHeader/';
component = getComponent();
tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
});
});
2 changes: 0 additions & 2 deletions eventol/front/src/components/Navigation/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Navigation from '.';

describe('Navigation', () => {
let component;
let instance;
let tree;

const getComponent = () => {
Expand All @@ -15,7 +14,6 @@ describe('Navigation', () => {

beforeEach(() => {
component = getComponent();
instance = renderer.root;
tree = component.toJSON();
});

Expand Down
5 changes: 2 additions & 3 deletions eventol/front/src/components/ReportTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ReportTable = props => {
totals,
} = props;
const columns = getColumns(table, eventsPrivateData, count, totals);
if (exportButton) exportButton.updateCsv(columns);
exportButton.updateCsv(columns);
return (
<ReactTable
className="-striped -highlight"
Expand All @@ -46,7 +46,7 @@ ReportTable.propTypes = {
data: PropTypes.arrayOf(PropTypes.shape()),
defaultRows: PropTypes.number,
eventsPrivateData: PropTypes.arrayOf(PropTypes.shape()),
exportButton: PropTypes.instanceOf(ExportButton),
exportButton: PropTypes.instanceOf(ExportButton).isRequired,
fetchData: PropTypes.func.isRequired,
isLoading: PropTypes.bool,
pages: PropTypes.number,
Expand All @@ -59,7 +59,6 @@ ReportTable.defaultProps = {
data: [],
defaultRows: 0,
eventsPrivateData: [],
exportButton: null,
isLoading: true,
pages: 0,
table: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,35 @@ exports[`Search Default Snapshot 1`] = `
/>
</div>
`;

exports[`Search Default Snapshot with update text 1`] = `
<div
className="search"
id="search"
>
<input
id="search-input"
onChange={[Function]}
onKeyUp={[Function]}
placeholder="Search by title..."
type="search"
value=""
/>
</div>
`;

exports[`Search Default Snapshot with update text 2`] = `
<div
className="search"
id="search"
>
<input
id="search-input"
onChange={[Function]}
onKeyUp={[Function]}
placeholder="Search by title..."
type="search"
value="searchTerm"
/>
</div>
`;
13 changes: 9 additions & 4 deletions eventol/front/src/components/Search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@ import PropTypes from 'prop-types';

import './index.scss';

export default class Search extends React.Component {
export default class Search extends React.PureComponent {
static propTypes = {
onChange: PropTypes.func.isRequired,
onChange: PropTypes.func,
onEnter: PropTypes.func.isRequired,
};

static defaultProps = {
onChange: () => {},
};

state = {
searchTerm: '',
};

handleKeyUp = ({key}) => {
if (key === 'Enter') {
const {onEnter} = this.props;
if (onEnter) onEnter();
const {searchTerm} = this.state;
onEnter(searchTerm);
}
};

handleChange = ({target: {value: searchTerm}}) => {
this.setState({searchTerm});
const {onChange} = this.props;
if (onChange) onChange(searchTerm);
onChange(searchTerm);
};

render() {
Expand Down
47 changes: 43 additions & 4 deletions eventol/front/src/components/Search/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
import wait from 'waait';
import React from 'react';
import renderer from 'react-test-renderer';

import Search from '.';

describe('Search', () => {
let component;
let instance;
let tree;
let onEnter;
let element;
let onChange;
let instance;
let component;

const getComponent = () => {
component = renderer.create(<Search />);
element = <Search onChange={onChange} onEnter={onEnter} />;
component = renderer.create(element);
return component;
};

beforeEach(() => {
onChange = jest.fn();
onEnter = jest.fn();
component = getComponent();
instance = renderer.root;
instance = component.root;
tree = component.toJSON();
});

describe('Default', () => {
test('Snapshot', () => {
expect(tree).toMatchSnapshot();
});

test('Snapshot with update text', async () => {
expect(tree).toMatchSnapshot();

const value = 'searchTerm';
instance.findByType('input').props.onChange({target: {value}});
component.update(element);
await wait(0);

tree = component.toJSON();
expect(tree).toMatchSnapshot();
expect(instance.findByType('input').props.value).toEqual(value);
});
});

test('handle onChange', () => {
const value = 'searchTerm';
instance.findByType('input').props.onChange({target: {value}});
expect(onChange).toBeCalled();
expect(onChange).toBeCalledWith(value);
});

describe('handle onKeyUp', () => {
test('With not Enter key', () => {
instance.findByType('input').props.onKeyUp({key: 'A'});
expect(onEnter).not.toBeCalled();
});

test('With Enter key', () => {
instance.findByType('input').props.onKeyUp({key: 'Enter'});
expect(onEnter).toBeCalled();
});
});
});
2 changes: 0 additions & 2 deletions eventol/front/src/components/SignIn/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import SignIn from '.';

describe('SignIn', () => {
let component;
let instance;
let tree;

const getComponent = () => {
Expand All @@ -15,7 +14,6 @@ describe('SignIn', () => {

beforeEach(() => {
component = getComponent();
instance = renderer.root;
tree = component.toJSON();
});

Expand Down
Loading

0 comments on commit 0b44f58

Please sign in to comment.