Skip to content

Commit

Permalink
Trim text and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Sep 6, 2023
1 parent 4698d5a commit fa833c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/kbn-text-based-editor/src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('helpers', function () {
describe('getWrappedInPipesCode', function () {
it('should return the code wrapped', function () {
const code = getWrappedInPipesCode('FROM index1 | keep field1, field2 | order field1', false);
expect(code).toEqual('FROM index1 \n| keep field1, field2 \n| order field1');
expect(code).toEqual('FROM index1\n| keep field1, field2\n| order field1');
});

it('should return the code unwrapped', function () {
Expand All @@ -150,5 +150,13 @@ describe('helpers', function () {
);
expect(code).toEqual('FROM index1 | keep field1, field2 | order field1');
});

it('should return the code unwrapped and trimmed', function () {
const code = getWrappedInPipesCode(
'FROM index1 \n| keep field1, field2 \n| order field1',
true
);
expect(code).toEqual('FROM index1 | keep field1, field2 | order field1');
});
});
});
4 changes: 2 additions & 2 deletions packages/kbn-text-based-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const getInlineEditorText = (queryString: string, isMultiLine: boolean) =
export const getWrappedInPipesCode = (code: string, isWrapped: boolean): string => {
const pipes = code?.split('|');
const codeNoLines = pipes?.map((pipe) => {
return pipe.replaceAll('\n', '');
return pipe.replaceAll('\n', '').trim();
});
return codeNoLines.join(isWrapped ? '|' : '\n|');
return codeNoLines.join(isWrapped ? ' | ' : '\n| ');
};

0 comments on commit fa833c0

Please sign in to comment.