@kiwicom/smart-faq
Version:
73 lines (61 loc) • 2.11 kB
JavaScript
// @flow
import * as React from 'react';
import { mount, shallow } from 'enzyme';
import { Provider as LogProvider } from '@kiwicom/nitro/lib/services/log/context';
import { events } from '../../../../const/events';
import ScreenVoting from '../ScreenVoting';
import screenList from '../screenList';
jest.mock('../../../../SmartFAQ/mutations/VoteArticle');
const articleIds = {
valid: 23,
invalid: -59,
};
describe('ScreenVoting', () => {
it('should match snapshot', () => {
const changeScreen = jest.fn();
const component = shallow(
<ScreenVoting articleId={articleIds.valid} changeScreen={changeScreen} />,
);
expect(component).toMatchSnapshot();
});
it('[On Succesful Voting] should redirect to thank you screen and log the corresponding event', done => {
const log = jest.fn();
const changeScreen = jest.fn();
const wrapper = mount(
<LogProvider value={{ log }}>
<ScreenVoting
articleId={articleIds.valid}
changeScreen={changeScreen}
/>
</LogProvider>,
);
wrapper.find("[data-test='thumbUp']").simulate('click');
expect(log).toHaveBeenCalledWith(events.FAQ_VOTE_UP, {});
setImmediate(() => {
expect(changeScreen).toHaveBeenCalledWith(screenList.THANK_YOU);
wrapper.find("[data-test='thumbDown']").simulate('click');
expect(log).toHaveBeenCalledWith(events.FAQ_VOTE_DOWN, {});
done();
});
});
it('[On Error] should redirect to error screen and log error', done => {
const log = jest.fn();
const changeScreen = jest.fn();
const wrapper = mount(
<LogProvider value={{ log }}>
<ScreenVoting
articleId={articleIds.invalid}
changeScreen={changeScreen}
/>
</LogProvider>,
);
wrapper.find("[data-test='thumbUp']").simulate('click');
setImmediate(() => {
expect(changeScreen).toHaveBeenCalledWith(screenList.ERROR);
expect(log).toHaveBeenLastCalledWith(events.FAQ_VOTE_ERROR, {
error: Error('ArticleId should be a positive number'),
});
done();
});
});
});