Index: trunk/extensions/VisualEditor/tests/es/es.testData.js |
— | — | @@ -0,0 +1,206 @@ |
| 2 | +esTest = {}; |
| 3 | + |
| 4 | +/* |
| 5 | + * Sample plain object (WikiDom). |
| 6 | + * |
| 7 | + * There are two kinds of nodes in WikiDom: |
| 8 | + * |
| 9 | + * {Object} ElementNode |
| 10 | + * type: {String} Symbolic node type name |
| 11 | + * [attributes]: {Object} List of symbolic attribute name and literal value pairs |
| 12 | + * [content]: {Object} Content node (not defined if node has children) |
| 13 | + * [children]: {Object[]} Child nodes (not defined if node has content) |
| 14 | + * |
| 15 | + * {Object} ContentNode |
| 16 | + * text: {String} Plain text data of content |
| 17 | + * [annotations]: {Object[]} List of annotation objects that can be used to render text |
| 18 | + * type: {String} Symbolic name of annotation type |
| 19 | + * start: {Integer} Offset within text to begin annotation |
| 20 | + * end: {Integer} Offset within text to end annotation |
| 21 | + * [data]: {Object} Additional information, only used by more complex annotations |
| 22 | + */ |
| 23 | +esTest.obj = { |
| 24 | + 'type': 'document', |
| 25 | + 'children': [ |
| 26 | + { |
| 27 | + 'type': 'paragraph', |
| 28 | + 'content': { |
| 29 | + 'text': 'abc', |
| 30 | + 'annotations': [ |
| 31 | + { |
| 32 | + 'type': 'textStyle/bold', |
| 33 | + 'range': { |
| 34 | + 'start': 1, |
| 35 | + 'end': 2 |
| 36 | + } |
| 37 | + }, |
| 38 | + { |
| 39 | + 'type': 'textStyle/italic', |
| 40 | + 'range': { |
| 41 | + 'start': 2, |
| 42 | + 'end': 3 |
| 43 | + } |
| 44 | + } |
| 45 | + ] |
| 46 | + } |
| 47 | + }, |
| 48 | + { |
| 49 | + 'type': 'table', |
| 50 | + 'children': [ |
| 51 | + { |
| 52 | + 'type': 'tableRow', |
| 53 | + 'children': [ |
| 54 | + { |
| 55 | + 'type': 'tableCell', |
| 56 | + 'children': [ |
| 57 | + { |
| 58 | + 'type': 'paragraph', |
| 59 | + 'content': { |
| 60 | + 'text': 'd' |
| 61 | + } |
| 62 | + }, |
| 63 | + { |
| 64 | + 'type': 'list', |
| 65 | + 'children': [ |
| 66 | + { |
| 67 | + 'type': 'listItem', |
| 68 | + 'attributes': { |
| 69 | + 'styles': ['bullet'] |
| 70 | + }, |
| 71 | + 'content': { |
| 72 | + 'text': 'e' |
| 73 | + } |
| 74 | + }, |
| 75 | + { |
| 76 | + 'type': 'listItem', |
| 77 | + 'attributes': { |
| 78 | + 'styles': ['bullet', 'bullet'] |
| 79 | + }, |
| 80 | + 'content': { |
| 81 | + 'text': 'f' |
| 82 | + } |
| 83 | + }, |
| 84 | + { |
| 85 | + 'type': 'listItem', |
| 86 | + 'attributes': { |
| 87 | + 'styles': ['number'] |
| 88 | + }, |
| 89 | + 'content': { |
| 90 | + 'text': 'g' |
| 91 | + } |
| 92 | + } |
| 93 | + ] |
| 94 | + } |
| 95 | + ] |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + 'type': 'paragraph', |
| 103 | + 'content': { |
| 104 | + 'text': 'h' |
| 105 | + } |
| 106 | + } |
| 107 | + ] |
| 108 | +}; |
| 109 | + |
| 110 | +/* |
| 111 | + * Sample content data. |
| 112 | + * |
| 113 | + * There are three types of components in content data: |
| 114 | + * |
| 115 | + * {String} Plain text character |
| 116 | + * |
| 117 | + * {Array} Annotated character |
| 118 | + * {String} Character |
| 119 | + * {String} Hash |
| 120 | + * {Object}... List of annotation object references |
| 121 | + * |
| 122 | + * {Object} Opening or closing structural element |
| 123 | + * type: {String} Symbolic node type name, if closing element first character will be "/" |
| 124 | + * node: {Object} Reference to model tree node |
| 125 | + * [attributes]: {Object} List of symbolic attribute name and literal value pairs |
| 126 | + */ |
| 127 | +esTest.data = [ |
| 128 | + // 0 - Beginning of paragraph |
| 129 | + { 'type': 'paragraph' }, |
| 130 | + // 1 - Plain content |
| 131 | + 'a', |
| 132 | + // 2 - Annotated content |
| 133 | + ['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }], |
| 134 | + // 3 - Annotated content |
| 135 | + ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }], |
| 136 | + // 4 - End of paragraph |
| 137 | + { 'type': '/paragraph' }, |
| 138 | + // 5 - Beginning of table |
| 139 | + { 'type': 'table' }, |
| 140 | + // 6 - Beginning of row |
| 141 | + { 'type': 'tableRow' }, |
| 142 | + // 7 - Beginning of cell |
| 143 | + { 'type': 'tableCell' }, |
| 144 | + // 8 - Beginning of paragraph |
| 145 | + { 'type': 'paragraph' }, |
| 146 | + // 9 - Plain content |
| 147 | + 'd', |
| 148 | + // 10 - End of paragraph |
| 149 | + { 'type': '/paragraph' }, |
| 150 | + // 11 - Beginning of list |
| 151 | + { 'type': 'list' }, |
| 152 | + // 12 - Beginning of bullet list item |
| 153 | + { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } }, |
| 154 | + // 13 - Plain content |
| 155 | + 'e', |
| 156 | + // 14 - End of item |
| 157 | + { 'type': '/listItem' }, |
| 158 | + // 15 - Beginning of nested bullet list item |
| 159 | + { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } }, |
| 160 | + // 16 - Plain content |
| 161 | + 'f', |
| 162 | + // 17 - End of item |
| 163 | + { 'type': '/listItem' }, |
| 164 | + // 18 - Beginning of numbered list item |
| 165 | + { 'type': 'listItem', 'attributes': { 'styles': ['number'] } }, |
| 166 | + // 19 - Plain content |
| 167 | + 'g', |
| 168 | + // 20 - End of item |
| 169 | + { 'type': '/listItem' }, |
| 170 | + // 21 - End of list |
| 171 | + { 'type': '/list' }, |
| 172 | + // 22 - End of cell |
| 173 | + { 'type': '/tableCell' }, |
| 174 | + // 23 - End of row |
| 175 | + { 'type': '/tableRow' }, |
| 176 | + // 24 - End of table |
| 177 | + { 'type': '/table' }, |
| 178 | + // 25 - Beginning of paragraph |
| 179 | + { 'type': 'paragraph' }, |
| 180 | + // 26 - Plain content |
| 181 | + 'h', |
| 182 | + // 27 - End of paragraph |
| 183 | + { 'type': '/paragraph' } |
| 184 | +]; |
| 185 | + |
| 186 | +/** |
| 187 | + * Sample content data index. |
| 188 | + * |
| 189 | + * This is a node tree that describes each partition within the document's content data. This is |
| 190 | + * what is automatically built by the es.DocumentModel constructor. |
| 191 | + */ |
| 192 | +esTest.tree = [ |
| 193 | + new es.ParagraphModel( esTest.data[0], 3 ), |
| 194 | + new es.TableModel( esTest.data[5], [ |
| 195 | + new es.TableRowModel( esTest.data[6], [ |
| 196 | + new es.TableCellModel( esTest.data[7], [ |
| 197 | + new es.ParagraphModel( esTest.data[8], 1 ), |
| 198 | + new es.ListModel( esTest.data[11], [ |
| 199 | + new es.ListItemModel( esTest.data[12], 1 ), |
| 200 | + new es.ListItemModel( esTest.data[15], 1 ), |
| 201 | + new es.ListItemModel( esTest.data[18], 1 ) |
| 202 | + ] ) |
| 203 | + ] ) |
| 204 | + ] ) |
| 205 | + ] ), |
| 206 | + new es.ParagraphModel( esTest.data[25], 1 ) |
| 207 | +]; |
Property changes on: trunk/extensions/VisualEditor/tests/es/es.testData.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 208 | + native |
Index: trunk/extensions/VisualEditor/tests/es/index.html |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | <script src="../../modules/es/models/es.TableRowModel.js"></script> |
40 | 40 | |
41 | 41 | <!-- Tests --> |
| 42 | + <script src="es.testData.js"></script> |
42 | 43 | <script src="es.test.js"></script> |
43 | 44 | <script src="es.DocumentNode.test.js"></script> |
44 | 45 | <script src="es.DocumentModel.test.js"></script> |
Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js |
— | — | @@ -1,219 +1,14 @@ |
2 | 2 | module( 'es/models' ); |
3 | 3 | |
4 | | -/* |
5 | | - * Sample plain object (WikiDom). |
6 | | - * |
7 | | - * There are two kinds of nodes in WikiDom: |
8 | | - * |
9 | | - * {Object} ElementNode |
10 | | - * type: {String} Symbolic node type name |
11 | | - * [attributes]: {Object} List of symbolic attribute name and literal value pairs |
12 | | - * [content]: {Object} Content node (not defined if node has children) |
13 | | - * [children]: {Object[]} Child nodes (not defined if node has content) |
14 | | - * |
15 | | - * {Object} ContentNode |
16 | | - * text: {String} Plain text data of content |
17 | | - * [annotations]: {Object[]} List of annotation objects that can be used to render text |
18 | | - * type: {String} Symbolic name of annotation type |
19 | | - * start: {Integer} Offset within text to begin annotation |
20 | | - * end: {Integer} Offset within text to end annotation |
21 | | - * [data]: {Object} Additional information, only used by more complex annotations |
22 | | - */ |
23 | | -var obj = { |
24 | | - 'type': 'document', |
25 | | - 'children': [ |
26 | | - { |
27 | | - 'type': 'paragraph', |
28 | | - 'content': { |
29 | | - 'text': 'abc', |
30 | | - 'annotations': [ |
31 | | - { |
32 | | - 'type': 'textStyle/bold', |
33 | | - 'range': { |
34 | | - 'start': 1, |
35 | | - 'end': 2 |
36 | | - } |
37 | | - }, |
38 | | - { |
39 | | - 'type': 'textStyle/italic', |
40 | | - 'range': { |
41 | | - 'start': 2, |
42 | | - 'end': 3 |
43 | | - } |
44 | | - } |
45 | | - ] |
46 | | - } |
47 | | - }, |
48 | | - { |
49 | | - 'type': 'table', |
50 | | - 'children': [ |
51 | | - { |
52 | | - 'type': 'tableRow', |
53 | | - 'children': [ |
54 | | - { |
55 | | - 'type': 'tableCell', |
56 | | - 'children': [ |
57 | | - { |
58 | | - 'type': 'paragraph', |
59 | | - 'content': { |
60 | | - 'text': 'd' |
61 | | - } |
62 | | - }, |
63 | | - { |
64 | | - 'type': 'list', |
65 | | - 'children': [ |
66 | | - { |
67 | | - 'type': 'listItem', |
68 | | - 'attributes': { |
69 | | - 'styles': ['bullet'] |
70 | | - }, |
71 | | - 'content': { |
72 | | - 'text': 'e' |
73 | | - } |
74 | | - }, |
75 | | - { |
76 | | - 'type': 'listItem', |
77 | | - 'attributes': { |
78 | | - 'styles': ['bullet', 'bullet'] |
79 | | - }, |
80 | | - 'content': { |
81 | | - 'text': 'f' |
82 | | - } |
83 | | - }, |
84 | | - { |
85 | | - 'type': 'listItem', |
86 | | - 'attributes': { |
87 | | - 'styles': ['number'] |
88 | | - }, |
89 | | - 'content': { |
90 | | - 'text': 'g' |
91 | | - } |
92 | | - } |
93 | | - ] |
94 | | - } |
95 | | - ] |
96 | | - } |
97 | | - ] |
98 | | - } |
99 | | - ] |
100 | | - }, |
101 | | - { |
102 | | - 'type': 'paragraph', |
103 | | - 'content': { |
104 | | - 'text': 'h' |
105 | | - } |
106 | | - } |
107 | | - ] |
108 | | -}; |
109 | | - |
110 | | -/* |
111 | | - * Sample content data. |
112 | | - * |
113 | | - * There are three types of components in content data: |
114 | | - * |
115 | | - * {String} Plain text character |
116 | | - * |
117 | | - * {Array} Annotated character |
118 | | - * {String} Character |
119 | | - * {String} Hash |
120 | | - * {Object}... List of annotation object references |
121 | | - * |
122 | | - * {Object} Opening or closing structural element |
123 | | - * type: {String} Symbolic node type name, if closing element first character will be "/" |
124 | | - * node: {Object} Reference to model tree node |
125 | | - * [attributes]: {Object} List of symbolic attribute name and literal value pairs |
126 | | - */ |
127 | | -var data = [ |
128 | | - // 0 - Beginning of paragraph |
129 | | - { 'type': 'paragraph' }, |
130 | | - // 1 - Plain content |
131 | | - 'a', |
132 | | - // 2 - Annotated content |
133 | | - ['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }], |
134 | | - // 3 - Annotated content |
135 | | - ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }], |
136 | | - // 4 - End of paragraph |
137 | | - { 'type': '/paragraph' }, |
138 | | - // 5 - Beginning of table |
139 | | - { 'type': 'table' }, |
140 | | - // 6 - Beginning of row |
141 | | - { 'type': 'tableRow' }, |
142 | | - // 7 - Beginning of cell |
143 | | - { 'type': 'tableCell' }, |
144 | | - // 8 - Beginning of paragraph |
145 | | - { 'type': 'paragraph' }, |
146 | | - // 9 - Plain content |
147 | | - 'd', |
148 | | - // 10 - End of paragraph |
149 | | - { 'type': '/paragraph' }, |
150 | | - // 11 - Beginning of list |
151 | | - { 'type': 'list' }, |
152 | | - // 12 - Beginning of bullet list item |
153 | | - { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } }, |
154 | | - // 13 - Plain content |
155 | | - 'e', |
156 | | - // 14 - End of item |
157 | | - { 'type': '/listItem' }, |
158 | | - // 15 - Beginning of nested bullet list item |
159 | | - { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } }, |
160 | | - // 16 - Plain content |
161 | | - 'f', |
162 | | - // 17 - End of item |
163 | | - { 'type': '/listItem' }, |
164 | | - // 18 - Beginning of numbered list item |
165 | | - { 'type': 'listItem', 'attributes': { 'styles': ['number'] } }, |
166 | | - // 19 - Plain content |
167 | | - 'g', |
168 | | - // 20 - End of item |
169 | | - { 'type': '/listItem' }, |
170 | | - // 21 - End of list |
171 | | - { 'type': '/list' }, |
172 | | - // 22 - End of cell |
173 | | - { 'type': '/tableCell' }, |
174 | | - // 23 - End of row |
175 | | - { 'type': '/tableRow' }, |
176 | | - // 24 - End of table |
177 | | - { 'type': '/table' }, |
178 | | - // 25 - Beginning of paragraph |
179 | | - { 'type': 'paragraph' }, |
180 | | - // 26 - Plain content |
181 | | - 'h', |
182 | | - // 27 - End of paragraph |
183 | | - { 'type': '/paragraph' } |
184 | | -]; |
185 | | - |
186 | | -/** |
187 | | - * Sample content data index. |
188 | | - * |
189 | | - * This is a node tree that describes each partition within the document's content data. This is |
190 | | - * what is automatically built by the es.DocumentModel constructor. |
191 | | - */ |
192 | | -var tree = [ |
193 | | - new es.ParagraphModel( data[0], 3 ), |
194 | | - new es.TableModel( data[5], [ |
195 | | - new es.TableRowModel( data[6], [ |
196 | | - new es.TableCellModel( data[7], [ |
197 | | - new es.ParagraphModel( data[8], 1 ), |
198 | | - new es.ListModel( data[11], [ |
199 | | - new es.ListItemModel( data[12], 1 ), |
200 | | - new es.ListItemModel( data[15], 1 ), |
201 | | - new es.ListItemModel( data[18], 1 ) |
202 | | - ] ) |
203 | | - ] ) |
204 | | - ] ) |
205 | | - ] ), |
206 | | - new es.ParagraphModel( data[25], 1 ) |
207 | | -]; |
208 | | - |
209 | 4 | test( 'es.DocumentModel.getData', 1, function() { |
210 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 5 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
211 | 6 | |
212 | 7 | // Test 1 |
213 | | - deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' ); |
| 8 | + deepEqual( documentModel.getData(), esTest.data, 'Flattening plain objects results in correct data' ); |
214 | 9 | } ); |
215 | 10 | |
216 | 11 | test( 'es.DocumentModel.getChildren', 1, function() { |
217 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 12 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
218 | 13 | |
219 | 14 | function equalLengths( a, b ) { |
220 | 15 | if ( a.length !== b.length ) { |
— | — | @@ -238,13 +33,13 @@ |
239 | 34 | |
240 | 35 | // Test 1 |
241 | 36 | ok( |
242 | | - equalLengths( documentModel.getChildren(), tree ), |
| 37 | + equalLengths( documentModel.getChildren(), esTest.tree ), |
243 | 38 | 'Nodes in the model tree contain correct lengths' |
244 | 39 | ); |
245 | 40 | } ); |
246 | 41 | |
247 | 42 | test( 'es.DocumentModel.getRelativeContentOffset', 7, function() { |
248 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 43 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
249 | 44 | |
250 | 45 | // Test 1 |
251 | 46 | equal( |
— | — | @@ -291,7 +86,7 @@ |
292 | 87 | } ); |
293 | 88 | |
294 | 89 | test( 'es.DocumentModel.getContent', 6, function() { |
295 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ), |
| 90 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ), |
296 | 91 | childNodes = documentModel.getChildren(); |
297 | 92 | |
298 | 93 | // Test 1 |
— | — | @@ -337,7 +132,7 @@ |
338 | 133 | } ); |
339 | 134 | |
340 | 135 | test( 'es.DocumentModel.getIndexOfAnnotation', 3, function() { |
341 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 136 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
342 | 137 | |
343 | 138 | var bold = { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }, |
344 | 139 | italic = { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }, |
— | — | @@ -367,7 +162,7 @@ |
368 | 163 | } ); |
369 | 164 | |
370 | 165 | test( 'es.DocumentModel.getWordBoundaries', 2, function() { |
371 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 166 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
372 | 167 | deepEqual( |
373 | 168 | documentModel.getWordBoundaries( 2 ), |
374 | 169 | new es.Range( 1, 4 ), |
— | — | @@ -381,7 +176,7 @@ |
382 | 177 | } ); |
383 | 178 | |
384 | 179 | test( 'es.DocumentModel.getAnnotationBoundaries', 2, function() { |
385 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 180 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
386 | 181 | deepEqual( |
387 | 182 | documentModel.getAnnotationBoundaries( 2, { 'type': 'textStyle/bold' } ), |
388 | 183 | new es.Range( 2, 3 ), |
— | — | @@ -395,7 +190,7 @@ |
396 | 191 | } ); |
397 | 192 | |
398 | 193 | test( 'es.DocumentModel.getAnnotationsFromOffset', 4, function() { |
399 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 194 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
400 | 195 | deepEqual( |
401 | 196 | documentModel.getAnnotationsFromOffset( 1 ), |
402 | 197 | [], |
— | — | @@ -419,7 +214,7 @@ |
420 | 215 | } ); |
421 | 216 | |
422 | 217 | test( 'es.DocumentModel.prepareElementAttributeChange', 4, function() { |
423 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 218 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
424 | 219 | |
425 | 220 | // Test 1 |
426 | 221 | deepEqual( |
— | — | @@ -464,7 +259,7 @@ |
465 | 260 | } ); |
466 | 261 | |
467 | 262 | test( 'es.DocumentModel.prepareContentAnnotation', 1, function() { |
468 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 263 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
469 | 264 | |
470 | 265 | // Test 1 |
471 | 266 | deepEqual( |
— | — | @@ -507,7 +302,7 @@ |
508 | 303 | } ); |
509 | 304 | |
510 | 305 | test( 'es.DocumentModel.prepareRemoval', 3, function() { |
511 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 306 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
512 | 307 | |
513 | 308 | // Test 1 |
514 | 309 | deepEqual( |
— | — | @@ -564,7 +359,7 @@ |
565 | 360 | } ); |
566 | 361 | |
567 | 362 | test( 'es.DocumentModel.prepareInsertion', 11, function() { |
568 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 363 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
569 | 364 | |
570 | 365 | // Test 1 |
571 | 366 | deepEqual( |
— | — | @@ -737,7 +532,7 @@ |
738 | 533 | } ); |
739 | 534 | |
740 | 535 | test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 12, function() { |
741 | | - var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 536 | + var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj ); |
742 | 537 | |
743 | 538 | var elementAttributeChange = documentModel.prepareElementAttributeChange( |
744 | 539 | 0, 'set', 'test', 1 |