Skip to content

Commit

Permalink
fix: 🐛 funnel state reset
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejrybaniec committed Oct 8, 2020
1 parent 29e90c7 commit 8768ce4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { Provider } from 'react-redux';
import { render as rtlRender, fireEvent } from '@testing-library/react';
import configureStore from 'redux-mock-store';

import FunnelSteps from './FunnelSteps';

jest.mock('uuid', () => {
return {
v4: jest.fn(() => 'id'),
};
});

const render = (storeState: any = {}) => {
const mockStore = configureStore([]);
const state = {
query: {
steps: [],
},
...storeState,
};

const store = mockStore({ ...state });

const wrapper = rtlRender(
<Provider store={store}>
<FunnelSteps />
</Provider>
);

return {
store,
wrapper,
};
};

test('allows user to add funnel step', () => {
const {
wrapper: { getByTestId },
store,
} = render();

const button = getByTestId('add-step-button');
fireEvent.click(button);

expect(store.getActions()).toMatchInlineSnapshot(`
Array [
Object {
"payload": Object {
"id": "id",
},
"type": "@query-creator/ADD_FUNNEL_STEP",
},
]
`);
});

test('resets funnel steps', () => {
const {
wrapper: { unmount },
store,
} = render();
unmount();

expect(store.getActions()).toMatchInlineSnapshot(`
Array [
Object {
"payload": Object {
"steps": Array [],
},
"type": "@query-creator/SET_FUNNEL_STEPS",
},
]
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import text from './text.json';
import FunnelStep from '../FunnelStep';
import {
addFunnelStep,
setFunnelSteps,
removeFunnelStep,
getFunnelSteps,
changeFunnelStepsOrder,
Expand Down Expand Up @@ -49,6 +50,10 @@ const FunnelSteps: FC<{}> = () => {
setDragMode(false);
},
});

return () => {
dispatch(setFunnelSteps([]));
};
}, []);

return (
Expand Down Expand Up @@ -94,6 +99,7 @@ const FunnelSteps: FC<{}> = () => {
)}
<AddStep
className="add-step"
data-testid="add-step-button"
onClick={() => {
const stepId = uuid();
dispatch(addFunnelStep(stepId));
Expand Down

0 comments on commit 8768ce4

Please sign in to comment.