fix(backend-test): delete nested file path (#2930)
This commit is contained in:
parent
45a6ee92cc
commit
b0fba6dc9a
@ -157,4 +157,48 @@ describe('test backend implementation', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteFile', () => {
|
||||
it('should delete entry by path', async () => {
|
||||
window.repoFiles = {
|
||||
posts: {
|
||||
'some-post.md': {
|
||||
content: 'post content',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const backend = new TestBackend();
|
||||
|
||||
await backend.deleteFile('posts/some-post.md');
|
||||
expect(window.repoFiles).toEqual({
|
||||
posts: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete entry by nested path', async () => {
|
||||
window.repoFiles = {
|
||||
posts: {
|
||||
dir1: {
|
||||
dir2: {
|
||||
'some-post.md': {
|
||||
content: 'post content',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const backend = new TestBackend();
|
||||
|
||||
await backend.deleteFile('posts/dir1/dir2/some-post.md');
|
||||
expect(window.repoFiles).toEqual({
|
||||
posts: {
|
||||
dir1: {
|
||||
dir2: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { attempt, isError, take } from 'lodash';
|
||||
import { attempt, isError, take, unset } from 'lodash';
|
||||
import uuid from 'uuid/v4';
|
||||
import { EditorialWorkflowError, Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util';
|
||||
import AuthenticationPage from './AuthenticationPage';
|
||||
@ -255,9 +255,7 @@ export default class TestBackend {
|
||||
if (assetIndex > -1) {
|
||||
this.assets.splice(assetIndex, 1);
|
||||
} else {
|
||||
const folder = path.substring(0, path.lastIndexOf('/'));
|
||||
const fileName = path.substring(path.lastIndexOf('/') + 1);
|
||||
delete window.repoFiles[folder][fileName];
|
||||
unset(window.repoFiles, path.split('/'));
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
|
Loading…
x
Reference in New Issue
Block a user