-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.15] [Cases] Fix remark stringify version to match remark parse (#1…
…19995) (#120916) * [Cases] Fix remark stringify version to match remark parse (#119995) * match parse and stringify version. try/catch added * Adding tests and refactoring logError * Adding relative path to core and kibana utils * remark curstom serializers adapted to version 8 * add error logging to comments migration * Adding tests for mergeMigrationFunctionMap logging Co-authored-by: Jonathan Buttner <[email protected]> Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # package.json # x-pack/plugins/cases/common/utils/markdown_plugins/utils.test.ts # x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts # x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts # x-pack/plugins/cases/server/saved_object_types/migrations/user_actions.test.ts # x-pack/plugins/cases/server/saved_object_types/migrations/user_actions.ts # x-pack/plugins/cases/server/saved_object_types/migrations/utils.test.ts # x-pack/plugins/cases/server/saved_object_types/migrations/utils.ts # yarn.lock * Adding tests and fixing yarn lock * Using correct migration * fixing eslint issues * Removing redudent tests Co-authored-by: Sergi Massaneda <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
6d6f294
commit 24db901
Showing
12 changed files
with
843 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
x-pack/plugins/cases/common/utils/markdown_plugins/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { parseCommentString, stringifyComment } from './utils'; | ||
|
||
describe('markdown utils', () => { | ||
describe('stringifyComment', () => { | ||
it('adds a newline to the end if one does not exist', () => { | ||
const parsed = parseCommentString('hello'); | ||
expect(stringifyComment(parsed)).toEqual('hello\n'); | ||
}); | ||
|
||
it('does not add a newline to the end if one already exists', () => { | ||
const parsed = parseCommentString('hello\n'); | ||
expect(stringifyComment(parsed)).toEqual('hello\n'); | ||
}); | ||
|
||
// This check ensures the version of remark-stringify supports tables. From version 9+ this is not supported by default. | ||
it('parses and stringifies github formatted markdown correctly', () => { | ||
const parsed = parseCommentString(`| Tables | Are | Cool | | ||
|----------|:-------------:|------:| | ||
| col 1 is | left-aligned | $1600 | | ||
| col 2 is | centered | $12 | | ||
| col 3 is | right-aligned | $1 |`); | ||
|
||
expect(stringifyComment(parsed)).toMatchInlineSnapshot(` | ||
"| Tables | Are | Cool | | ||
| -------- | :-----------: | ----: | | ||
| col 1 is | left-aligned | $1600 | | ||
| col 2 is | centered | $12 | | ||
| col 3 is | right-aligned | $1 | | ||
" | ||
`); | ||
}); | ||
|
||
it('parses a timeline url', () => { | ||
const timelineUrl = | ||
'[asdasdasdasd](http://localhost:5601/moq/app/security/timelines?timeline=(id%3A%27e4362a60-f478-11eb-a4b0-ebefce184d8d%27%2CisOpen%3A!t))'; | ||
|
||
const parsedNodes = parseCommentString(timelineUrl); | ||
|
||
expect(parsedNodes).toMatchInlineSnapshot(` | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"match": "[asdasdasdasd](http://localhost:5601/moq/app/security/timelines?timeline=(id%3A%27e4362a60-f478-11eb-a4b0-ebefce184d8d%27%2CisOpen%3A!t))", | ||
"position": Position { | ||
"end": Object { | ||
"column": 138, | ||
"line": 1, | ||
"offset": 137, | ||
}, | ||
"indent": Array [], | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "timeline", | ||
}, | ||
], | ||
"position": Object { | ||
"end": Object { | ||
"column": 138, | ||
"line": 1, | ||
"offset": 137, | ||
}, | ||
"start": Object { | ||
"column": 1, | ||
"line": 1, | ||
"offset": 0, | ||
}, | ||
}, | ||
"type": "root", | ||
} | ||
`); | ||
}); | ||
|
||
it('stringifies a timeline url', () => { | ||
const timelineUrl = | ||
'[asdasdasdasd](http://localhost:5601/moq/app/security/timelines?timeline=(id%3A%27e4362a60-f478-11eb-a4b0-ebefce184d8d%27%2CisOpen%3A!t))'; | ||
|
||
const parsedNodes = parseCommentString(timelineUrl); | ||
|
||
expect(stringifyComment(parsedNodes)).toEqual(`${timelineUrl}\n`); | ||
}); | ||
|
||
it('parses a lens visualization', () => { | ||
const lensVisualization = | ||
'!{lens{"timeRange":{"from":"now-7d","to":"now","mode":"relative"},"attributes":{"title":"TEst22","type":"lens","visualizationType":"lnsMetric","state":{"datasourceStates":{"indexpattern":{"layers":{"layer1":{"columnOrder":["col2"],"columns":{"col2":{"dataType":"number","isBucketed":false,"label":"Count of records","operationType":"count","scale":"ratio","sourceField":"Records"}}}}}},"visualization":{"layerId":"layer1","accessor":"col2"},"query":{"language":"kuery","query":""},"filters":[]},"references":[{"type":"index-pattern","id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-current-indexpattern"},{"type":"index-pattern","id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-layer-layer1"}]}}}'; | ||
|
||
const parsedNodes = parseCommentString(lensVisualization); | ||
expect(parsedNodes.children[0].type).toEqual('lens'); | ||
}); | ||
|
||
it('stringifies a lens visualization', () => { | ||
const lensVisualization = | ||
'!{lens{"timeRange":{"from":"now-7d","to":"now","mode":"relative"},"attributes":{"title":"TEst22","type":"lens","visualizationType":"lnsMetric","state":{"datasourceStates":{"indexpattern":{"layers":{"layer1":{"columnOrder":["col2"],"columns":{"col2":{"dataType":"number","isBucketed":false,"label":"Count of records","operationType":"count","scale":"ratio","sourceField":"Records"}}}}}},"visualization":{"layerId":"layer1","accessor":"col2"},"query":{"language":"kuery","query":""},"filters":[]},"references":[{"type":"index-pattern","id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-current-indexpattern"},{"type":"index-pattern","id":"90943e30-9a47-11e8-b64d-95841ca0b247","name":"indexpattern-datasource-layer-layer1"}]}}}'; | ||
|
||
const parsedNodes = parseCommentString(lensVisualization); | ||
|
||
expect(stringifyComment(parsedNodes)).toEqual(`${lensVisualization}\n`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.