From 5fc039f014821f508903d8207f9111f5a6069ed0 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 23 Jul 2021 12:06:13 +0500 Subject: [PATCH 1/5] #3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - стилистические правки функции cleanNumString --- ...um-string.test.js => clean-num-string.test.ts} | 0 src/common/helpers/clean-num-string.ts | 15 ++++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) rename src/common/helpers/__test__/{clean-num-string.test.js => clean-num-string.test.ts} (100%) diff --git a/src/common/helpers/__test__/clean-num-string.test.js b/src/common/helpers/__test__/clean-num-string.test.ts similarity index 100% rename from src/common/helpers/__test__/clean-num-string.test.js rename to src/common/helpers/__test__/clean-num-string.test.ts diff --git a/src/common/helpers/clean-num-string.ts b/src/common/helpers/clean-num-string.ts index d267adea..c3e5dd1b 100644 --- a/src/common/helpers/clean-num-string.ts +++ b/src/common/helpers/clean-num-string.ts @@ -1,12 +1,9 @@ -import pipe from 'lodash/fp/pipe'; -import toString from 'lodash/toString'; - /** * Очищает строку от любых символов, кроме цифр и удаляет лишние нули вначале. - * @param {string} str Строка. - * @return {string} Возвращает очищенную строку. + * @param value Строка. + * @return Возвращает очищенную строку. */ -export const cleanNumString = pipe( - str => toString(str) && str.replace(/[^0-9]/g, ''), - str => str === '' ? '' : Number(str).toString() -); +export const cleanNumString = (value: unknown): string => { + const string = String(value).replace(/\D/g, ''); + return string.length > 0 ? Number(string).toString() : ''; +}; From 14646b0cb6878c013706551eb4faf9da7180c1d0 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 23 Jul 2021 12:06:38 +0500 Subject: [PATCH 2/5] #3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - удален лишний JSDoc в ModifiersList --- src/mobile/components/modifiers-list/index.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mobile/components/modifiers-list/index.tsx b/src/mobile/components/modifiers-list/index.tsx index 27b32b87..4895b723 100644 --- a/src/mobile/components/modifiers-list/index.tsx +++ b/src/mobile/components/modifiers-list/index.tsx @@ -18,14 +18,14 @@ const cx = classnames.bind(classes); /** * Компонент списка модификаторов. - * @param {Object} props Свойства компонента. - * @param {Array} props.items Массив данных модификаторов. - * @param {string} props.currencyGrapheme Графема валюты пользователя. - * @param {string} props.sizesTableUrl Url таблицы размеров. - * @param {Object} props.wrapperProps Свойства блока-обертки. - * @param {Object} props.itemsContainerProps Свойства блока-обертки списка модификаторов. - * @param {Function} props.onItemClick Обработчик клика на модификатор. - * @return {ReactElement} Компонент списка модификаторов. + * @param props Свойства компонента. + * @param props.items Массив данных модификаторов. + * @param props.currencyGrapheme Графема валюты пользователя. + * @param props.sizesTableUrl Url таблицы размеров. + * @param props.wrapperProps Свойства блока-обертки. + * @param props.itemsContainerProps Свойства блока-обертки списка модификаторов. + * @param props.onItemClick Обработчик клика на модификатор. + * @return Компонент списка модификаторов. */ export const ModifiersList = ({ items, From c82a7d861a3dffee0c3533424deb638c0a5e6ec3 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 23 Jul 2021 12:07:14 +0500 Subject: [PATCH 3/5] #3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - исправлено имя пропа data-testid - обновлены снепшоты --- .../group/__test__/__snapshots__/index.test.jsx.snap | 2 +- src/desktop/components/modifiers/group/index.tsx | 4 ++-- .../widget/__test__/__snapshots__/index.test.tsx.snap | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/desktop/components/modifiers/group/__test__/__snapshots__/index.test.jsx.snap b/src/desktop/components/modifiers/group/__test__/__snapshots__/index.test.jsx.snap index a206ce21..c74de73c 100644 --- a/src/desktop/components/modifiers/group/__test__/__snapshots__/index.test.jsx.snap +++ b/src/desktop/components/modifiers/group/__test__/__snapshots__/index.test.jsx.snap @@ -3,7 +3,7 @@ exports[` should match snapshot 1`] = `
isMarkdown?: ModifierPredicate onClickShowAll?: () => void - 'data-tetsid'?: string + 'data-testid'?: string } const cx = classnames.bind(classes); @@ -190,7 +190,7 @@ export class ModifiersGroup extends Component { isSelectedItem = defaultIsSelectedItem, getItemImage = defaultGetItemImage, isMarkdown = defaultGetIsMarkdown, - 'data-tetsid': testId = 'data-tetsid', + 'data-testid': testId = 'modifiers-group', } = this.props; const { needShowAll, hasHiddenNodes, lastVisibleChildIndex } = this.state; diff --git a/src/desktop/components/modifiers/widget/__test__/__snapshots__/index.test.tsx.snap b/src/desktop/components/modifiers/widget/__test__/__snapshots__/index.test.tsx.snap index d9021a3b..f0c983bd 100644 --- a/src/desktop/components/modifiers/widget/__test__/__snapshots__/index.test.tsx.snap +++ b/src/desktop/components/modifiers/widget/__test__/__snapshots__/index.test.tsx.snap @@ -56,7 +56,7 @@ exports[` should renders correctly with prop 1`] = ` >
Date: Fri, 23 Jul 2021 12:11:40 +0500 Subject: [PATCH 4/5] #3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - добавлена возможность следить за событиями видео - добавлены тесты - добавлены stories --- .../__stories__/index.stories.tsx | 9 ++- .../__snapshots__/gallery-modal.test.tsx.snap | 3 + .../__test__/gallery-modal.test.tsx | 66 +++++++++++++++++++ .../components/gallery-modal.tsx | 29 +++++--- 4 files changed, 96 insertions(+), 11 deletions(-) diff --git a/src/desktop/components/gallery-modal/__stories__/index.stories.tsx b/src/desktop/components/gallery-modal/__stories__/index.stories.tsx index b682c568..3add0a11 100644 --- a/src/desktop/components/gallery-modal/__stories__/index.stories.tsx +++ b/src/desktop/components/gallery-modal/__stories__/index.stories.tsx @@ -17,7 +17,11 @@ export default { }; export const Primary = () => ( - + action('GalleryModal:video-event')(e.type)} + /> ); export const WithReview = () => ( @@ -28,6 +32,7 @@ export const WithReview = () => ( rating: 3.2, author: 'Пелагеевская Вероника Сергеевна', }} - onGoToReview={() => action('GalleryModal:go-to-review')} + onGoToReview={() => action('GalleryModal:go-to-review')()} + onVideoEvent={e => action('GalleryModal:video-event')(e.type)} /> ); diff --git a/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap b/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap index 61e5c013..b3fd9835 100644 --- a/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap +++ b/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap @@ -2752,6 +2752,9 @@ exports[`GalleryModal should renders with review footer 2`] = ` autoPlay={true} controls={true} controlsList="nodownload" + onEnded={[Function]} + onPause={[Function]} + onPlay={[Function]} > { expect(wrapper).toMatchSnapshot(); }); + it('should handle video events', () => { + const spy = jest.fn(); + + const wrapper = mount( + item.type === 'video')} + onVideoEvent={spy} + /> + ); + + expect(spy).toBeCalledTimes(0); + + // play + act(() => { + wrapper.find('video').simulate('play'); + }); + wrapper.update(); + + expect(spy).toBeCalledTimes(1); + expect(spy.mock.calls[0][0].type).toBe('play'); + + // pause + act(() => { + wrapper.find('video').simulate('pause'); + }); + wrapper.update(); + + expect(spy).toBeCalledTimes(2); + expect(spy.mock.calls[1][0].type).toBe('pause'); + + // ended + act(() => { + wrapper.find('video').simulate('ended'); + }); + wrapper.update(); + + expect(spy).toBeCalledTimes(3); + expect(spy.mock.calls[2][0].type).toBe('ended'); + }); + + it('should handle video events without callback', () => { + const wrapper = mount( + item.type === 'video')} + /> + ); + + // play + act(() => { + wrapper.find('video').simulate('play'); + }); + wrapper.update(); + + // pause + act(() => { + wrapper.find('video').simulate('pause'); + }); + wrapper.update(); + + // ended + act(() => { + wrapper.find('video').simulate('ended'); + }); + wrapper.update(); + }); + it('should renders with review footer', () => { const spy = jest.fn(); diff --git a/src/desktop/components/gallery-modal/components/gallery-modal.tsx b/src/desktop/components/gallery-modal/components/gallery-modal.tsx index fce3c74a..44f8aeea 100644 --- a/src/desktop/components/gallery-modal/components/gallery-modal.tsx +++ b/src/desktop/components/gallery-modal/components/gallery-modal.tsx @@ -23,6 +23,7 @@ export interface GalleryModalProps extends Pick void onClose?: () => void + onVideoEvent?: (event: React.SyntheticEvent) => void } interface InnerStyles extends React.CSSProperties { @@ -41,6 +42,7 @@ export const GalleryModal = ({ onMediaChange, withScrollDisable, scrollDisableOptions, + onVideoEvent, }: GalleryModalProps) => { const [currentIndex, setCurrent] = useState(defaultMediaIndex); @@ -101,7 +103,7 @@ export const GalleryModal = ({ {size !== null && (
- + {media.length > 1 && ( <> @@ -138,20 +140,29 @@ export const GalleryModal = ({ ); }; -const Media = (props: MediaData) => ( +const Media = ({ onVideoEvent, ...media }: MediaData & { + onVideoEvent?: (event: React.SyntheticEvent) => void +}) => (
- {props.type === 'image' && ( + {media.type === 'image' && ( - {props.data.alt + {media.data.alt )} - {props.type === 'video' && ( -
); From 58471bc8a2ff5dd5a66ad68f05683ae962ff6636 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 23 Jul 2021 12:49:49 +0500 Subject: [PATCH 5/5] #3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - код упрощен по комментариям --- .../__test__/__snapshots__/gallery-modal.test.tsx.snap | 3 --- .../components/gallery-modal/components/gallery-modal.tsx | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap b/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap index b3fd9835..61e5c013 100644 --- a/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap +++ b/src/desktop/components/gallery-modal/components/__test__/__snapshots__/gallery-modal.test.tsx.snap @@ -2752,9 +2752,6 @@ exports[`GalleryModal should renders with review footer 2`] = ` autoPlay={true} controls={true} controlsList="nodownload" - onEnded={[Function]} - onPause={[Function]} - onPlay={[Function]} > onVideoEvent?.(e)} - onPause={e => onVideoEvent?.(e)} - onEnded={e => onVideoEvent?.(e)} + onPlay={onVideoEvent} + onPause={onVideoEvent} + onEnded={onVideoEvent} >