| 1 | const tables = require( '../../../resources/skins.vector.js/tables.js' ).init; |
| 2 | |
| 3 | describe( 'tables', () => { |
| 4 | test( 'wraps table with div', () => { |
| 5 | document.body.innerHTML = ` |
| 6 | <div class="mw-parser-output"> |
| 7 | <table class="wikitable"> |
| 8 | <tbody><tr><th>table table table</th></tr></tbody> |
| 9 | </table> |
| 10 | </div> |
| 11 | `; |
| 12 | tables(); |
| 13 | |
| 14 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 15 | } ); |
| 16 | |
| 17 | test( 'wraps multiple table with div', () => { |
| 18 | document.body.innerHTML = ` |
| 19 | <div class="mw-parser-output"> |
| 20 | <table class="wikitable"> |
| 21 | <tbody><tr><th>table table table</th></tr></tbody> |
| 22 | </table> |
| 23 | <table class="wikitable"> |
| 24 | <table class="wikitable"> |
| 25 | <tbody><tr><th>table table table</th></tr></tbody> |
| 26 | </table> |
| 27 | <table class="wikitable"> |
| 28 | <tbody><tr><th>table table table</th></tr></tbody> |
| 29 | </table> |
| 30 | </div> |
| 31 | `; |
| 32 | tables(); |
| 33 | |
| 34 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 35 | } ); |
| 36 | |
| 37 | test( 'doesnt wrap nested tables', () => { |
| 38 | document.body.innerHTML = ` |
| 39 | <div class="mw-parser-output"> |
| 40 | <table class="wikitable"> |
| 41 | <tbody> |
| 42 | <tr><th>table table table</th></tr> |
| 43 | <tr><td><table class="wikitable"><tbody><tr><th>table table table</th></tr></tbody></table><td></tr> |
| 44 | </tbody> |
| 45 | </table> |
| 46 | </div> |
| 47 | `; |
| 48 | tables(); |
| 49 | |
| 50 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 51 | } ); |
| 52 | |
| 53 | test( 'doesnt wrap tables that are not wikitables', () => { |
| 54 | document.body.innerHTML = ` |
| 55 | <div class="mw-parser-output"> |
| 56 | <table> |
| 57 | <tbody> |
| 58 | <tr><th>table table table</th></tr> |
| 59 | <tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr> |
| 60 | </tbody> |
| 61 | </table> |
| 62 | <div> |
| 63 | `; |
| 64 | tables(); |
| 65 | |
| 66 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 67 | } ); |
| 68 | |
| 69 | test( 'doesnt wrap tables that already have noresize', () => { |
| 70 | document.body.innerHTML = ` |
| 71 | <div class="mw-parser-output"> |
| 72 | <div class="noresize"> |
| 73 | <table class="wikitable"> |
| 74 | <tbody> |
| 75 | <tr><th>table table table</th></tr> |
| 76 | </tbody> |
| 77 | </table> |
| 78 | </div> |
| 79 | </div> |
| 80 | `; |
| 81 | tables(); |
| 82 | |
| 83 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 84 | } ); |
| 85 | |
| 86 | test( 'doesnt wrap tables that are already wrapped', () => { |
| 87 | document.body.innerHTML = ` |
| 88 | <div class="mw-parser-output"> |
| 89 | <div> |
| 90 | <table class="wikitable"> |
| 91 | <tbody> |
| 92 | <tr><th>table table table</th></tr> |
| 93 | </tbody> |
| 94 | </table> |
| 95 | </div> |
| 96 | </div> |
| 97 | `; |
| 98 | tables(); |
| 99 | |
| 100 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 101 | } ); |
| 102 | |
| 103 | test( 'doesnt wrap floated tables', () => { |
| 104 | document.body.innerHTML = ` |
| 105 | <div class="mw-parser-output"> |
| 106 | <table class="wikitable" style="float:right"> |
| 107 | <tbody> |
| 108 | <tr><th>table table table</th></tr> |
| 109 | </tbody> |
| 110 | </table> |
| 111 | <div> |
| 112 | `; |
| 113 | tables(); |
| 114 | |
| 115 | expect( document.body.innerHTML ).toMatchSnapshot(); |
| 116 | } ); |
| 117 | } ); |