2017-05-25 22:05:11 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { markupToReact } from 'translations/markup';
|
|
|
|
|
|
|
|
describe('markupToReact', () => {
|
|
|
|
it('passes plain string as is', () => {
|
|
|
|
const value = 'string';
|
|
|
|
const expected = 'string';
|
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('transforms bold syntax', () => {
|
|
|
|
let value = '**foo**';
|
2017-06-01 00:46:03 +00:00
|
|
|
let expected = [<b key="boldify-0">foo</b>];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = '**foo** bar';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = [<b key="boldify-0">foo</b>, ' bar'];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = 'bar **foo**';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = ['bar ', <b key="boldify-0">foo</b>];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = 'bar **foo** baz';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = ['bar ', <b key="boldify-0">foo</b>, ' baz'];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = '**foo****bar**';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = [<b key="boldify-0">foo</b>, <b key="boldify-1">bar</b>];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('transforms link syntax', () => {
|
|
|
|
let value = '[foo](http://google.com)';
|
2017-06-01 00:46:03 +00:00
|
|
|
let expected = [<a key="linkify-0" href="http://google.com" target="_blank">foo</a>];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = '[foo](http://google.com) bar';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = [<a key="linkify-0" href="http://google.com" target="_blank">foo</a>, ' bar'];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = 'bar [foo](http://google.com)';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = ['bar ', <a key="linkify-0" href="http://google.com" target="_blank">foo</a>];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = 'bar [foo](http://google.com) baz';
|
2017-06-01 00:46:03 +00:00
|
|
|
expected = ['bar ', <a key="linkify-0" href="http://google.com" target="_blank">foo</a>, ' baz'];
|
2017-05-25 22:05:11 +00:00
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
|
|
|
|
value = '[foo](http://google.com)[bar](http://google.ca)';
|
|
|
|
expected = [
|
2017-06-01 00:46:03 +00:00
|
|
|
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
|
|
|
<a key="linkify-1" href="http://google.ca" target="_blank">bar</a>
|
2017-05-25 22:05:11 +00:00
|
|
|
];
|
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts mixed syntax', () => {
|
|
|
|
let value = 'Bold **foo** link [foo](http://google.com) text';
|
|
|
|
let expected = [
|
|
|
|
'Bold ',
|
2017-06-01 00:46:03 +00:00
|
|
|
<b key="boldify-0">foo</b>,
|
2017-05-25 22:05:11 +00:00
|
|
|
' link ',
|
2017-06-01 00:46:03 +00:00
|
|
|
<a key="linkify-0" href="http://google.com" target="_blank">foo</a>,
|
2017-05-25 22:05:11 +00:00
|
|
|
' text'
|
|
|
|
];
|
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
});
|
2017-06-01 20:13:59 +00:00
|
|
|
|
|
|
|
it('converts html entities', () => {
|
|
|
|
let value = '&&';
|
|
|
|
let expected = '&&';
|
|
|
|
expect(markupToReact(value)).toEqual(expected);
|
|
|
|
})
|
2017-05-25 22:05:11 +00:00
|
|
|
});
|