r102048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102047‎ | r102048 | r102049 >
Date:21:16, 4 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Moved es.DocumentModelBranchNode tests to their own file
Modified paths:
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentModelBranchNode.test.js (added) (history)
  • /trunk/extensions/VisualEditor/tests/es/index.html (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModelBranchNode.test.js
@@ -0,0 +1,129 @@
 2+module( 'es/bases' );
 3+
 4+test( 'es.DocumentModelBranchNode', 20, function() {
 5+ // Example data (integers) is used for simplicity of testing
 6+ var node1 = new es.DocumentModelBranchNode( '1' ),
 7+ node2 = new es.DocumentModelBranchNode( '2' ),
 8+ node3 = new es.DocumentModelBranchNode(
 9+ '3',
 10+ null,
 11+ [new es.DocumentModelBranchNode( '3a' )]
 12+ ),
 13+ node4 = new es.DocumentModelBranchNode(
 14+ '4',
 15+ null,
 16+ [new es.DocumentModelBranchNode( '4a' ), new es.DocumentModelBranchNode( '4b' )]
 17+ );
 18+
 19+ // Event triggering is detected using a callback that increments a counter
 20+ var updates = 0;
 21+ node1.on( 'update', function() {
 22+ updates++;
 23+ } );
 24+ var attaches = 0;
 25+ node2.on( 'afterAttach', function() {
 26+ attaches++;
 27+ } );
 28+ node3.on( 'afterAttach', function() {
 29+ attaches++;
 30+ } );
 31+ node4.on( 'afterAttach', function() {
 32+ attaches++;
 33+ } );
 34+ var detaches = 0;
 35+ node2.on( 'afterDetach', function() {
 36+ detaches++;
 37+ } );
 38+ node3.on( 'afterDetach', function() {
 39+ detaches++;
 40+ } );
 41+ node4.on( 'afterDetach', function() {
 42+ detaches++;
 43+ } );
 44+ function strictArrayValueEqual( a, b, msg ) {
 45+ if ( a.length !== b.length ) {
 46+ ok( false, msg );
 47+ return;
 48+ }
 49+ for ( var i = 0; i < a.length; i++ ) {
 50+ if ( a[i] !== b[i] ) {
 51+ ok( false, msg );
 52+ return;
 53+ }
 54+ }
 55+ ok( true, msg );
 56+ }
 57+
 58+ // Test 1
 59+ node1.push( node2 );
 60+ equal( updates, 1, 'push emits update events' );
 61+ strictArrayValueEqual( node1.getChildren(), [node2], 'push appends a node' );
 62+
 63+ // Test 2
 64+ equal( attaches, 1, 'push attaches added node' );
 65+
 66+ // Test 3, 4
 67+ node1.unshift( node3 );
 68+ equal( updates, 2, 'unshift emits update events' );
 69+ strictArrayValueEqual( node1.getChildren(), [node3, node2], 'unshift prepends a node' );
 70+
 71+ // Test 5
 72+ equal( attaches, 2, 'unshift attaches added node' );
 73+
 74+ // Test 6, 7
 75+ node1.splice( 1, 0, node4 );
 76+ equal( updates, 3, 'splice emits update events' );
 77+ strictArrayValueEqual( node1.getChildren(), [node3, node4, node2], 'splice inserts nodes' );
 78+
 79+ // Test 8
 80+ equal( attaches, 3, 'splice attaches added nodes' );
 81+
 82+ // Test 9
 83+ node1.reverse();
 84+ equal( updates, 4, 'reverse emits update events' );
 85+
 86+ // Test 10, 11
 87+ node1.sort( function( a, b ) {
 88+ return a.getChildren().length < b.getChildren().length ? -1 : 1;
 89+ } );
 90+ equal( updates, 5, 'sort emits update events' );
 91+ strictArrayValueEqual(
 92+ node1.getChildren(),
 93+ [node2, node3, node4],
 94+ 'sort reorderes nodes correctly'
 95+ );
 96+
 97+ // Test 12, 13
 98+ node1.pop();
 99+ equal( updates, 6, 'pop emits update events' );
 100+ strictArrayValueEqual(
 101+ node1.getChildren(),
 102+ [node2, node3],
 103+ 'pop removes the last child node'
 104+ );
 105+
 106+ // Test 14
 107+ equal( detaches, 1, 'pop detaches a node' );
 108+
 109+ // Test 15, 16
 110+ node1.shift();
 111+ equal( updates, 7, 'es.ModelNode emits update events on shift' );
 112+ strictArrayValueEqual(
 113+ node1.getChildren(),
 114+ [node3],
 115+ 'es.ModelNode removes first Node on shift'
 116+ );
 117+
 118+ // Test 17
 119+ equal( detaches, 2, 'shift detaches a node' );
 120+
 121+ // Test 18
 122+ strictEqual( node3.getParent(), node1, 'getParent returns the correct reference' );
 123+
 124+ // Test 19
 125+ try {
 126+ var view = node3.createView();
 127+ } catch ( err ){
 128+ ok( true, 'createView throws an exception when not overridden' );
 129+ }
 130+} );
Index: trunk/extensions/VisualEditor/tests/es/index.html
@@ -41,6 +41,7 @@
4242 <script src="es.testData.js"></script>
4343 <script src="es.test.js"></script>
4444 <script src="es.DocumentNode.test.js"></script>
 45+ <script src="es.DocumentModelBranchNode.test.js"></script>
4546 <script src="es.DocumentModel.test.js"></script>
4647 </body>
4748 </html>
Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js
@@ -718,131 +718,3 @@
719719 'rollback keeps model tree up to date with removals'
720720 );
721721 } );
722 -
723 -test( 'es.DocumentDocumentModelNode child operations', 20, function() {
724 - // Example data (integers) is used for simplicity of testing
725 - var node1 = new es.DocumentModelBranchNode( '1' ),
726 - node2 = new es.DocumentModelBranchNode( '2' ),
727 - node3 = new es.DocumentModelBranchNode(
728 - '3',
729 - null,
730 - [new es.DocumentModelBranchNode( '3a' )]
731 - ),
732 - node4 = new es.DocumentModelBranchNode(
733 - '4',
734 - null,
735 - [new es.DocumentModelBranchNode( '4a' ), new es.DocumentModelBranchNode( '4b' )]
736 - );
737 -
738 - // Event triggering is detected using a callback that increments a counter
739 - var updates = 0;
740 - node1.on( 'update', function() {
741 - updates++;
742 - } );
743 - var attaches = 0;
744 - node2.on( 'afterAttach', function() {
745 - attaches++;
746 - } );
747 - node3.on( 'afterAttach', function() {
748 - attaches++;
749 - } );
750 - node4.on( 'afterAttach', function() {
751 - attaches++;
752 - } );
753 - var detaches = 0;
754 - node2.on( 'afterDetach', function() {
755 - detaches++;
756 - } );
757 - node3.on( 'afterDetach', function() {
758 - detaches++;
759 - } );
760 - node4.on( 'afterDetach', function() {
761 - detaches++;
762 - } );
763 - function strictArrayValueEqual( a, b, msg ) {
764 - if ( a.length !== b.length ) {
765 - ok( false, msg );
766 - return;
767 - }
768 - for ( var i = 0; i < a.length; i++ ) {
769 - if ( a[i] !== b[i] ) {
770 - ok( false, msg );
771 - return;
772 - }
773 - }
774 - ok( true, msg );
775 - }
776 -
777 - // Test 1
778 - node1.push( node2 );
779 - equal( updates, 1, 'push emits update events' );
780 - strictArrayValueEqual( node1.getChildren(), [node2], 'push appends a node' );
781 -
782 - // Test 2
783 - equal( attaches, 1, 'push attaches added node' );
784 -
785 - // Test 3, 4
786 - node1.unshift( node3 );
787 - equal( updates, 2, 'unshift emits update events' );
788 - strictArrayValueEqual( node1.getChildren(), [node3, node2], 'unshift prepends a node' );
789 -
790 - // Test 5
791 - equal( attaches, 2, 'unshift attaches added node' );
792 -
793 - // Test 6, 7
794 - node1.splice( 1, 0, node4 );
795 - equal( updates, 3, 'splice emits update events' );
796 - strictArrayValueEqual( node1.getChildren(), [node3, node4, node2], 'splice inserts nodes' );
797 -
798 - // Test 8
799 - equal( attaches, 3, 'splice attaches added nodes' );
800 -
801 - // Test 9
802 - node1.reverse();
803 - equal( updates, 4, 'reverse emits update events' );
804 -
805 - // Test 10, 11
806 - node1.sort( function( a, b ) {
807 - return a.getChildren().length < b.getChildren().length ? -1 : 1;
808 - } );
809 - equal( updates, 5, 'sort emits update events' );
810 - strictArrayValueEqual(
811 - node1.getChildren(),
812 - [node2, node3, node4],
813 - 'sort reorderes nodes correctly'
814 - );
815 -
816 - // Test 12, 13
817 - node1.pop();
818 - equal( updates, 6, 'pop emits update events' );
819 - strictArrayValueEqual(
820 - node1.getChildren(),
821 - [node2, node3],
822 - 'pop removes the last child node'
823 - );
824 -
825 - // Test 14
826 - equal( detaches, 1, 'pop detaches a node' );
827 -
828 - // Test 15, 16
829 - node1.shift();
830 - equal( updates, 7, 'es.ModelNode emits update events on shift' );
831 - strictArrayValueEqual(
832 - node1.getChildren(),
833 - [node3],
834 - 'es.ModelNode removes first Node on shift'
835 - );
836 -
837 - // Test 17
838 - equal( detaches, 2, 'shift detaches a node' );
839 -
840 - // Test 18
841 - strictEqual( node3.getParent(), node1, 'getParent returns the correct reference' );
842 -
843 - // Test 19
844 - try {
845 - var view = node3.createView();
846 - } catch ( err ){
847 - ok( true, 'createView throws an exception when not overridden' );
848 - }
849 -} );

Status & tagging log