This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
link.js
166 lines (128 loc) · 6.85 KB
/
link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* globals document */
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Link from '@ckeditor/ckeditor5-link/src/link';
import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { expectPaste } from '../_utils/utils';
import withinText from '../data/integration/link/within-text/input.word2016.html';
import combined from '../data/integration/link/combined/input.word2016.html';
import twoLine from '../data/integration/link/two-line/input.word2016.html';
describe( 'Link – integration', () => {
let element, editor;
before( () => {
element = document.createElement( 'div' );
document.body.appendChild( element );
return ClassicTestEditor
.create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter ] } )
.then( editorInstance => {
editor = editorInstance;
} );
} );
beforeEach( () => {
setData( editor.model, '<paragraph>[]</paragraph>' );
} );
after( () => {
editor.destroy();
element.remove();
} );
// Pastes: 'Regular <a href="https://ckeditor.com/">link</a>1'
// Input same for: Chrome, Firefox and Edge.
describe( 'within text', () => {
it( 'pastes in the empty editor', () => {
expectPaste( editor, withinText, '<paragraph>Regular ' +
'<$text linkHref="https://ckeditor.com/">link</$text>1[]</paragraph>' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, '<paragraph>More [] text</paragraph>' );
expectPaste( editor, withinText, '<paragraph>More Regular ' +
'<$text linkHref="https://ckeditor.com/">link</$text>1[] text</paragraph>' );
} );
it( 'pastes in the different block context', () => {
setData( editor.model, '<heading1>More [] text</heading1>' );
expectPaste( editor, withinText, '<heading1>More Regular ' +
'<$text linkHref="https://ckeditor.com/">link</$text>1[] text</heading1>' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
expectPaste( editor, withinText, '<paragraph><$text bold="true">Bo</$text>' +
'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text bold="true">ld</$text></paragraph>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
expectPaste( editor, withinText, '<paragraph>1<$text linkHref="#test">tes</$text>' +
'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text linkHref="#test">t</$text>2</paragraph>' );
} );
} );
// Pastes: '<a href="https://ckeditor.com/">CKEditor</a><a href="https://cksource.com/">CKSource</a> 2'
// Input same for: Chrome, Firefox and Edge.
describe( 'combined', () => {
it( 'pastes in the empty editor', () => {
expectPaste( editor, combined, '<paragraph><$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]</paragraph>' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, '<paragraph>More [] text</paragraph>' );
expectPaste( editor, combined, '<paragraph>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
'<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</paragraph>' );
} );
it( 'pastes in the different block context', () => {
setData( editor.model, '<heading1>More [] text</heading1>' );
expectPaste( editor, combined, '<heading1>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
'<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</heading1>' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
expectPaste( editor, combined, '<paragraph><$text bold="true">Bo</$text>' +
'<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
'<$text bold="true">ld</$text></paragraph>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
expectPaste( editor, combined, '<paragraph>1<$text linkHref="#test">tes</$text>' +
'<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
'<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
'<$text linkHref="#test">t</$text>2</paragraph>' );
} );
} );
// Pastes: '<a href="https://cksource.com/">Long link <br> WITH spaces</a>'
// Input same for: Chrome, Firefox and Edge.
describe( 'two line', () => {
it( 'pastes in the empty editor', () => {
expectPaste( editor, twoLine, '<paragraph><$text linkHref="https://cksource.com/">Long link </$text><softBreak></softBreak>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]</$text></paragraph>' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, '<paragraph>More [] text</paragraph>' );
expectPaste( editor, twoLine, '<paragraph>More <$text linkHref="https://cksource.com/">Long link </$text>' +
'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</paragraph>' );
} );
it( 'pastes in the different block context', () => {
setData( editor.model, '<heading1>More [] text</heading1>' );
expectPaste( editor, twoLine, '<heading1>More <$text linkHref="https://cksource.com/">Long link </$text>' +
'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</heading1>' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
expectPaste( editor, twoLine, '<paragraph><$text bold="true">Bo</$text>' +
'<$text linkHref="https://cksource.com/">Long link </$text>' +
'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
'<$text bold="true">ld</$text></paragraph>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
expectPaste( editor, twoLine, '<paragraph>1<$text linkHref="#test">tes</$text>' +
'<$text linkHref="https://cksource.com/">Long link </$text>' +
'<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
'<$text linkHref="#test">t</$text>2</paragraph>' );
} );
} );
} );