2024-05-24 16:15:14 +00:00
|
|
|
const tables = require( '../../../resources/skins.vector.js/tables.js' ).init;
|
|
|
|
|
|
|
|
describe( 'tables', () => {
|
|
|
|
test( 'wraps table with div', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<section class="mw-parser-output">
|
2024-05-28 21:36:07 +00:00
|
|
|
<table class="wikitable">
|
2024-05-24 16:15:14 +00:00
|
|
|
<tbody><tr><th>table table table</th></tr></tbody>
|
|
|
|
</table>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'wraps multiple table with div', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<section class="mw-parser-output">
|
2024-05-29 18:38:19 +00:00
|
|
|
<table class="wikitable">
|
|
|
|
<tbody><tr><th>table table table</th></tr></tbody>
|
|
|
|
</table>
|
|
|
|
<table class="wikitable">
|
2024-05-28 21:36:07 +00:00
|
|
|
<table class="wikitable">
|
2024-05-24 16:15:14 +00:00
|
|
|
<tbody><tr><th>table table table</th></tr></tbody>
|
|
|
|
</table>
|
2024-05-28 21:36:07 +00:00
|
|
|
<table class="wikitable">
|
2024-05-24 16:15:14 +00:00
|
|
|
<tbody><tr><th>table table table</th></tr></tbody>
|
|
|
|
</table>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'doesnt wrap nested tables', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<section class="mw-parser-output">
|
2024-05-28 21:36:07 +00:00
|
|
|
<table class="wikitable">
|
2024-05-24 16:15:14 +00:00
|
|
|
<tbody>
|
|
|
|
<tr><th>table table table</th></tr>
|
2024-05-29 18:38:19 +00:00
|
|
|
<tr><td><table class="wikitable"><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
2024-05-24 16:15:14 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-05-29 18:38:19 +00:00
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
2024-05-24 16:15:14 +00:00
|
|
|
|
2024-05-29 18:38:19 +00:00
|
|
|
test( 'only wraps wikitables', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<section class="mw-parser-output">
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr><th>table table table</th></tr>
|
|
|
|
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-05-24 16:15:14 +00:00
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
2024-05-28 21:36:07 +00:00
|
|
|
|
|
|
|
test( 'doesnt wrap tables that are not wikitables', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr><th>table table table</th></tr>
|
|
|
|
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'doesnt wrap tables that are already wrapped', () => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<div class="mw-parser-output">
|
|
|
|
<div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr><th>table table table</th></tr>
|
|
|
|
<tr><td><table><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
tables();
|
|
|
|
|
|
|
|
expect( document.body.innerHTML ).toMatchSnapshot();
|
|
|
|
} );
|
2024-05-24 16:15:14 +00:00
|
|
|
} );
|