From 84e68b9bc8da29b18d6b45b769d675f50dbe949d Mon Sep 17 00:00:00 2001 From: Serge Adamovich Date: Mon, 20 Apr 2020 11:22:14 +0300 Subject: [PATCH] Check messages in tests --- .../app/components/comment-form/comment-form.test.tsx | 10 ++++++---- frontend/app/components/comment-form/comment-form.tsx | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/app/components/comment-form/comment-form.test.tsx b/frontend/app/components/comment-form/comment-form.test.tsx index 31ad5489..adb2d69b 100644 --- a/frontend/app/components/comment-form/comment-form.test.tsx +++ b/frontend/app/components/comment-form/comment-form.test.tsx @@ -7,7 +7,7 @@ import { StaticStore } from '@app/common/static_store'; import { LS_SAVED_COMMENT_VALUE } from '@app/common/constants'; import * as localStorageModule from '@app/common/local-storage'; -import { CommentForm, Props } from './comment-form'; +import { CommentForm, Props, messages } from './comment-form'; import { SubscribeByEmail } from './__subscribe-by-email'; import TextareaAutosize from './textarea-autosize'; @@ -29,8 +29,8 @@ const DEFAULT_PROPS: Readonly> = { }; const intl = { - formatMessage() { - return ''; + formatMessage(message: { defaultMessage: string }) { + return message.defaultMessage || ''; }, } as any; @@ -133,13 +133,14 @@ describe('', () => { }); it('should show error message of image upload try by anonymous user', () => { - const props = { ...DEFAULT_PROPS, anonymousUser, intl }; + const props = { ...DEFAULT_PROPS, user: anonymousUser, intl }; const wrapper = shallow(); // @ts-ignore const instance: CommentForm = wrapper.instance(); instance.onDrop(new Event('drag') as DragEvent); expect(wrapper.exists('.comment-form__error')).toEqual(true); + expect(wrapper.find('.comment-form__error').text()).toEqual(messages.anonymousUploadingDisabled.defaultMessage); }); it('should show error message of image upload try by unauthorized user', () => { @@ -150,5 +151,6 @@ describe('', () => { instance.onDrop(new Event('drag') as DragEvent); expect(wrapper.exists('.comment-form__error')).toEqual(true); + expect(wrapper.find('.comment-form__error').text()).toEqual(messages.unauthorizedUploadingDisabled.defaultMessage); }); }); diff --git a/frontend/app/components/comment-form/comment-form.tsx b/frontend/app/components/comment-form/comment-form.tsx index d8c1330b..a042e541 100644 --- a/frontend/app/components/comment-form/comment-form.tsx +++ b/frontend/app/components/comment-form/comment-form.tsx @@ -60,7 +60,7 @@ export interface State { const ImageMimeRegex = /image\//i; -const messages = defineMessages({ +export const messages = defineMessages({ placeholder: { id: 'commentForm.input-placeholder', defaultMessage: 'Your comment here',