Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only clear interventions on Intervention unmount #5349

Merged
merged 3 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/classifier/components/Intervention/Intervention.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ const StyledInterventionMessage = styled.div`
}
`;

function Intervention({ onUnmount, intervention, user }) {
function Intervention(props) {
const { onUnmount, intervention, user } = props;
const { message } = intervention;
const checkbox = React.createRef();

useEffect(() => {
// the return value of an effect will be called to clean up after the component
/* the return value of an effect will be called to clean up after the component.
Passing an empty array ([]) as a second argument tells React that your effect doesn’t depend on any values from props or state
so it never needs to re-run, https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects */
return onUnmount;
});
}, []);
camallen marked this conversation as resolved.
Show resolved Hide resolved

function onChange() {
// Invert the checked value because true means do not send me messages.
Expand Down
14 changes: 12 additions & 2 deletions app/classifier/components/Intervention/Intervention.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ describe('Intervention', function () {
})
});

describe('on props change', function () {
before(function () {
wrapper.setProps({ intervention: {message: 'Hello' } });
});

it('should not call onUnmount', function () {
expect(onUnmount).to.have.not.been.called
});
});

describe('on unmount', function () {
before(function () {
wrapper.unmount()
});

it('should call onUnmount', function () {
expect(onUnmount).to.have.been.calledOnce
})
})
});
});
});