Skip to content

Commit

Permalink
Rewrite test suite to React Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 20, 2021
1 parent 2bc8097 commit 41b1981
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 173 deletions.
14 changes: 8 additions & 6 deletions test/DateBonduariesOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { getISOLocalDateTime } from '@wojtekmaj/date-utils';
export default function DateBonduariesOptions({
maxDate,
minDate,
setState,
setMaxDate,
setMinDate,
}) {
function onMinChange(event) {
const { value } = event.target;

setState({ minDate: new Date(value) });
setMinDate(new Date(value));
}

function onMaxChange(event) {
const { value } = event.target;

setState({ maxDate: new Date(value) });
setMaxDate(new Date(value));
}

return (
Expand All @@ -37,7 +38,7 @@ export default function DateBonduariesOptions({
/>
 
<button
onClick={() => setState({ minDate: null })}
onClick={() => setMinDate(null)}
type="button"
>
Clear
Expand All @@ -55,7 +56,7 @@ export default function DateBonduariesOptions({
/>
&nbsp;
<button
onClick={() => setState({ maxDate: null })}
onClick={() => setMaxDate(null)}
type="button"
>
Clear
Expand All @@ -68,5 +69,6 @@ export default function DateBonduariesOptions({
DateBonduariesOptions.propTypes = {
maxDate: PropTypes.instanceOf(Date),
minDate: PropTypes.instanceOf(Date),
setState: PropTypes.func.isRequired,
setMaxDate: PropTypes.func.isRequired,
setMinDate: PropTypes.func.isRequired,
};
10 changes: 5 additions & 5 deletions test/LocaleOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';

export default function LocaleOptions({
locale,
setState,
setLocale,
}) {
function onChange(event) {
let { value: nextLocale } = event.target;
Expand All @@ -12,19 +12,19 @@ export default function LocaleOptions({
nextLocale = null;
}

setState({ locale: nextLocale });
setLocale(nextLocale);
}

function onCustomChange(event) {
event.preventDefault();

const { value: nextLocale } = event.target.customLocale;

setState({ locale: nextLocale });
setLocale(nextLocale);
}

function resetLocale() {
setState({ locale: null });
setLocale(null);
}

return (
Expand Down Expand Up @@ -119,5 +119,5 @@ export default function LocaleOptions({

LocaleOptions.propTypes = {
locale: PropTypes.string,
setState: PropTypes.func.isRequired,
setLocale: PropTypes.func.isRequired,
};
10 changes: 7 additions & 3 deletions test/MaxDetailOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ function upperCaseFirstLetter(str) {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}

export default function MaxDetailOptions({ maxDetail, minDetail, setState }) {
export default function MaxDetailOptions({
maxDetail,
minDetail,
setMaxDetail,
}) {
function onChange(event) {
const { value } = event.target;

setState({ maxDetail: value });
setMaxDetail(value);
}

const minDetailIndex = allViews.indexOf(minDetail);
Expand Down Expand Up @@ -45,5 +49,5 @@ export default function MaxDetailOptions({ maxDetail, minDetail, setState }) {
MaxDetailOptions.propTypes = {
maxDetail: PropTypes.oneOf(allViews).isRequired,
minDetail: PropTypes.oneOf(allViews).isRequired,
setState: PropTypes.func.isRequired,
setMaxDetail: PropTypes.func.isRequired,
};
10 changes: 7 additions & 3 deletions test/MinDetailOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ function upperCaseFirstLetter(str) {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}

export default function MinDetailOptions({ maxDetail, minDetail, setState }) {
export default function MinDetailOptions({
maxDetail,
minDetail,
setMinDetail,
}) {
function onChange(event) {
const { value } = event.target;

setState({ minDetail: value });
setMinDetail(value);
}

const maxDetailIndex = allViews.indexOf(maxDetail);
Expand Down Expand Up @@ -45,5 +49,5 @@ export default function MinDetailOptions({ maxDetail, minDetail, setState }) {
MinDetailOptions.propTypes = {
maxDetail: PropTypes.oneOf(allViews).isRequired,
minDetail: PropTypes.oneOf(allViews).isRequired,
setState: PropTypes.func.isRequired,
setMinDetail: PropTypes.func.isRequired,
};
Loading

0 comments on commit 41b1981

Please sign in to comment.