forked from Automattic/simplenote-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove markdown in preview without triggering bug (Automattic#1088)
- Loading branch information
Showing
4 changed files
with
75 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import noteTitleAndPreview, { defaults } from './note-utils'; | ||
|
||
describe('noteTitleAndPreview', () => { | ||
let note; | ||
|
||
beforeEach(() => { | ||
note = { | ||
data: { | ||
content: '', | ||
systemTags: ['markdown'], | ||
}, | ||
}; | ||
}); | ||
|
||
it('should return default values if note content is empty', () => { | ||
const result = noteTitleAndPreview(note); | ||
expect(result).toEqual(defaults); | ||
}); | ||
|
||
it('should return the title and preview when note is not Markdown', () => { | ||
note.data.content = 'My title\nThe preview'; | ||
note.data.systemTags = []; | ||
const result = noteTitleAndPreview(note); | ||
expect(result).toEqual({ | ||
title: 'My title', | ||
preview: 'The preview', | ||
}); | ||
}); | ||
|
||
it('should return the title and preview with Markdown removed when note is Markdown', () => { | ||
note.data.content = '# My title\nThe [preview](https://test.com)'; | ||
const result = noteTitleAndPreview(note); | ||
expect(result).toEqual({ | ||
title: 'My title', | ||
preview: 'The preview', | ||
}); | ||
}); | ||
|
||
// Test that it doesn't trigger the bug in `remove-markdown` | ||
// See https://github.com/stiang/remove-markdown/issues/35 | ||
it('should complete in a reasonable amount of time', () => { | ||
const bugInducingString = | ||
'# aaa bbb'; | ||
note.data.content = bugInducingString + '\n' + bugInducingString; | ||
const startTime = Date.now(); | ||
noteTitleAndPreview(note); | ||
const elapsedMs = Date.now() - startTime; | ||
expect(elapsedMs).toBeLessThanOrEqual(1); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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