mediawiki-skins-Vector/tests/jest/skins.vector.js/tables.test.js
bwang 711f67ce00 Avoid wrapping floated tables using computed styles
Bug: T366314
Change-Id: I71657b7f1f26bcf52f5ade5b7668955a1f4df24b
2024-06-07 16:49:30 +00:00

97 lines
2.3 KiB
JavaScript

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">
<table class="wikitable">
<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">
<table class="wikitable">
<tbody><tr><th>table table table</th></tr></tbody>
</table>
<table class="wikitable">
<table class="wikitable">
<tbody><tr><th>table table table</th></tr></tbody>
</table>
<table class="wikitable">
<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">
<table class="wikitable">
<tbody>
<tr><th>table table table</th></tr>
<tr><td><table class="wikitable"><tbody><tr><th>table table table</th></tr></tbody></table><td></tr>
</tbody>
</table>
</section>
`;
tables();
expect( document.body.innerHTML ).toMatchSnapshot();
} );
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 class="noresize">
<table class="wikitable">
<tbody>
<tr><th>table table table</th></tr>
</tbody>
</table>
</div>
</div>
`;
tables();
expect( document.body.innerHTML ).toMatchSnapshot();
} );
test( 'doesnt wrap floated tables', () => {
document.body.innerHTML = `
<table class="wikitable" style="float:right">
<tbody>
<tr><th>table table table</th></tr>
</tbody>
</table>
`;
tables();
expect( document.body.innerHTML ).toMatchSnapshot();
} );
} );