Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-07-01 15:53:05 +0300
committerJulius Härtl <jus@bitgrid.net>2019-07-02 09:21:49 +0300
commitd85640fa6ffc6ffe277830580ab693e069ea088b (patch)
treeff4549a1e5bf691fccddb995a442d9863008bf46 /src/tests
parent9977abd62c377a4e65c9e5ee83a629c5f4cc82a1 (diff)
Allow plain text editing of files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/markdown.spec.js (renamed from src/tests/index.spec.js)0
-rw-r--r--src/tests/plaintext.spec.js78
2 files changed, 78 insertions, 0 deletions
diff --git a/src/tests/index.spec.js b/src/tests/markdown.spec.js
index b0d33e341..b0d33e341 100644
--- a/src/tests/index.spec.js
+++ b/src/tests/markdown.spec.js
diff --git a/src/tests/plaintext.spec.js b/src/tests/plaintext.spec.js
new file mode 100644
index 000000000..6b9b54a63
--- /dev/null
+++ b/src/tests/plaintext.spec.js
@@ -0,0 +1,78 @@
+import { markdownit, createEditor, createMarkdownSerializer, serializePlainText } from './../EditorFactory';
+import spec from "./fixtures/spec"
+
+const markdownToDocument = (markdown) => {
+ const tiptap = createEditor({
+ content: markdownit.render(markdown),
+ enableRichEditing: false
+ })
+ const serializer = createMarkdownSerializer(tiptap.nodes, tiptap.marks)
+ return tiptap.state.doc
+}
+
+const plaintextThroughEditor = (markdown) => {
+ const content = `<pre>${markdown}</pre>`
+ const tiptap = createEditor({
+ content: content,
+ enableRichEditing: false
+ })
+ return serializePlainText(tiptap) || ''
+}
+
+describe('Commonmark', () => {
+ beforeAll(() => {
+ // Make sure html tests pass
+ // entry.section === 'HTML blocks' || entry.section === 'Raw HTML'
+ markdownit.set({ html: true})
+ })
+ afterAll(() => {
+ markdownit.set({ html: false})
+ })
+
+ // failures because of some additional newline in markdownit
+ const skippedMarkdownTests = [
+ 181, 202, 203
+ ];
+
+ spec.forEach((entry) => {
+ if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
+ return
+ }
+ test('commonmark ' + entry.example, () => {
+ expect(markdownit.render(entry.markdown)).toBe(entry.html, entry)
+ })
+ })
+})
+
+describe('Markdown though editor', () => {
+ test('headlines', () => {
+ expect(plaintextThroughEditor('# Test')).toBe('# Test')
+ expect(plaintextThroughEditor('## Test')).toBe('## Test')
+ expect(plaintextThroughEditor('### Test')).toBe('### Test')
+ expect(plaintextThroughEditor('#### Test')).toBe('#### Test')
+ expect(plaintextThroughEditor('##### Test')).toBe('##### Test')
+ })
+ test('inline format', () => {
+ expect(plaintextThroughEditor('**Test**')).toBe('**Test**')
+ expect(plaintextThroughEditor('__Test__')).toBe('__Test__')
+ expect(plaintextThroughEditor('_Test_')).toBe('_Test_')
+ expect(plaintextThroughEditor('~~Test~~')).toBe('~~Test~~')
+ })
+ test('ul', () => {
+ expect(plaintextThroughEditor('- foo\n- bar')).toBe('- foo\n- bar')
+ expect(plaintextThroughEditor('- foo\n\n- bar')).toBe('- foo\n\n- bar')
+ expect(plaintextThroughEditor('- foo\n\n\n- bar')).toBe('- foo\n\n\n- bar')
+ })
+ test('ol', () => {
+ expect(plaintextThroughEditor('1. foo\n2. bar')).toBe('1. foo\n2. bar')
+ })
+ test('paragraph', () => {
+ expect(plaintextThroughEditor('foo\nbar\n\nfoobar\n\tfoobar')).toBe('foo\nbar\n\nfoobar\n\tfoobar')
+ })
+ test('links', () => {
+ expect(plaintextThroughEditor('[test](foo)')).toBe('[test](foo)')
+ })
+ test('images', () => {
+ expect(plaintextThroughEditor('![test](foo)')).toBe('![test](foo)')
+ })
+})