add update method
This commit is contained in:
@@ -13,9 +13,9 @@ export abstract class UmbFileSystemMockDbBase<T extends { path: string }> extend
|
||||
return this.data.find((item) => item.path === path);
|
||||
}
|
||||
|
||||
update(updateItem: T) {
|
||||
const itemIndex = this.data.findIndex((item) => item.path === updateItem.path);
|
||||
this.data[itemIndex] = updateItem;
|
||||
update(existingPath: string, updatedItem: T) {
|
||||
const itemIndex = this.data.findIndex((item) => item.path === existingPath);
|
||||
this.data[itemIndex] = updatedItem;
|
||||
}
|
||||
|
||||
delete(path: string) {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { UmbFileSystemMockDbBase } from './file-system-base.js';
|
||||
import { CreateTextFileViewModelBaseModel, ScriptResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { getParentPathFromServerPath } from './util/index.js';
|
||||
import {
|
||||
CreateTextFileViewModelBaseModel,
|
||||
ScriptResponseModel,
|
||||
UpdateTextFileViewModelBaseModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export interface UmbMockFileSystemDetailManagerArgs<MockItemType extends ScriptResponseModel> {
|
||||
createMapper: (item: CreateTextFileViewModelBaseModel) => MockItemType;
|
||||
@@ -30,6 +35,22 @@ export class UmbMockFileSystemDetailManager<MockItemType extends ScriptResponseM
|
||||
return mappedItem;
|
||||
}
|
||||
|
||||
update(item: UpdateTextFileViewModelBaseModel) {
|
||||
const mockItem = this.#db.read(item.existingPath);
|
||||
|
||||
const parentPath = getParentPathFromServerPath(item.existingPath);
|
||||
const newPath = parentPath ? parentPath + '/' + item.name : item.name;
|
||||
|
||||
const updatedMockItem = {
|
||||
...mockItem,
|
||||
name: item.name,
|
||||
content: item.content,
|
||||
path: newPath,
|
||||
} as MockItemType;
|
||||
|
||||
this.#db.update(item.existingPath, updatedMockItem);
|
||||
}
|
||||
|
||||
delete(path: string) {
|
||||
this.#db.delete(path);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from './parent-path-from-server-path.function.js';
|
||||
@@ -0,0 +1,15 @@
|
||||
import { expect } from '@open-wc/testing';
|
||||
import { getParentPathFromServerPath } from './parent-path-from-server-path.function.js';
|
||||
|
||||
describe('parent-path-from-server-path', () => {
|
||||
it('it returns the parent path of a nested server path', () => {
|
||||
const path = 'Folder A/Folder AA/Folder AAA';
|
||||
const expectedParentPath = 'Folder A/Folder AA';
|
||||
expect(getParentPathFromServerPath(path)).to.equal(expectedParentPath);
|
||||
});
|
||||
|
||||
it('it returns null of a root server path', () => {
|
||||
const path = 'Folder A';
|
||||
expect(getParentPathFromServerPath(path)).to.be.null;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
export const getParentPathFromServerPath = (serverPath: string): string | null => {
|
||||
const parentPath = serverPath.substring(0, serverPath.lastIndexOf('/'));
|
||||
return parentPath || null;
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { UmbMockFileSystemItemManager } from '../file-system/file-system-item.ma
|
||||
import { UmbMockFileSystemTreeManager } from '../file-system/file-system-tree.manager.js';
|
||||
import { UmbMockFileSystemDetailManager } from '../file-system/file-system-detail.manager.js';
|
||||
import { UmbMockScriptModel, data as scriptData } from './script.data.js';
|
||||
import { CreateTextFileViewModelBaseModel, ScriptResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { CreateScriptRequestModel, ScriptResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
class UmbScriptMockDB extends UmbFileSystemMockDbBase<UmbMockScriptModel> {
|
||||
tree = new UmbMockFileSystemTreeManager<UmbMockScriptModel>(this);
|
||||
@@ -21,7 +21,7 @@ class UmbScriptMockDB extends UmbFileSystemMockDbBase<UmbMockScriptModel> {
|
||||
});
|
||||
}
|
||||
|
||||
#createScriptMockItem = (item: CreateTextFileViewModelBaseModel): UmbMockScriptModel => {
|
||||
#createScriptMockItem = (item: CreateScriptRequestModel): UmbMockScriptModel => {
|
||||
return {
|
||||
name: item.name,
|
||||
content: item.content,
|
||||
|
||||
Reference in New Issue
Block a user