Files
remark42/frontend/app/components/comment-form/comment-form.test.tsx
T
Pavel MineevandUmputun 7d9e8ce076 UI for email subscription (#537)
* Add api methods for subscription

* Small changes

* little changes in remark.tsx
* disallow pass className to Button and Input

* Subscribe block

* add RSS and  Email subscription drobdowns
* add hook useTheme
* unify dropdown import/export

* Change API

* rename subscribe methods
* add unsubscribe method

* Add email subscription to settings and user

* Refactor and add new steps

* render by single component
* add final step
* add unsubscribe step it user is subscribed

* Add tests

* Update subscription logic

* test without mocking redux methods but with mocking store
* update user in store after subscribe and unsubscribe
* little changes in subscription flow

* fix drobdown size

* Fix RSS subscription link for site

* fix link
* add test for RSS subscription

* Fix showing email subscription

* it don't show to unauth users
* it don't show to anonymous users
* it tested
* isUserAnonymous is a bit rewrited
* isUserAnonymous is tested

* Make Email button visible for anon users

* React X supporst Fragments thats why .babelrc changed
* disabled button is more visible
* fix hovering on disabled buttons
* create mocks for tests
*  move email dropdown to __subscribe-by-email
2020-01-08 13:55:50 -06:00

47 lines
1.6 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<Props> = {
mode: 'main',
theme: 'light',
onSubmit: () => Promise.resolve(),
getPreview: () => Promise.resolve(''),
user: null,
};
describe('<CommentForm />', () => {
it('should render without control panel, preview button, and rss links in "simple view" mode', () => {
const props = { ...DEFAULT_PROPS, simpleView: true };
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 };
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 };
const wrapper = shallow(<CommentForm {...props} />);
expect(wrapper.exists(SubscribeByEmail)).toEqual(false);
});
});