diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index f0a8c4c4a..f95029786 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -33,8 +33,8 @@ export class PathHelper { if (!lastItem) { throw new Error(`Couldn't get the segments for ${path}`) } - // Match if last item is Root/content(123) or Root/Example('content') - const matches = lastItem.match(/(\('\w+'\)$)/g) + // Match if last item is Root/Example('content') + const matches = lastItem.match(/(\('.+'\)$)/g) if (!matches) { return [...splitted, lastItem] } @@ -44,11 +44,11 @@ export class PathHelper { } /** - * Checks if a specific segment is an Item segment or not (like "('Content1')" or "Test(1)") + * Checks if a specific segment is an Item segment or not (like "('Content1')") * @param segment The segment to be examined */ public static isItemSegment(segment: string): boolean { - return RegExp(/\('+[\s\S]+'\)$/).test(segment) || RegExp(/\(+\w+\d+\)$/).test(segment) + return RegExp(/\('.+'\)$/).test(segment) } /** diff --git a/packages/sn-client-utils/test/path-helper.test.ts b/packages/sn-client-utils/test/path-helper.test.ts index ee9a5f50b..50e91f806 100644 --- a/packages/sn-client-utils/test/path-helper.test.ts +++ b/packages/sn-client-utils/test/path-helper.test.ts @@ -9,10 +9,6 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.isItemSegment("('Item1')")).toBe(true) }) - it('Should return true for item segments with numeric key "(42)"', () => { - expect(PathHelper.isItemSegment('(42)')).toBe(true) - }) - it('Should return false for string keys w/o quotes', () => { expect(PathHelper.isItemSegment('(invalidValue)')).toBe(false) }) @@ -63,11 +59,6 @@ export const pathHelperTests = describe('PathHelper', () => { const isAnItem = PathHelper.isItemPath("/workspace/('project')/CustomAction") expect(isAnItem).toBe(true) }) - - it('should return true for reference paths with ids', () => { - const isAnItem = PathHelper.isItemPath('/workspaces/(22)/CustomAction') - expect(isAnItem).toBe(true) - }) }) describe('#getContentUrlbyId()', () => { @@ -202,6 +193,10 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.getParentPath('Root/Memo/Test(1)')).toBe('Root/Memo') }) + it('Should return the parent path in case of more than 1 segments with item path', () => { + expect(PathHelper.getParentPath('Root/Memo/Test (11)')).toBe('Root/Memo') + }) + it('Should return the path in case of 1 segments', () => { expect(PathHelper.getParentPath('Root')).toBe('Root') })