Index: trunk/phase3/tests/qunit/index.html |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | <script src="../../resources/jquery/jquery.localize.js"></script> |
49 | 49 | <script src="../../resources/jquery/jquery.tabIndex.js"></script> |
50 | 50 | <script src="../../resources/jquery/jquery.tablesorter.js"></script> |
| 51 | + <script src="../../resources/jquery/jquery.textSelection.js"></script> |
51 | 52 | <script src="../../resources/mediawiki/mediawiki.Title.js"></script> |
52 | 53 | <script src="../../resources/mediawiki.special/mediawiki.special.js"></script> |
53 | 54 | <script src="../../resources/mediawiki.special/mediawiki.special.recentchanges.js"></script> |
— | — | @@ -73,6 +74,7 @@ |
74 | 75 | <script src="suites/resources/jquery/jquery.localize.js"></script> |
75 | 76 | <script src="suites/resources/jquery/jquery.tabIndex.js"></script> |
76 | 77 | <script src="suites/resources/jquery/jquery.tablesorter.test.js" charset="UTF-8"></script> |
| 78 | + <script src="suites/resources/jquery/jquery.textSelection.js" charset="UTF-8"></script> |
77 | 79 | <script src="suites/resources/mediawiki/mediawiki.Title.js"></script> |
78 | 80 | <script src="suites/resources/mediawiki.special/mediawiki.special.recentchanges.js"></script> |
79 | 81 | </head> |
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.js |
— | — | @@ -0,0 +1,216 @@ |
| 2 | +module( 'jquery.textSelection.js' ); |
| 3 | + |
| 4 | +test( '-- Initial check', function() { |
| 5 | + expect(1); |
| 6 | + ok( $.fn.textSelection, 'jQuery.fn.textSelection defined' ); |
| 7 | +} ); |
| 8 | + |
| 9 | +/** |
| 10 | + * Test factory for $.fn.textSelection('encapsulateText') |
| 11 | + * |
| 12 | + * @param options {object} associative array containing: |
| 13 | + * description {string} |
| 14 | + * input {string} |
| 15 | + * output {string} |
| 16 | + * start {int} starting char for selection |
| 17 | + * end {int} ending char for selection |
| 18 | + * params {object} add'l parameters for $().textSelection('encapsulateText') |
| 19 | + */ |
| 20 | +var encapsulateTest = function( options ) { |
| 21 | + var opt = $.extend({ |
| 22 | + description: '', |
| 23 | + before: {}, |
| 24 | + after: {}, |
| 25 | + replace: {} |
| 26 | + }, options); |
| 27 | + |
| 28 | + opt.before = $.extend({ |
| 29 | + text: '', |
| 30 | + start: 0, |
| 31 | + end: 0 |
| 32 | + }, opt.before); |
| 33 | + opt.after = $.extend({ |
| 34 | + text: '', |
| 35 | + selected: null |
| 36 | + }, opt.after); |
| 37 | + |
| 38 | + test( opt.description, function() { |
| 39 | + var tests = 1; |
| 40 | + if (opt.after.selected !== null) { |
| 41 | + tests++; |
| 42 | + } |
| 43 | + expect(tests); |
| 44 | + |
| 45 | + var $fixture = $('<div id="qunit-fixture"></div>'); |
| 46 | + var $textarea = $('<textarea>'); |
| 47 | + |
| 48 | + $fixture.append($textarea); |
| 49 | + $('body').append($fixture); |
| 50 | + |
| 51 | + //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm... |
| 52 | + $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe? |
| 53 | + |
| 54 | + $textarea.textSelection( 'setSelection', { |
| 55 | + start: opt.before.start, |
| 56 | + end: opt.before.end |
| 57 | + }); |
| 58 | + |
| 59 | + $textarea.textSelection( 'encapsulateSelection', opt.replace ); |
| 60 | + |
| 61 | + var text = $textarea.textSelection( 'getContents' ); |
| 62 | + |
| 63 | + equal( text, opt.after.text, 'Checking full text after encapsulation' ); |
| 64 | + |
| 65 | + if (opt.after.selected !== null) { |
| 66 | + var selected = $textarea.textSelection( 'getSelection' ); |
| 67 | + equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' ); |
| 68 | + } |
| 69 | + |
| 70 | + } ); |
| 71 | +}; |
| 72 | + |
| 73 | +var sig = { |
| 74 | + 'pre': "--~~~~" |
| 75 | +}, bold = { |
| 76 | + pre: "'''", |
| 77 | + peri: 'Bold text', |
| 78 | + post: "'''" |
| 79 | +}, h2 = { |
| 80 | + 'pre': '== ', |
| 81 | + 'peri': 'Heading 2', |
| 82 | + 'post': ' ==', |
| 83 | + 'regex': /^(\s*)(={1,6})(.*?)\2(\s*)$/, |
| 84 | + 'regexReplace': "\$1==\$3==\$4", |
| 85 | + 'ownline': true |
| 86 | +}, ulist = { |
| 87 | + 'pre': "* ", |
| 88 | + 'peri': 'Bulleted list item', |
| 89 | + 'post': "", |
| 90 | + 'ownline': true, |
| 91 | + 'splitlines': true |
| 92 | +}; |
| 93 | + |
| 94 | +encapsulateTest({ |
| 95 | + description: "Adding sig to end of text", |
| 96 | + before: { |
| 97 | + text: "Wikilove dude! ", |
| 98 | + start: 15, |
| 99 | + end: 15 |
| 100 | + }, |
| 101 | + after: { |
| 102 | + text: "Wikilove dude! --~~~~", |
| 103 | + selected: "" |
| 104 | + }, |
| 105 | + replace: sig |
| 106 | +}); |
| 107 | + |
| 108 | +encapsulateTest({ |
| 109 | + description: "Adding bold to empty", |
| 110 | + before: { |
| 111 | + text: "", |
| 112 | + start: 0, |
| 113 | + end: 0 |
| 114 | + }, |
| 115 | + after: { |
| 116 | + text: "'''Bold text'''", |
| 117 | + selected: "Bold text" // selected because it's the default |
| 118 | + }, |
| 119 | + replace: bold |
| 120 | +}); |
| 121 | + |
| 122 | +encapsulateTest({ |
| 123 | + description: "Adding bold to existing text", |
| 124 | + before: { |
| 125 | + text: "Now is the time for all good men to come to the aid of their country", |
| 126 | + start: 20, |
| 127 | + end: 32 |
| 128 | + }, |
| 129 | + after: { |
| 130 | + text: "Now is the time for '''all good men''' to come to the aid of their country", |
| 131 | + selected: "" // empty because it's not the default' |
| 132 | + }, |
| 133 | + replace: bold |
| 134 | +}); |
| 135 | + |
| 136 | +encapsulateTest({ |
| 137 | + description: "ownline option: adding new h2", |
| 138 | + before: { |
| 139 | + text:"Before\nAfter", |
| 140 | + start: 7, |
| 141 | + end: 7 |
| 142 | + }, |
| 143 | + after: { |
| 144 | + text: "Before\n== Heading 2 ==\nAfter", |
| 145 | + selected: "Heading 2" |
| 146 | + }, |
| 147 | + replace: h2 |
| 148 | +}); |
| 149 | + |
| 150 | +encapsulateTest({ |
| 151 | + description: "ownline option: turn a whole line into new h2", |
| 152 | + before: { |
| 153 | + text:"Before\nMy heading\nAfter", |
| 154 | + start: 7, |
| 155 | + end: 17 |
| 156 | + }, |
| 157 | + after: { |
| 158 | + text: "Before\n== My heading ==\nAfter", |
| 159 | + selected: "" |
| 160 | + }, |
| 161 | + replace: h2 |
| 162 | +}); |
| 163 | + |
| 164 | + |
| 165 | +encapsulateTest({ |
| 166 | + description: "ownline option: turn a partial line into new h2", |
| 167 | + before: { |
| 168 | + text:"BeforeMy headingAfter", |
| 169 | + start: 6, |
| 170 | + end: 16 |
| 171 | + }, |
| 172 | + after: { |
| 173 | + text: "Before\n== My heading ==\nAfter", |
| 174 | + selected: "" |
| 175 | + }, |
| 176 | + replace: h2 |
| 177 | +}); |
| 178 | + |
| 179 | + |
| 180 | +encapsulateTest({ |
| 181 | + description: "splitlines option: no selection, insert new list item", |
| 182 | + before: { |
| 183 | + text: "Before\nAfter", |
| 184 | + start: 7, |
| 185 | + end: 7 |
| 186 | + }, |
| 187 | + after: { |
| 188 | + text: "Before\n* Bulleted list item\nAfter" |
| 189 | + }, |
| 190 | + replace: ulist |
| 191 | +}); |
| 192 | + |
| 193 | +encapsulateTest({ |
| 194 | + description: "splitlines option: single partial line selection, insert new list item", |
| 195 | + before: { |
| 196 | + text: "BeforeMy List ItemAfter", |
| 197 | + start: 6, |
| 198 | + end: 18 |
| 199 | + }, |
| 200 | + after: { |
| 201 | + text: "Before\n* My List Item\nAfter" |
| 202 | + }, |
| 203 | + replace: ulist |
| 204 | +}); |
| 205 | + |
| 206 | +encapsulateTest({ |
| 207 | + description: "splitlines option: multiple lines", |
| 208 | + before: { |
| 209 | + text: "Before\nFirst\nSecond\nThird\nAfter", |
| 210 | + start: 7, |
| 211 | + end: 25 |
| 212 | + }, |
| 213 | + after: { |
| 214 | + text: "Before\n* First\n* Second\n* Third\nAfter" |
| 215 | + }, |
| 216 | + replace: ulist |
| 217 | +}); |
Property changes on: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 218 | + native |