Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broken action on content name w parenthesis #1395

Merged
merged 7 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/sn-client-utils/src/path-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand All @@ -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)
}

/**
Expand Down
13 changes: 4 additions & 9 deletions packages/sn-client-utils/test/path-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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')
})
Expand Down