cirandas.net

ref: master

public/javascripts/tinymce/tests/plugins/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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
(function() {

	var nonRelativeRegex = /^\w+:/i;

	module("tinymce.plugins.Link", {
		setupModule: function() {
			QUnit.stop();

			tinymce.init({
				selector: 'textarea',
				add_unload_trigger: false,
				skin: false,
				indent: false,
				plugins: "link",
				init_instance_callback: function(ed) {
					window.editor = ed;
					QUnit.start();
				}
			});
		},

		teardown: function() {
			delete editor.settings.file_browser_callback;
			delete editor.settings.link_list;
			delete editor.settings.link_class_list;
			delete editor.settings.link_target_list;
			delete editor.settings.rel_list;

			var win = Utils.getFrontmostWindow();

			if (win) {
				win.close();
			}
		}
	});

	function cleanHtml(html) {
		return Utils.cleanHtml(html).replace(/<p>(&nbsp;|<br[^>]+>)<\/p>$/, '');
	}

	function fillAndSubmitWindowForm(data) {
		var win = Utils.getFrontmostWindow();

		win.fromJSON(data);
		win.find('form')[0].submit();
		win.close();
	}

	test('Default link dialog on empty editor', function() {
		editor.setContent('');
		editor.execCommand('mceLink', true);

		deepEqual(Utils.getFrontmostWindow().toJSON(), {
			"href": "",
			"target": "",
			"text": "",
			"title": ""
		});

		fillAndSubmitWindowForm({
			"href": "href",
			"target": "_blank",
			"text": "text",
			"title": "title"
		});

		equal(
			cleanHtml(editor.getContent()),
			'<p><a title="title" href="href" target="_blank">text</a></p>'
		);
	});

	test('Default link dialog on text selection', function() {
		editor.setContent('<p>abc</p>');
		Utils.setSelection('p', 1, 'p', 2);
		editor.execCommand('mceLink', true);

		deepEqual(Utils.getFrontmostWindow().toJSON(), {
			"href": "",
			"target": "",
			"text": "b",
			"title": ""
		});

		fillAndSubmitWindowForm({
			"href": "href",
			"target": "_blank",
			"title": "title"
		});

		equal(
			cleanHtml(editor.getContent()),
			'<p>a<a title="title" href="href" target="_blank">b</a>c</p>'
		);
	});

	test('Default link dialog on non pure text selection', function() {
		editor.setContent('<p>a</p><p>bc</p>');
		Utils.setSelection('p:nth-child(1)', 0, 'p:nth-child(2)', 2);
		editor.execCommand('mceLink', true);

		deepEqual(Utils.getFrontmostWindow().toJSON(), {
			"href": "",
			"target": "",
			"title": ""
		});

		fillAndSubmitWindowForm({
			"href": "href",
			"target": "_blank",
			"title": "title"
		});

		equal(
			cleanHtml(editor.getContent()),
			'<p><a title="title" href="href" target="_blank">a</a></p>' +
			'<p><a title="title" href="href" target="_blank">bc</a></p>'
		);
	});

	test('All lists link dialog on empty editor', function() {
		editor.settings.link_list = [
			{title: 'link1', value: 'link1'},
			{title: 'link2', value: 'link2'}
		];

		editor.settings.link_class_list = [
			{title: 'class1', value: 'class1'},
			{title: 'class2', value: 'class2'}
		];

		editor.settings.target_list = [
			{title: 'target1', value: 'target1'},
			{title: 'target2', value: 'target2'}
		];

		editor.settings.rel_list = [
			{title: 'rel1', value: 'rel1'},
			{title: 'rel2', value: 'rel2'}
		];

		editor.setContent('');
		editor.execCommand('mceLink', true);

		deepEqual(Utils.getFrontmostWindow().toJSON(), {
			"class": "class1",
			"href": "",
			"rel": "rel1",
			"target": "target1",
			"text": "",
			"title": ""
		});

		fillAndSubmitWindowForm({
			"href": "href",
			"text": "text",
			"title": "title"
		});

		equal(
			cleanHtml(editor.getContent()),
			'<p><a class="class1" title="title" href="href" target="target1" rel="rel1">text</a></p>'
		);
	});

	//Since there's no capability to use the confirm dialog with unit tests, simply test the regex we're using
	test('Test new regex for non relative link setting ftp', function() {
		equal(nonRelativeRegex.test('ftp://testftp.com'), true);
	});

	test('Test new regex for non relative link setting http', function() {
		equal(nonRelativeRegex.test('http://testhttp.com'), true);
	});

	test('Test new regex for non relative link setting relative', function() {
		equal(nonRelativeRegex.test('testhttp.com'), false);
	});

	test('Test new regex for non relative link setting relative base', function() {
		equal(nonRelativeRegex.test('/testjpg.jpg'), false);
	});
})();