Index: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentSynchronizer.test.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | module( 've/dm' ); |
3 | 3 | |
4 | | -test( 've.dm.DocumentSynchronizer', 9, function() { |
| 4 | +test( 've.dm.DocumentSynchronizer', 10, function() { |
5 | 5 | var tests = { |
6 | 6 | // Test 1 |
7 | 7 | 'resize actions adjust node lengths': { |
— | — | @@ -141,6 +141,34 @@ |
142 | 142 | return model.getChildren()[1].getContentData(); |
143 | 143 | }, |
144 | 144 | 'expected': ['x'] |
| 145 | + }, |
| 146 | + // Test 10 |
| 147 | + 'multiple actions can be synchronized together': { |
| 148 | + 'actual': function( sync ) { |
| 149 | + var model = sync.getModel(), |
| 150 | + data = [{ 'type': 'paragraph' }, 'x', { 'type': '/paragraph' }], |
| 151 | + node = ve.dm.DocumentNode.createNodesFromData( data )[0]; |
| 152 | + // Delete bold "b" from first paragraph |
| 153 | + model.data.splice( 2, 1 ); |
| 154 | + // Push resize action |
| 155 | + sync.pushAction( 'resize', model.getChildren()[0], 0, -1 ); |
| 156 | + // Delete the first paragraph (offset adjusted for previous action) |
| 157 | + model.data.splice( 30, 3 ); |
| 158 | + // Push deletion action (note: using original offset) |
| 159 | + sync.pushAction( 'delete', model.getChildren()[2], 31 ); |
| 160 | + // Insert element after last paragraph |
| 161 | + ve.insertIntoArray( model.data, 30, data ); |
| 162 | + // Push insertion action (note: using original offset) |
| 163 | + sync.pushAction( 'insert', node, 34 ); |
| 164 | + // Sync |
| 165 | + sync.synchronize(); |
| 166 | + return [ |
| 167 | + model.getChildren()[0].getContentLength(), |
| 168 | + model.getChildren().length, |
| 169 | + model.getChildren()[2].getContentData() |
| 170 | + ]; |
| 171 | + }, |
| 172 | + 'expected': [2, 3, ['x']] |
145 | 173 | } |
146 | 174 | }; |
147 | 175 | |