From 09bb1dab2b43634e9b1d518a4b37a4e20d9e85c2 Mon Sep 17 00:00:00 2001 From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:54:07 -0500 Subject: [PATCH] feat: add import transcripts from youtube (#176) --- .../LicenseWidget/LicenseDisplay.jsx | 2 +- .../TranscriptWidget/ImportTranscriptCard.jsx | 60 ++++++++++ .../ImportTranscriptCard.test.jsx | 57 ++++++++++ .../ImportTranscriptCard.test.jsx.snap | 40 +++++++ .../__snapshots__/index.test.jsx.snap | 104 +++++++++++++++--- .../components/TranscriptWidget/index.jsx | 19 +++- .../TranscriptWidget/index.test.jsx | 13 ++- .../components/TranscriptWidget/messages.js | 15 +++ src/editors/data/constants/requests.js | 2 + src/editors/data/redux/requests/reducer.js | 3 +- .../data/redux/thunkActions/requests.js | 27 +++++ .../data/redux/thunkActions/requests.test.js | 48 +++++++- src/editors/data/redux/thunkActions/video.js | 40 +++++++ .../data/redux/thunkActions/video.test.js | 43 +++++++- src/editors/data/redux/video/reducer.js | 1 + src/editors/data/redux/video/selectors.js | 1 + src/editors/data/services/cms/api.js | 27 +++++ src/editors/data/services/cms/api.test.js | 28 +++++ src/editors/data/services/cms/mockApi.js | 12 ++ .../data/services/cms/mockVideoData.js | 2 - src/editors/data/services/cms/urls.js | 8 ++ src/editors/data/services/cms/urls.test.js | 16 +++ 22 files changed, 531 insertions(+), 37 deletions(-) create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.jsx create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.test.jsx create mode 100644 src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/ImportTranscriptCard.test.jsx.snap diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx index 2cf92a661..735f381b0 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/LicenseWidget/LicenseDisplay.jsx @@ -50,7 +50,7 @@ LicenseDisplay.propTypes = { shareAlike: PropTypes.bool.isRequired, }).isRequired, level: PropTypes.string.isRequired, - licenseDescription: PropTypes.func.isRequired, + licenseDescription: PropTypes.string.isRequired, }; export default injectIntl(LicenseDisplay); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.jsx new file mode 100644 index 000000000..7ad8dcffa --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.jsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; + +import { FormattedMessage, injectIntl } from '@edx/frontend-platform/i18n'; +import { + ActionRow, + Button, + Icon, + IconButton, + Stack, +} from '@edx/paragon'; +import { Close } from '@edx/paragon/icons'; + +import messages from './messages'; +import { thunkActions } from '../../../../../../data/redux'; + +export const ImportTranscriptCard = ({ + setOpen, + // redux + importTranscript, +}) => ( + + + + + setOpen(false)} + /> + + + + +); + +ImportTranscriptCard.defaultProps = { + setOpen: true, +}; + +ImportTranscriptCard.propTypes = { + setOpen: PropTypes.func, + // redux + importTranscript: PropTypes.func.isRequired, +}; + +export const mapStateToProps = () => ({}); + +export const mapDispatchToProps = { + importTranscript: thunkActions.video.importTranscript, +}; + +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ImportTranscriptCard)); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.test.jsx b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.test.jsx new file mode 100644 index 000000000..abc7165ef --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/ImportTranscriptCard.test.jsx @@ -0,0 +1,57 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { Button, IconButton } from '@edx/paragon'; + +import { thunkActions } from '../../../../../../data/redux'; +import * as module from './ImportTranscriptCard'; + +jest.mock('react', () => ({ + ...jest.requireActual('react'), + useContext: jest.fn(() => ({ transcripts: ['error.transcripts', jest.fn().mockName('error.setTranscripts')] })), +})); + +jest.mock('../../../../../../data/redux', () => ({ + thunkActions: { + video: { + importTranscript: jest.fn().mockName('thunkActions.video.importTranscript'), + }, + }, +})); + +describe('ImportTranscriptCard', () => { + const props = { + setOpen: jest.fn().mockName('setOpen'), + importTranscript: jest.fn().mockName('args.importTranscript'), + }; + let el; + describe('snapshots', () => { + test('snapshots: renders as expected with default props', () => { + expect( + shallow(), + ).toMatchSnapshot(); + }); + }); + describe('behavior inspection', () => { + beforeEach(() => { + el = shallow(); + }); + test('close behavior is linked to IconButton', () => { + expect(el.find(IconButton) + .props().onClick).toBeDefined(); + }); + test('import behavior is linked to Button onClick', () => { + expect(el.find(Button) + .props().onClick).toEqual(props.importTranscript); + }); + }); + describe('mapStateToProps', () => { + it('returns an empty object', () => { + expect(module.mapStateToProps()).toEqual({}); + }); + }); + describe('mapDispatchToProps', () => { + test('updateField from thunkActions.video.importTranscript', () => { + expect(module.mapDispatchToProps.importTranscript).toEqual(thunkActions.video.importTranscript); + }); + }); +}); diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/ImportTranscriptCard.test.jsx.snap b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/ImportTranscriptCard.test.jsx.snap new file mode 100644 index 000000000..e71ea14cb --- /dev/null +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/ImportTranscriptCard.test.jsx.snap @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ImportTranscriptCard snapshots snapshots: renders as expected with default props 1`] = ` + + + + + + + + + +`; diff --git a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/index.test.jsx.snap b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/index.test.jsx.snap index a03d9e42e..2c18443df 100644 --- a/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/index.test.jsx.snap +++ b/src/editors/containers/VideoEditor/components/VideoSettingsModal/components/TranscriptWidget/__snapshots__/index.test.jsx.snap @@ -30,9 +30,11 @@ exports[`TranscriptWidget component snapshots snapshot: renders ErrorAlert with /> - +
+
+
+ +`; + +exports[`TranscriptWidget component snapshots snapshots: renders as expected with allowTranscriptImport true 1`] = ` + + + + + + + + + + +