/* * This file is part of the MediaWiki extension MediaViewer. * * MediaViewer is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MediaViewer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MediaViewer. If not, see . */ ( function () { QUnit.module( 'mmv.HtmlUtils', QUnit.newMwEnvironment() ); QUnit.test( 'wrapAndJquerify() for single node', function ( assert ) { var utils = new mw.mmv.HtmlUtils(), $el = $( '' ), el = $( '' ).get( 0 ), html = '', invalid = {}; assert.strictEqual( utils.wrapAndJquerify( $el ).html(), '', 'jQuery' ); assert.strictEqual( utils.wrapAndJquerify( el ).html(), '', 'HTMLElement' ); assert.strictEqual( utils.wrapAndJquerify( html ).html(), '', 'HTML string' ); try { utils.wrapAndJquerify( invalid ); } catch ( e ) { assert.ok( e, 'throws exception for invalid type' ); } } ); QUnit.test( 'wrapAndJquerify() for multiple nodes', function ( assert ) { var utils = new mw.mmv.HtmlUtils(), $el = $( '' ), html = ''; assert.strictEqual( utils.wrapAndJquerify( $el ).html(), '', 'jQuery' ); assert.strictEqual( utils.wrapAndJquerify( html ).html(), '', 'HTML string' ); } ); QUnit.test( 'wrapAndJquerify() for text', function ( assert ) { var utils = new mw.mmv.HtmlUtils(), $el = $( document.createTextNode( 'foo' ) ), html = 'foo'; assert.strictEqual( utils.wrapAndJquerify( $el ).html(), 'foo', 'jQuery' ); assert.strictEqual( utils.wrapAndJquerify( html ).html(), 'foo', 'HTML string' ); } ); QUnit.test( 'wrapAndJquerify() does not change original', function ( assert ) { var utils = new mw.mmv.HtmlUtils(), $el = $( '' ), el = $( '' ).get( 0 ); utils.wrapAndJquerify( $el ).find( 'span' ).prop( 'data-x', 1 ); utils.wrapAndJquerify( el ).find( 'span' ).prop( 'data-x', 1 ); assert.strictEqual( $el.prop( 'data-x' ), undefined, 'wrapped jQuery element is not the same as original' ); assert.strictEqual( $( el ).prop( 'data-x' ), undefined, 'wrapped HTMLElement is not the same as original' ); } ); QUnit.test( 'filterInvisible()', function ( assert ) { var utils = new mw.mmv.HtmlUtils(), $visibleChild = $( '
' ), $invisibleChild = $( '
' ), $styleChild = $( '
' ), $invisibleChildInVisibleChild = $( '
' ), $visibleChildInInvisibleChild = $( '
' ), $invisibleChildWithVisibleSiblings = $( '
' ); utils.filterInvisible( $visibleChild ); utils.filterInvisible( $invisibleChild ); utils.filterInvisible( $styleChild ); utils.filterInvisible( $invisibleChildInVisibleChild ); utils.filterInvisible( $visibleChildInInvisibleChild ); utils.filterInvisible( $invisibleChildWithVisibleSiblings ); assert.ok( $visibleChild.has( 'span' ).length, 'visible child is not filtered' ); assert.notOk( $invisibleChild.has( 'span' ).length, 'invisible child is filtered' ); assert.notOk( $styleChild.has( 'style' ).length, '