Skip to content

Commit

Permalink
fix: expandable textarea should save on blur (openedx#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhou-bit committed May 4, 2023
1 parent 34d6fcc commit adc2173
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/editors/data/services/cms/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const processLicense = (licenseType, licenseDetails) => {

export const checkMockApi = (key) => {
if (process.env.REACT_APP_DEVGALLERY) {
return mockApi[key];
return mockApi[key] ? mockApi[key] : mockApi.emptyMock;
}
return module.apiMethods[key];
};
Expand Down
26 changes: 26 additions & 0 deletions src/editors/data/services/cms/api.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as utils from '../../../utils';
import * as api from './api';
import * as mockApi from './mockApi';
import * as urls from './urls';
import { get, post, deleteObject } from './utils';

Expand Down Expand Up @@ -547,6 +548,31 @@ describe('cms api', () => {
expect(api.processLicense(licenseType, licenseDetails)).toEqual('all-rights-reserved');
});
});
describe('checkMockApi', () => {
const envTemp = process.env;
beforeEach(() => {
jest.resetModules();
process.env = { ...envTemp };
});
afterEach(() => {
process.env = envTemp;
});
describe('if REACT_APP_DEVGALLERY is true', () => {
it('should return the mockApi version of a call when it exists', () => {
process.env.REACT_APP_DEVGALLERY = true;
expect(api.checkMockApi('fetchBlockById')).toEqual(mockApi.fetchBlockById);
});
it('should return an empty mock when the call does not exist', () => {
process.env.REACT_APP_DEVGALLERY = true;
expect(api.checkMockApi('someRAnDomThINg')).toEqual(mockApi.emptyMock);
});
});
describe('if REACT_APP_DEVGALLERY is not true', () => {
it('should return the appropriate call', () => {
expect(api.checkMockApi('fetchBlockById')).toEqual(apiMethods.fetchBlockById);
});
});
});
describe('fetchVideoFeatures', () => {
it('should call get with url.videoFeatures', () => {
const args = { studioEndpointUrl, learningContextId };
Expand Down
6 changes: 1 addition & 5 deletions src/editors/data/services/cms/mockApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,4 @@ export const fetchStudioView = ({ blockId, studioEndpointUrl }) => {
});
};

export const checkTranscriptsForImport = () => mockPromise({});

export const uploadTranscript = () => mockPromise({});

export const fetchAdvancedSettings = () => mockPromise({});
export const emptyMock = () => mockPromise({});
2 changes: 2 additions & 0 deletions src/editors/sharedComponents/TinyMceWidget/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export const setupCustomBehavior = ({
updateContent,
});
});
// TODO: consider using tinyMCE onblur for all react state updates
editor.on('blur', () => updateContent(editor.getContent()));
}
editor.on('ExecCommand', (e) => {
if (editorType === 'text' && e.command === 'mceFocus') {
Expand Down
3 changes: 2 additions & 1 deletion src/editors/sharedComponents/TinyMceWidget/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('TinyMceEditor hooks', () => {
const openSourceCodeModal = jest.fn();
const setImage = jest.fn();
const updateContent = jest.fn();
const editorType = 'SOmeEDitor';
const editorType = 'expandable';
const lmsEndpointUrl = 'sOmEvaLue.cOm';
const editor = {
ui: { registry: { addButton, addToggleButton, addIcon } },
Expand Down Expand Up @@ -88,6 +88,7 @@ describe('TinyMceEditor hooks', () => {
}],
]);
expect(openImgModal).not.toHaveBeenCalled();
expect(editor.on).toHaveBeenCalled();
});
});

Expand Down

0 comments on commit adc2173

Please sign in to comment.