Skip to content

Commit

Permalink
Added modal confirm/cancel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena committed Jan 13, 2019
1 parent 382e0a9 commit 6af9186
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions client/app/components/queries/ScheduleDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,69 @@ describe('ScheduleDialog', () => {
// should have changed to '1'
expect(wrapper.state('count')).toBe('1');
});

describe('Modal Confirm/Cancel feature', () => {
const confirmCb = jest.fn().mockName('confirmCb');
const closeCb = jest.fn().mockName('closeCb');
const initProps = { updateQuery: confirmCb, onClose: closeCb };

beforeEach(() => {
jest.clearAllMocks();
});

test('Query saved on confirm if state changed', () => {
// init
const [wrapper, props] = getWrapper(null, initProps);

// change state
const change = { time: '22:15' };
const newSchedule = Object.assign({}, props.schedule, change);
wrapper.setState({ newSchedule });

// click confirm button
wrapper
.find('.ant-modal-footer')
.find('.ant-btn-primary')
.simulate('click');

// expect calls
expect(confirmCb).toBeCalled();
expect(closeCb).toBeCalled();
});

test('Query not saved on confirm if state unchanged', () => {
// init
const [wrapper] = getWrapper(null, initProps);

// click confirm button
wrapper
.find('.ant-modal-footer')
.find('.ant-btn-primary')
.simulate('click');

// expect calls
expect(confirmCb).not.toBeCalled();
expect(closeCb).toBeCalled();
});

test('Cancel closes modal and query unsaved', () => {
// init
const [wrapper, props] = getWrapper(null, initProps);

// change state
const change = { time: '22:15' };
const newSchedule = Object.assign({}, props.schedule, change);
wrapper.setState({ newSchedule });

// click cancel button
wrapper
.find('.ant-modal-footer')
.find('button:not(.ant-btn-primary)')
.simulate('click');

// expect calls
expect(confirmCb).not.toBeCalled();
expect(closeCb).toBeCalled();
});
});
});

0 comments on commit 6af9186

Please sign in to comment.