MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/181169
Change subject: Add tests for mw.fileApi
......................................................................
Add tests for mw.fileApi
Change-Id: I000685dce47d4d4ea448a8f8c1871ee818aea175
---
M UploadWizardHooks.php
A tests/qunit/mw.fileApi.test.js
2 files changed, 113 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/69/181169/1
diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php
index 403f261..43a137c 100644
--- a/UploadWizardHooks.php
+++ b/UploadWizardHooks.php
@@ -908,6 +908,7 @@
'tests/qunit/mw.FlickrChecker.test.js',
'tests/qunit/mw.UploadWizardDetails.test.js',
'tests/qunit/mw.UtilitiesTime.test.js',
+ 'tests/qunit/mw.fileApi.test.js',
),
'dependencies' => array(
'ext.uploadWizard',
diff --git a/tests/qunit/mw.fileApi.test.js b/tests/qunit/mw.fileApi.test.js
new file mode 100644
index 0000000..a99c906
--- /dev/null
+++ b/tests/qunit/mw.fileApi.test.js
@@ -0,0 +1,112 @@
+/*
+ * This file is part of the MediaWiki extension UploadWizard.
+ *
+ * UploadWizard 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.
+ *
+ * UploadWizard 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 UploadWizard. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+( function ( mw ) {
+ QUnit.module( 'mw.fileApi', QUnit.newMwEnvironment() );
+
+ QUnit.test( 'isAvailable', 2, function ( assert ) {
+ var oldFileReader = window.FileReader;
+
+ window.FileReader = undefined;
+ assert.strictEqual( mw.fileApi.isAvailable(), false );
+
+ window.FileReader = {};
+ assert.strictEqual( mw.fileApi.isAvailable(), true );
+
+ window.FileReader = oldFileReader;
+ } );
+
+ QUnit.test( 'isPreviewableFile', 6, function ( assert ) {
+ var testFile = {};
+
+ testFile.type = 'image/png';
+ testFile.size = 5 * 1024 * 1024;
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
true );
+
+ testFile.type = 'image/gif';
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
true );
+
+ testFile.type = 'image/jpeg';
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
true );
+
+ testFile.size = 11 * 1024 * 1024;
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
false );
+
+ testFile.size = 5 * 1024 * 1024;
+ testFile.type = 'unplayable/type';
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
false );
+
+ this.sandbox.stub( mw.fileApi, 'isPreviewableVideo' ).returns(
true );
+ assert.strictEqual( mw.fileApi.isPreviewableFile( testFile ),
true );
+ } );
+
+ QUnit.test( 'isPreviewableVideo', 6, function ( assert ) {
+ var cestub,
+ testFile = {},
+ fakeVideo = {
+ canPlayType: this.sandbox.stub().returns( 'yes'
)
+ };
+
+ cestub = this.sandbox.stub( document, 'createElement'
).returns( fakeVideo );
+
+ assert.strictEqual( mw.fileApi.isPreviewableVideo( testFile ),
true );
+ assert.strictEqual( cestub.called, true );
+ assert.strictEqual( fakeVideo.canPlayType.callCount, 1 );
+
+ fakeVideo.canPlayType = this.sandbox.stub().returns( 'no' );
+ assert.strictEqual( mw.fileApi.isPreviewableVideo( testFile ),
false );
+ assert.strictEqual( cestub.called, true );
+ assert.strictEqual( fakeVideo.canPlayType.callCount, 1 );
+ } );
+
+ QUnit.test( 'isFormDataAvailable', 6, function ( assert ) {
+ var oldfd = window.FormData,
+ oldf = window.File;
+
+ window.FormData = undefined;
+ window.File = undefined;
+
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), false );
+
+ window.File = { prototype: {} };
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), false );
+
+ window.FormData = {};
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), false );
+
+ window.File = {
+ prototype: {
+ slice: function () {}
+ }
+ };
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), true );
+
+ window.File = undefined;
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), false );
+
+ window.FormData = undefined;
+ window.File = {
+ prototype: {
+ slice: function () {}
+ }
+ };
+ assert.strictEqual( mw.fileApi.isFormDataAvailable(), false );
+
+ window.FormData = oldfd;
+ window.File = oldf;
+ } );
+}( mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/181169
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I000685dce47d4d4ea448a8f8c1871ee818aea175
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits