Files
remark42/frontend/app/components/comment-form/comment-form.test.tsx
T
Pavel MineevandUmputun 93fd445bd4 On-demand auth
* auth block was moved to comment form
* if comments on page read only auth form shows in old place
* comment value in form will be saved between refreshes (it is side effect form saving comment value between unauth and auth states)
2020-03-12 15:44:31 -05:00

54 lines
1.7 KiB
TypeScript

/** @jsx createElement */
import { createElement } from 'preact';
import { shallow } from 'enzyme';
import { user } from '@app/testUtils/mocks/user';
import { StaticStore } from '@app/common/static_store';
import { CommentForm, Props } from './comment-form';
import { SubscribeByEmail } from './__subscribe-by-email';
const DEFAULT_PROPS: Readonly<Omit<Props, 'intl'>> = {
mode: 'main',
theme: 'light',
onSubmit: () => Promise.resolve(),
getPreview: () => Promise.resolve(''),
user: null,
id: '1',
};
const intl = {
formatMessage() {
return '';
},
} as any;
describe('<CommentForm />', () => {
it('should render without control panel, preview button, and rss links in "simple view" mode', () => {
const props = { ...DEFAULT_PROPS, simpleView: true, intl };
const wrapper = shallow(<CommentForm {...props} />);
expect(wrapper.exists('.comment-form__control-panel')).toEqual(false);
expect(wrapper.exists('.comment-form__button_type_preview')).toEqual(false);
expect(wrapper.exists('.comment-form__rss')).toEqual(false);
});
it('should be rendered with email subscription button', () => {
StaticStore.config.email_notifications = true;
const props = { ...DEFAULT_PROPS, user, intl };
const wrapper = shallow(<CommentForm {...props} />);
expect(wrapper.exists(SubscribeByEmail)).toEqual(true);
});
it('should be rendered without email subscription button when email_notifications disabled', () => {
StaticStore.config.email_notifications = false;
const props = { ...DEFAULT_PROPS, user, intl };
const wrapper = shallow(<CommentForm {...props} />);
expect(wrapper.exists(SubscribeByEmail)).toEqual(false);
});
});