/* tslint:disable:trailing-comma */
/* tslint:disable:max-line-length */
/* tslint:disable:whitespace */
/* eslint-disable max-len, quotes, quote-props, key-spacing, comma-spacing, comma-dangle, indent */
import * as testUtils from '../../components/tests/utils';
import {AtomicBlockParser} from '../to-html';
import {ContentState, convertToRaw, convertFromRaw} from 'draft-js';
import {getInitialContent} from 'core/editor3/store';
import {editor3StateToHtml} from '../to-html/editor3StateToHtml';
describe('core.editor3.html.to-html snapshots', () => {
it('converts a sentence without formatting', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds".
'
);
});
it('converts a sentence with simple inline styles', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":3,"style":"BOLD"},{"offset":4,"length":4,"style":"ITALIC"},{"offset":9,"length":2,"style":"UNDERLINE"},{"offset":12,"length":8,"style":"STRIKETHROUGH"},{"offset":21,"length":5,"style":"SUBSCRIPT"},{"offset":27,"length":4,"style":"SUPERSCRIPT"}],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
ThenameofHighlawscomesfrom the Old English hēah-hlāw, meaning "high mounds".
'
);
});
it('converts headings', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw","type":"header-one","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"32mrs","text":", meaning \"high mounds\". In the past,","type":"header-two","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"d2ggv","text":"variant spellings included Heelawes, Hielawes,","type":"header-three","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"3eqv5","text":"Highlows, Hielows, and Hylaws.","type":"header-four","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"8lcpm","text":"[2] The hamlet appears in a survey of Holm Cultram dating back","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"emuqc","text":"to the year 1538, during the reign of Henry VIII.","type":"header-six","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"90o9n","text":"There were at least thirteen families resident in Highlaws at that time.[3] Abdastartus is a genus of lace bugs in the family Tingidae. There are about five described species in Abdastartus.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of Highlaws comes from the Old English hēah-hlāw
, meaning "high mounds". In the past,
variant spellings included Heelawes, Hielawes,
Highlows, Hielows, and Hylaws.
[2] The hamlet appears in a survey of Holm Cultram dating back
to the year 1538, during the reign of Henry VIII.
There were at least thirteen families resident in Highlaws at that time.[3] Abdastartus is a genus of lace bugs in the family Tingidae. There are about five described species in Abdastartus.
`
);
});
it('converts a blockquote', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"blockquote","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"2u79k","text":"In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds".
In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.
`
);
});
it('converts a code block', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"2u79k","text":"In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds".
In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.
`
);
});
it('converts a link', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":12,"length":8,"key":0}],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{"0":{"type":"LINK","mutability":"MUTABLE","data":{"link":{"href":"https://en.wikipedia.org/wiki/Highlaws"}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds".
'
);
});
it('converts a simple table', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"fhokc","text":" ","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":0}],"data":{"data":"{\"cells\":[[{\"blocks\":[{\"key\":\"k8sb\",\"text\":\"three\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"a25i9\",\"text\":\"column\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"ej3lv\",\"text\":\"table\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}],[{\"blocks\":[{\"key\":\"f0qc0\",\"text\":\"example\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"50s2o\",\"text\":\"right\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"escgd\",\"text\":\"here\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}]],\"numRows\":2,\"numCols\":3,\"withHeader\":false}"}},{"key":"2u79k","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{"0":{"type":"TABLE","mutability":"MUTABLE","data":{"data":{"cells":[[{"blocks":[{"key":"k8sb","text":"three","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"a25i9","text":"column","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"ej3lv","text":"table","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}}],[{"blocks":[{"key":"f0qc0","text":"example","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"50s2o","text":"right","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"escgd","text":"here","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}}]],"numRows":2,"numCols":3,"withHeader":false}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
three
column
table
example
right
here
'
);
});
it('converts a table with inline styles', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"fhokc","text":" ","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":0}],"data":{"data":"{\"cells\":[[{\"blocks\":[{\"key\":\"k8sb\",\"text\":\"three\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"BOLD\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"a25i9\",\"text\":\"column\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":6,\"style\":\"ITALIC\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"ej3lv\",\"text\":\"table\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"UNDERLINE\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}],[{\"blocks\":[{\"key\":\"f0qc0\",\"text\":\"example\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":7,\"style\":\"SUBSCRIPT\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"50s2o\",\"text\":\"right\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":5,\"style\":\"SUPERSCRIPT\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}},{\"blocks\":[{\"key\":\"escgd\",\"text\":\"here\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":0,\"length\":4,\"style\":\"STRIKETHROUGH\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}]],\"numRows\":2,\"numCols\":3,\"withHeader\":false}"}},{"key":"2u79k","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{"0":{"type":"TABLE","mutability":"MUTABLE","data":{"data":{"cells":[[{"blocks":[{"key":"k8sb","text":"three","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":5,"style":"BOLD"}],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"a25i9","text":"column","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":6,"style":"ITALIC"}],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"ej3lv","text":"table","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":5,"style":"UNDERLINE"}],"entityRanges":[],"data":{}}],"entityMap":{}}],[{"blocks":[{"key":"f0qc0","text":"example","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":7,"style":"SUBSCRIPT"}],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"50s2o","text":"right","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":5,"style":"SUPERSCRIPT"}],"entityRanges":[],"data":{}}],"entityMap":{}},{"blocks":[{"key":"escgd","text":"here","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":4,"style":"STRIKETHROUGH"}],"entityRanges":[],"data":{}}],"entityMap":{}}]],"numRows":2,"numCols":3,"withHeader":false}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
three
column
table
example
right
here
'
);
});
it('converts an image', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"fi1d","text":" ","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":0}],"data":{}},{"key":"60vvd","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{"0":{"type":"MEDIA","mutability":"MUTABLE","data":{"media":{"flags":{"marked_for_not_publication":false,"marked_for_sms":false,"marked_archived_only":false,"marked_for_legal":false},"language":"en","_updated":"2019-03-28T17:26:54+0000","description_text":"pin dec","source":"Superdesk","type":"picture","priority":6,"_current_version":2,"versioncreated":"2019-03-28T17:26:54+0000","task":{"stage":"5c374805149f116db6aae6ad","user":"5acb79292e03ed5d2a84bbd6","desk":"5c374805149f116db6aae6af"},"urgency":3,"alt_text":"pin alt","_created":"2019-03-28T17:26:53+0000","genre":[{"name":"Article (news)","qcode":"Article"}],"guid":"tag:localhost:5000:2019:9df37ab0-4d96-4f95-8da5-06b744ef8604","renditions":{"baseImage":{"width":933,"mimetype":"image/jpeg","href":"http://localhost:5000/api/upload-raw/5c9d03de149f116747b67317.jpg","media":"5c9d03de149f116747b67317","height":1400},"thumbnail":{"width":79,"mimetype":"image/jpeg","href":"http://localhost:5000/api/upload-raw/5c9d03de149f116747b67319.jpg","media":"5c9d03de149f116747b67319","height":120},"viewImage":{"width":426,"mimetype":"image/jpeg","href":"http://localhost:5000/api/upload-raw/5c9d03de149f116747b6731b.jpg","media":"5c9d03de149f116747b6731b","height":640},"original":{"width":3648,"mimetype":"image/jpeg","href":"http://localhost:5000/api/upload-raw/5c9d03dd149f116747b6730f.jpg","media":"5c9d03dd149f116747b6730f","height":5472}},"state":"in_progress","expiry":null,"byline":null,"headline":"A picture of pineapple","_etag":"a2c443900319548148e9073b9c5cc4c76c9331c5","_id":"urn:newsml:localhost:5000:2019-03-28T18:26:53.805271:f47e37fd-a6bd-4a5e-b91d-01b581f04e8c","_type":"archive","_links":{"self":{"title":"Archive","href":"archive/urn:newsml:localhost:5000:2019-03-28T18:26:53.805271:f47e37fd-a6bd-4a5e-b91d-01b581f04e8c"}},"_latest_version":2,"selected":false}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
pin dec
`
);
});
it('converts unordered list', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"fgkp6","text":"Highlaws comes","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"6g9h6","text":"from the Old English","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"7v7b1","text":"hēah-hlāw","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of
Highlaws comes
from the Old English
hēah-hlāw
`
);
});
it('converts an ordered list', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"fgkp6","text":"Highlaws comes","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"6g9h6","text":"from the Old English","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"7v7b1","text":"hēah-hlāw","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of
Highlaws comes
from the Old English
hēah-hlāw
`
);
});
it('converts two different lists next to each other', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}},{"key":"6oe0d","text":"hēah-hlāw, meaning \"high mounds\". In the past, variant","type":"unordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"aegg","text":"spellings included Heelawes, Hielawes, Highlows,","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"a1qv7","text":"Hielows, and Hylaws.","type":"ordered-list-item","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
`
The name of Highlaws comes from the Old English
hēah-hlāw, meaning "high mounds". In the past, variant
'
);
}));
it('converts nested inline styles', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":4,"length":43,"style":"BOLD"},{"offset":21,"length":5,"style":"UNDERLINE"},{"offset":32,"length":3,"style":"ITALIC"}],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.
'
);
});
it('converts overlapping inline styles', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":66,"style":"BOLD"},{"offset":4,"length":89,"style":"ITALIC"},{"offset":27,"length":142,"style":"UNDERLINE"},{"offset":165,"length":5,"style":"SUPERSCRIPT"}],"entityRanges":[],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.
'
);
});
it('converts inline styles overlapping with a links', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":12,"length":14,"style":"BOLD"},{"offset":55,"length":6,"style":"BOLD"},{"offset":48,"length":18,"style":"UNDERLINE"}],"entityRanges":[{"offset":21,"length":10,"key":0},{"offset":36,"length":21,"key":1}],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{"0":{"type":"LINK","mutability":"MUTABLE","data":{"link":{"href":"https://en.wikipedia.org/wiki/Highlaws"}}},"1":{"type":"LINK","mutability":"MUTABLE","data":{"link":{"href":"https://en.wikipedia.org/wiki/Highlaws"}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds". In the past, variant spellings included Heelawes, Hielawes, Highlows, Hielows, and Hylaws.
'
);
});
it('converts an attachement', () => {
const rawContentState: any = {"blocks":[{"key":"fcbn3","text":"The name of Highlaws comes from the Old English hēah-hlāw, meaning \"high mounds\".","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":12,"length":8,"key":0}],"data":{"MULTIPLE_HIGHLIGHTS":{}}}],"entityMap":{"0":{"type":"LINK","mutability":"MUTABLE","data":{"link":{"attachment":"5c9dd26d149f114c61d84db0"}}}}};
expect(editor3StateToHtml(convertFromRaw(rawContentState))).toBe(
'
The name of Highlaws comes from the Old English hēah-hlāw, meaning "high mounds".