summaryrefslogtreecommitdiff
path: root/vendor/oojs/oojs-ui/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/oojs/oojs-ui/tests')
-rw-r--r--vendor/oojs/oojs-ui/tests/Element.test.js52
-rw-r--r--vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js61
-rw-r--r--vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js55
-rw-r--r--vendor/oojs/oojs-ui/tests/Process.test.js179
-rw-r--r--vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js113
-rw-r--r--vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js64
-rw-r--r--vendor/oojs/oojs-ui/tests/index.php77
7 files changed, 601 insertions, 0 deletions
diff --git a/vendor/oojs/oojs-ui/tests/Element.test.js b/vendor/oojs/oojs-ui/tests/Element.test.js
new file mode 100644
index 00000000..b37d8e35
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/Element.test.js
@@ -0,0 +1,52 @@
+QUnit.module( 'Element', {
+ setup: function () {
+ this.fixture = document.createElement( 'div' );
+ document.body.appendChild( this.fixture );
+
+ this.makeFrame = function () {
+ var frame = document.createElement( 'iframe' );
+ this.fixture.appendChild( frame );
+ return ( frame.contentWindow && frame.contentWindow.document ) || frame.contentDocument;
+ };
+ },
+ teardown: function () {
+ this.fixture.parentNode.removeChild( this.fixture );
+ this.fixture = null;
+ }
+} );
+
+QUnit.test( 'static.getDocument', 10, function ( assert ) {
+ var frameDoc, frameEl, frameDiv,
+ el = this.fixture,
+ div = document.createElement( 'div' ),
+ $el = $( this.fixture ),
+ $div = $( '<div>' ),
+ win = window,
+ doc = document;
+
+ frameDoc = this.makeFrame();
+ frameEl = frameDoc.createElement( 'span' );
+ frameDoc.documentElement.appendChild( frameEl );
+ frameDiv = frameDoc.createElement( 'div' );
+
+ assert.strictEqual( OO.ui.Element.static.getDocument( $el ), doc, 'jQuery' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( $div ), doc, 'jQuery (detached)' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( el ), doc, 'HTMLElement' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( div ), doc, 'HTMLElement (detached)' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( win ), doc, 'Window' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( doc ), doc, 'HTMLDocument' );
+
+ assert.strictEqual( OO.ui.Element.static.getDocument( frameEl ), frameDoc, 'HTMLElement (framed)' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( frameDiv ), frameDoc, 'HTMLElement (framed, detached)' );
+ assert.strictEqual( OO.ui.Element.static.getDocument( frameDoc ), frameDoc, 'HTMLDocument (framed)' );
+
+ assert.strictEqual( OO.ui.Element.static.getDocument( {} ), null, 'Invalid' );
+} );
+
+QUnit.test( 'getElementDocument', 1, function ( assert ) {
+ var el, doc;
+
+ doc = document;
+ el = new OO.ui.Element();
+ assert.strictEqual( el.getElementDocument(), doc );
+} );
diff --git a/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js b/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js
new file mode 100644
index 00000000..1a1473c1
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/JSPHP.test.karma.js
@@ -0,0 +1,61 @@
+QUnit.module( 'JSPHP' );
+
+( function () {
+ // Generate some tests based on the test suite data and HTML from PHP version.
+ var theme, klassName,
+ themes = {
+ ApexTheme: new OO.ui.ApexTheme(),
+ MediaWikiTheme: new OO.ui.MediaWikiTheme()
+ };
+
+ function unstub( value ) {
+ var config;
+ if ( typeof value === 'string' && value.substr( 0, 13 ) === '_placeholder_' ) {
+ value = JSON.parse( value.substr( 13 ) );
+ config = OO.copy( value.config, null, unstub );
+ return new OO.ui[ value.class ]( config );
+ }
+ }
+
+ function makeTest( theme, klassName, tests, output ) {
+ QUnit.test( theme + ': ' + klassName, tests.length * 2, function ( assert ) {
+ var test, config, instance, infused, $fromPhp, i, testName;
+ OO.ui.theme = themes[ theme ];
+ for ( i = 0; i < tests.length; i++ ) {
+ test = tests[ i ];
+ // Unstub placeholders
+ config = OO.copy( test.config, null, unstub );
+
+ instance = new OO.ui[ test.class ]( config );
+ $fromPhp = $( $.parseHTML( output[ i ] ) );
+
+ $( 'body' ).append( instance.$element, $fromPhp );
+
+ // Updating theme classes is normally debounced, we need to do it immediately
+ instance.debouncedUpdateThemeClasses();
+
+ testName = JSON.stringify( test.config );
+ assert.equalDomElement( instance.$element[ 0 ], $fromPhp[ 0 ], testName, true );
+
+ infused = OO.ui.infuse( $fromPhp[ 0 ] );
+ infused.debouncedUpdateThemeClasses();
+
+ assert.equalDomElement( instance.$element[ 0 ], infused.$element[ 0 ], testName + ' (infuse)' );
+ instance.$element.add( infused.$element ).detach();
+ }
+ } );
+ }
+
+ /*global testSuiteConfigs, testSuitePHPOutput */
+ for ( klassName in testSuiteConfigs ) {
+ for ( theme in themes ) {
+ makeTest(
+ theme,
+ klassName,
+ testSuiteConfigs[ klassName ],
+ testSuitePHPOutput[ theme ][ klassName ]
+ );
+ }
+ }
+
+} )();
diff --git a/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js b/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js
new file mode 100644
index 00000000..1cbebc3a
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/JSPHP.test.standalone.js
@@ -0,0 +1,55 @@
+QUnit.module( 'JSPHP' );
+
+( function () {
+ // Generate some tests based on the test suite data and HTML from PHP version.
+ var theme, klassName,
+ themes = {
+ ApexTheme: new OO.ui.ApexTheme(),
+ MediaWikiTheme: new OO.ui.MediaWikiTheme()
+ };
+
+ function unstub( value ) {
+ var config;
+ if ( typeof value === 'string' && value.substr( 0, 13 ) === '_placeholder_' ) {
+ value = JSON.parse( value.substr( 13 ) );
+ config = OO.copy( value.config, null, unstub );
+ return new OO.ui[ value.class ]( config );
+ }
+ }
+
+ function makeTest( theme, klassName, tests ) {
+ QUnit.test( theme + ': ' + klassName, tests.length * 2, function ( assert ) {
+ var test, config, instance, infused, id, fromPhp, i, testName;
+ OO.ui.theme = themes[ theme ];
+ for ( i = 0; i < tests.length; i++ ) {
+ test = tests[ i ];
+ // Unstub placeholders
+ config = OO.copy( test.config, null, unstub );
+
+ instance = new OO.ui[ test.class ]( config );
+
+ id = 'JSPHPTestSuite_' + theme + klassName + i;
+ fromPhp = document.getElementById( id ).firstChild;
+ instance.$element.insertBefore( fromPhp );
+
+ // Updating theme classes is normally debounced, we need to do it immediately
+ instance.debouncedUpdateThemeClasses();
+
+ testName = JSON.stringify( test.config );
+ assert.equalDomElement( instance.$element[ 0 ], fromPhp, testName );
+
+ infused = OO.ui.infuse( fromPhp );
+ infused.debouncedUpdateThemeClasses();
+
+ assert.equalDomElement( instance.$element[ 0 ], infused.$element[ 0 ], testName + ' (infuse)' );
+ }
+ } );
+ }
+
+ for ( klassName in OO.ui.JSPHPTestSuite ) {
+ for ( theme in themes ) {
+ makeTest( theme, klassName, OO.ui.JSPHPTestSuite[ klassName ] );
+ }
+ }
+
+} )();
diff --git a/vendor/oojs/oojs-ui/tests/Process.test.js b/vendor/oojs/oojs-ui/tests/Process.test.js
new file mode 100644
index 00000000..3f036407
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/Process.test.js
@@ -0,0 +1,179 @@
+QUnit.module( 'OO.ui.Process' );
+
+/* Tests */
+
+QUnit.test( 'next', 1, function ( assert ) {
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .next( function () {
+ result.push( 0 );
+ } )
+ .next( function () {
+ result.push( 1 );
+ } )
+ .next( function () {
+ result.push( 2 );
+ } )
+ .execute();
+
+ assert.deepEqual( result, [ 0, 1, 2 ], 'Steps can be added at the end' );
+} );
+
+QUnit.test( 'first', 1, function ( assert ) {
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .first( function () {
+ result.push( 0 );
+ } )
+ .first( function () {
+ result.push( 1 );
+ } )
+ .first( function () {
+ result.push( 2 );
+ } )
+ .execute();
+
+ assert.deepEqual( result, [ 2, 1, 0 ], 'Steps can be added at the beginning' );
+} );
+
+QUnit.asyncTest( 'execute (async)', 1, function ( assert ) {
+ // Async
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .next( function () {
+ var deferred = $.Deferred();
+
+ setTimeout( function () {
+ result.push( 1 );
+ deferred.resolve();
+ }, 10 );
+
+ return deferred.promise();
+ } )
+ .first( function () {
+ var deferred = $.Deferred();
+
+ setTimeout( function () {
+ result.push( 0 );
+ deferred.resolve();
+ }, 10 );
+
+ return deferred.promise();
+ } )
+ .next( function () {
+ result.push( 2 );
+ } );
+
+ process.execute().done( function () {
+ assert.deepEqual(
+ result,
+ [ 0, 1, 2 ],
+ 'Synchronous and asynchronous steps are executed in the correct order'
+ );
+ QUnit.start();
+ } );
+} );
+
+QUnit.asyncTest( 'execute (return false)', 1, function ( assert ) {
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .next( function () {
+ var deferred = $.Deferred();
+
+ setTimeout( function () {
+ result.push( 0 );
+ deferred.resolve();
+ }, 10 );
+
+ return deferred.promise();
+ } )
+ .next( function () {
+ result.push( 1 );
+ return false;
+ } )
+ .next( function () {
+ // Should never be run because previous step is rejected
+ result.push( 2 );
+ } );
+
+ process.execute().fail( function () {
+ assert.deepEqual(
+ result,
+ [ 0, 1 ],
+ 'Process is stopped when a step returns false'
+ );
+ QUnit.start();
+ } );
+} );
+
+QUnit.asyncTest( 'execute (async reject)', 1, function ( assert ) {
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .next( function () {
+ result.push( 0 );
+ } )
+ .next( function () {
+ var deferred = $.Deferred();
+
+ setTimeout( function () {
+ result.push( 1 );
+ deferred.reject();
+ }, 10 );
+
+ return deferred.promise();
+ } )
+ .next( function () {
+ // Should never be run because previous step is rejected
+ result.push( 2 );
+ } );
+
+ process.execute().fail( function () {
+ assert.deepEqual(
+ result,
+ [ 0, 1 ],
+ 'Process is stopped when a step returns a promise that is then rejected'
+ );
+ QUnit.start();
+ } );
+} );
+
+QUnit.asyncTest( 'execute (wait)', 1, function ( assert ) {
+ var process = new OO.ui.Process(),
+ result = [];
+
+ process
+ .next( function () {
+ result.push( 'A' );
+ return 10;
+ } )
+ .next( function () {
+ result.push( 'B' );
+ } );
+
+ // Steps defined above don't run until execute()
+ result.push( 'before' );
+
+ // Process yields between step A and B
+ setTimeout( function () {
+ result.push( 'yield' );
+ } );
+
+ process.execute().done( function () {
+ assert.deepEqual(
+ result,
+ [ 'before', 'A', 'yield', 'B' ],
+ 'Process is stopped when a step returns a promise that is then rejected'
+ );
+ QUnit.start();
+ } );
+} );
diff --git a/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js b/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js
new file mode 100644
index 00000000..f041c258
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/QUnit.assert.equalDomElement.js
@@ -0,0 +1,113 @@
+/*!
+ * A QUnit assertion to compare DOM node trees.
+ *
+ * Adapted from VisualEditor plugin for QUnit. Additionally supports comparing properties to
+ * attributes (for dynamically generated nodes) and order-insensitive comparison of classes on DOM
+ * nodes.
+ *
+ * @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
+ * @copyright 2011-2015 OOjs Team and other contributors
+ */
+
+( function ( QUnit ) {
+
+ /**
+ * Build a summary of an HTML element.
+ *
+ * Summaries include node name, text, attributes and recursive summaries of children.
+ * Used for serializing or comparing HTML elements.
+ *
+ * @private
+ * @param {HTMLElement} element Element to summarize
+ * @param {boolean} [includeHtml=false] Include an HTML summary for element nodes
+ * @return {Object} Summary of element.
+ */
+ function getDomElementSummary( element, includeHtml ) {
+ var i, name,
+ summary = {
+ type: element.nodeName.toLowerCase(),
+ // $( '<div><textarea>Foo</textarea></div>' )[0].textContent === 'Foo', which breaks
+ // comparisons :( childNodes are summarized anyway, this would just be a nicety
+ // text: element.textContent,
+ attributes: {},
+ children: []
+ };
+
+ if ( includeHtml && element.nodeType === Node.ELEMENT_NODE ) {
+ summary.html = element.outerHTML;
+ }
+
+ // Gather attributes
+ if ( element.attributes ) {
+ for ( i = 0; i < element.attributes.length; i++ ) {
+ name = element.attributes[ i ].name;
+ if ( name.substr( 0, 5 ) !== 'data-' && name !== 'id' ) {
+ summary.attributes[ name ] = element.attributes[ i ].value;
+ }
+ }
+ }
+
+ // Sort classes
+ if ( summary.attributes.class ) {
+ summary.attributes.class = summary.attributes.class.split( ' ' ).sort().join( ' ' );
+ }
+
+ // Gather certain properties and pretend they are attributes.
+ // Take note of casing differences.
+ if ( element.value !== undefined ) {
+ summary.attributes.value = element.value;
+ }
+ if ( element.readOnly !== undefined ) {
+ summary.attributes.readonly = element.readOnly;
+ }
+ if ( element.checked !== undefined ) {
+ summary.attributes.checked = element.checked;
+ }
+ if ( element.disabled !== undefined ) {
+ summary.attributes.disabled = element.disabled;
+ }
+ if ( element.tabIndex !== undefined ) {
+ summary.attributes.tabindex = element.tabIndex;
+ }
+
+ // Summarize children
+ if ( element.childNodes ) {
+ for ( i = 0; i < element.childNodes.length; i++ ) {
+ summary.children.push( getDomElementSummary( element.childNodes[ i ], includeHtml ) );
+ }
+ }
+
+ // Special handling for textareas, where we only want to account for the content as the 'value'
+ // property, never as childNodes or textContent
+ if ( summary.type === 'textarea' ) {
+ // summary.text = '';
+ summary.children = [];
+ }
+
+ return summary;
+ }
+
+ /**
+ * @method
+ * @static
+ */
+ QUnit.assert.equalDomElement = function ( actual, expected, message, stringify ) {
+ var actualSummary = getDomElementSummary( actual ),
+ expectedSummary = getDomElementSummary( expected ),
+ actualSummaryHtml = getDomElementSummary( actual, true ),
+ expectedSummaryHtml = getDomElementSummary( expected, true );
+
+ // When running with Karma, the objects are not nicely stringified in the output when the test
+ // fails, only showing "Expected: [object Object], Actual: [object Object]" instead. Running
+ // QUnit in browser does this, and stringifying causes double escaping in output.
+ if ( stringify ) {
+ actualSummaryHtml = JSON.stringify( actualSummaryHtml, null, 2 );
+ expectedSummaryHtml = JSON.stringify( expectedSummaryHtml, null, 2 );
+ }
+
+ QUnit.push(
+ QUnit.equiv( actualSummary, expectedSummary ), actualSummaryHtml, expectedSummaryHtml, message
+ );
+ };
+
+}( QUnit ) );
diff --git a/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js b/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js
new file mode 100644
index 00000000..f5c483ad
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/elements/FlaggedElement.test.js
@@ -0,0 +1,64 @@
+( function () {
+ QUnit.module( 'FlaggedElement' );
+
+ function TestElement( config ) {
+ TestElement.super.call( this, config );
+ OO.ui.FlaggedElement.call( this, config );
+ }
+ OO.inheritClass( TestElement, OO.ui.Widget );
+ OO.mixinClass( TestElement, OO.ui.FlaggedElement );
+
+ QUnit.test( 'constructor', 2, function ( assert ) {
+ var element;
+
+ element = new TestElement();
+ assert.deepEqual( element.getFlags(), [], 'No flags by default' );
+
+ element = new TestElement( {
+ flags: [ 'foo' ]
+ } );
+ assert.deepEqual( element.getFlags(), [ 'foo' ], 'Config option "flags"' );
+ } );
+
+ QUnit.test( 'getFlags', 2, function ( assert ) {
+ var element = new TestElement();
+
+ element.setFlags( 'foo' );
+ assert.deepEqual( element.getFlags(), [ 'foo' ], 'Flag was set' );
+
+ element.clearFlags();
+ assert.deepEqual( element.getFlags(), [], 'Flag was removed' );
+ } );
+
+ QUnit.test( 'hasFlag', 3, function ( assert ) {
+ var element = new TestElement();
+ assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag absent by default' );
+
+ element.setFlags( 'foo' );
+ assert.deepEqual( element.hasFlag( 'foo' ), true, 'Flag was set' );
+
+ element.clearFlags();
+ assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag was removed' );
+ } );
+
+ QUnit.test( 'clearFlags', 1, function ( assert ) {
+ var element = new TestElement();
+ element.setFlags( 'foo' );
+ element.clearFlags();
+ assert.deepEqual( element.hasFlag( 'foo' ), false, 'Flag was removed' );
+ } );
+
+ QUnit.test( 'setFlags', 5, function ( assert ) {
+ var element = new TestElement();
+ element.setFlags( 'foo' );
+ assert.deepEqual( element.hasFlag( 'foo' ), true, 'string' );
+
+ element.setFlags( [ 'bar', 'qux' ] );
+ assert.deepEqual( element.hasFlag( 'bar' ), true, 'array[ 0 ]' );
+ assert.deepEqual( element.hasFlag( 'qux' ), true, 'array[ 1 ]' );
+
+ element.setFlags( { bar: false, quux: true } );
+ assert.deepEqual( element.hasFlag( 'bar' ), false, 'object set' );
+ assert.deepEqual( element.hasFlag( 'quux' ), true, 'object remove' );
+ } );
+}() );
diff --git a/vendor/oojs/oojs-ui/tests/index.php b/vendor/oojs/oojs-ui/tests/index.php
new file mode 100644
index 00000000..d8e06835
--- /dev/null
+++ b/vendor/oojs/oojs-ui/tests/index.php
@@ -0,0 +1,77 @@
+<?php
+ $autoload = '../vendor/autoload.php';
+ if ( !file_exists( $autoload ) ) {
+ echo '<h1>Did you forget to run <code>composer install</code>?</h1>';
+ exit;
+ }
+ require_once $autoload;
+
+ $testSuiteFile = 'JSPHP-suite.json';
+ if ( !file_exists( $testSuiteFile ) ) {
+ echo '<h1>Did you forget to run <code>grunt build</code>?</h1>';
+ exit;
+ }
+ $testSuiteJSON = file_get_contents( $testSuiteFile );
+ $testSuite = json_decode( $testSuiteJSON, true );
+?>
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="UTF-8">
+ <title>OOjs UI Test Suite</title>
+ <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
+ <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
+ <script src="./QUnit.assert.equalDomElement.js"></script>
+ <script>
+ QUnit.config.requireExpects = true;
+ </script>
+ <!-- Dependencies -->
+ <script src="../node_modules/jquery/dist/jquery.js"></script>
+ <script src="../node_modules/oojs/dist/oojs.jquery.js"></script>
+ <!-- Source code -->
+ <script src="../dist/oojs-ui.js"></script>
+ <script src="../dist/oojs-ui-apex.js"></script>
+ <script src="../dist/oojs-ui-mediawiki.js"></script>
+ <!-- Test suites -->
+ <script src="./Element.test.js"></script>
+ <script src="./Process.test.js"></script>
+ <script src="./elements/FlaggedElement.test.js"></script>
+ <!-- JS/PHP comparison tests -->
+ <script>OO.ui.JSPHPTestSuite = <?php echo $testSuiteJSON; ?></script>
+ <script src="./JSPHP.test.standalone.js"></script>
+</head>
+<body>
+ <div id="JSPHPTestSuite" style="display: none;">
+ <?php
+ function new_OOUI( $class, $config = array() ) {
+ $class = "OOUI\\" . $class;
+ return new $class( $config );
+ }
+ function unstub( &$value ) {
+ if ( is_string( $value ) && substr( $value, 0, 13 ) === '_placeholder_' ) {
+ $value = json_decode( substr( $value, 13 ), true );
+ array_walk_recursive( $value['config'], 'unstub' );
+ $value = new_OOUI( $value['class'], $value['config'] );
+ }
+ }
+ // Keep synchronized with bin/generate-JSPHP-for-karma.php
+ $themes = array( 'ApexTheme', 'MediaWikiTheme' );
+ foreach ( $themes as $theme ) {
+ OOUI\Theme::setSingleton( new_OOUI( $theme ) );
+ foreach ( $testSuite as $className => $tests ) {
+ foreach ( $tests as $index => $test ) {
+ // Unstub placeholders
+ $config = $test['config'];
+ array_walk_recursive( $config, 'unstub' );
+ $config['infusable'] = true;
+ $instance = new_OOUI( $test['class'], $config );
+ echo "<div id='JSPHPTestSuite_$theme$className$index'>$instance</div>\n";
+ }
+ }
+ }
+ ?>
+ </div>
+ <div id="qunit"></div>
+ <div id="qunit-fixture"></div>
+</body>
+</html>