fix: expandable textarea should save on blur (#325)

This commit is contained in:
Raymond Zhou
2023-05-04 14:17:14 -07:00
committed by GitHub
parent 34d6fcc552
commit adc21735fc
5 changed files with 32 additions and 7 deletions

View File

@@ -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];
};

View File

@@ -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';
@@ -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 };

View File

@@ -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({});

View File

@@ -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') {

View File

@@ -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 } },
@@ -88,6 +88,7 @@ describe('TinyMceEditor hooks', () => {
}],
]);
expect(openImgModal).not.toHaveBeenCalled();
expect(editor.on).toHaveBeenCalled();
});
});