Skip to content

Commit

Permalink
Merge pull request #958 from codaco/fix/dialog-cancel-error
Browse files Browse the repository at this point in the history
correct typo in onCancel handler
  • Loading branch information
wwqrd authored Aug 22, 2019
2 parents 7442759 + b0ae081 commit 9c4439c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/ducks/modules/__tests__/dialogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,53 @@ describe('dialogs', () => {
});
});
});

describe('openDialog', () => {
let store;
const getDialog = () => ({
foo: 'bar',
onCancel: jest.fn(),
onConfirm: jest.fn(),
});

beforeEach(() => {
store = createStore(reducer, undefined, applyMiddleware(thunks));
});

it('Returns a promise', () => {
const dialog = getDialog();

expect.assertions(1);

expect(store.dispatch(actionCreators.openDialog(dialog))).toBeInstanceOf(Promise);
});

it('Promise resolves to `false` when onCancel is called', () => {
const dialog = getDialog();

expect.assertions(1);

const subject = expect(store.dispatch(actionCreators.openDialog(dialog)))
.resolves.toBe(false);

const state = store.getState();
state.dialogs[0].onCancel();

return subject;
});

it('Promise resolves to `true` when onConfirm is called', () => {
const dialog = getDialog();

expect.assertions(1);

const subject = expect(store.dispatch(actionCreators.openDialog(dialog)))
.resolves.toBe(true);

const state = store.getState();
state.dialogs[0].onConfirm();

return subject;
});
});
});
2 changes: 1 addition & 1 deletion src/ducks/modules/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const openDialog = dialog =>
};

const onCancel = () => {
if (dialog.onConfirm) { dialog.onCancel(); }
if (dialog.onCancel) { dialog.onCancel(); }
resolve(false);
};

Expand Down

0 comments on commit 9c4439c

Please sign in to comment.