Browse Source

Fix save restore

pull/6809/head
Artur Arseniev 2 months ago
parent
commit
324fcac490
  1. 13
      packages/core/src/editor/model/Editor.ts
  2. 26
      packages/core/test/specs/grapesjs/index.ts

13
packages/core/src/editor/model/Editor.ts

@ -909,11 +909,14 @@ export default class EditorModel extends Model {
this.clearDirtyCount();
}, 1);
const data = this.storeData();
await this.Storage.store(data, options);
setTimeout(() => {
this._isStoring = false;
}, 1);
return data;
try {
await this.Storage.store(data, options);
return data;
} finally {
setTimeout(() => {
this._isStoring = false;
}, 1);
}
}
/**

26
packages/core/test/specs/grapesjs/index.ts

@ -4,6 +4,7 @@ import ComponentWrapper from '../../../src/dom_components/model/ComponentWrapper
import { EditorConfig } from '../../../src/editor/config/config';
import PluginsEvents, { Plugin } from '../../../src/plugin_manager/types';
import { StorageManagerConfig } from '../../../src/storage_manager/config/config';
import { wait } from '../../../src/utils/mixins';
import { fixJsDom, fixJsDomIframe, waitEditorEvent } from '../../common';
type TestPlugin = Plugin<{ cVal: string }>;
@ -517,6 +518,31 @@ describe('GrapesJS', () => {
expect(data).toEqual(projectData);
});
test('Allows retrying store after a storage failure', async () => {
const store = jest
.fn()
.mockRejectedValueOnce(new Error('store failed'))
.mockResolvedValueOnce(undefined);
(config.storageManager as StorageManagerConfig).type = storageId;
config.plugins = [
(e) =>
e.StorageManager.add(storageId, {
store,
async load() {
return {};
},
}),
];
const editor = initTestEditor(config);
await expect(editor.store()).rejects.toThrow('store failed');
await wait(2);
await editor.store();
expect(store).toHaveBeenCalledTimes(2);
});
test('Adds a new storage and fetch correctly data from it', async () => {
fixture.innerHTML = documentEl;
const styleResult = { color: 'white', display: 'block' };

Loading…
Cancel
Save