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
|
<!DOCTYPE html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>goog.editor.plugins.LinkDialogPlugin Tests</title>
<script src="../../base.js"></script>
<script>
goog.require('goog.dom.DomHelper');
goog.require('goog.editor.BrowserFeature');
goog.require('goog.editor.Command');
goog.require('goog.editor.Field');
goog.require('goog.editor.node');
goog.require('goog.editor.plugins.EquationEditorPlugin');
goog.require('goog.ui.editor.EquationEditorDialog');
goog.require('goog.ui.editor.EquationEditorOkEvent');
goog.require('goog.ui.equation.EquationEditorDialog');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.MockRange');
goog.require('goog.testing.editor.FieldMock');
goog.require('goog.testing.editor.TestHelper');
goog.require('goog.testing.editor.dom');
goog.require('goog.testing.events');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
goog.require('goog.ui.editor.AbstractDialog.EventType');
goog.require('goog.ui.editor.LinkDialog');
goog.require('goog.ui.editor.LinkDialog.OkEvent');
</script>
<link rel="stylesheet" href="../../css/dialog.css"/>
<link rel="stylesheet" href="../../css/editor/dialog.css"/>
<link rel="stylesheet" href="../../css/editor/linkdialog.css"/>
</head>
<body>
<script>
var plugin;
var imgElem;
var mockCtrl;
var mockRange;
var mockField;
var mockEditor;
var mockPlaceCursorNextTo;
var propertyReplacer = new goog.testing.PropertyReplacer();
var fieldObj;
var fieldElem;
var domHelper = new goog.dom.DomHelper();
var IMG_URL = 'https://www.google.com/chart?cht=tx&chf=bg,s,' +
'FFFFFF00&chco=000000&chl=x^2%2Fy^2';
function setUp() {
mockCtrl = new goog.testing.MockControl();
mockRange = new goog.testing.MockRange();
mockCtrl.addMock(mockRange);
mockField = new goog.testing.editor.FieldMock(undefined, undefined,
mockRange);
mockCtrl.addMock(mockField);
mockPlaceCursorNextTo = mockCtrl.createFunctionMock('placeCursorNextTo');
}
function tearDown() {
plugin.dispose();
}
/**
* Sets up expectations for testing when the OK event fires: the field is
* focused, the image is inserted.
* @param {string} imageUrl Url of the image being inserted.
*/
function setUpTestOk(imageUrl) {
mockField.focus().$times(1);
var tempImage = goog.dom.$dom(goog.dom.TagName.IMG, {src: imageUrl});
var fullImageUrl = tempImage.src;
var createdNodeMatcher = new goog.testing.mockmatchers.ArgumentMatcher(
function(arg) {
if (!arg) {
return true;
}
return arg.tagName == goog.dom.TagName.IMG &&
arg.src == fullImageUrl;
},
'<IMG src="' + imageUrl + '">');
mockPlaceCursorNextTo(createdNodeMatcher, false);
mockRange.isCollapsed().$times(1);
mockRange.removeContents().$times(1);
mockRange.insertNode(
domHelper.htmlToDocumentFragment(imageUrl), false).$times(1);
propertyReplacer.set(goog.editor.range,
'placeCursorNextTo',
mockPlaceCursorNextTo);
mockField.dispatchChange().$times(1);
}
/**
* Tests that when the OK event fires the editable field is properly updated.
*/
function testOk() {
setUpTestOk(IMG_URL);
mockField.dispatchBeforeChange().$times(1);
mockCtrl.$replayAll();
plugin = new goog.editor.plugins.EquationEditorPlugin(domHelper);
plugin.registerFieldObject(mockField);
var dialog = plugin.createDialog();
// Mock of execCommand + clicking OK without actually opening the dialog.
dialog.dispatchEvent(
new goog.ui.editor.EquationEditorOkEvent(IMG_URL));
mockCtrl.$verifyAll();
}
</script>
</body>
</html>
|