Wordpress/tests/qunit/wp-admin/js/widgets/test-media-video-widget.js
Weston Ruter da32c2f630 Widgets: Introduce media widgets for images, audio, and video with extensible base for additional media widgets in the future.
The last time a new widget was introduced, Vuvuzelas were a thing, Angry Birds started taking over phones, and WordPress stopped shipping with Kubrick. Seven years and 17 releases without new widgets have been enough, time to spice up your sidebar!

Props westonruter, melchoyce, obenland, timmydcrawford, adamsilverstein, gonom9, wonderboymusic, Fab1en, DrewAPicture, sirbrillig, joen, matias, samikeijonen, afercia, celloexpressions, designsimply, michelleweber, ranh, kjellr, karmatosed.
Fixes #32417, #39993, #39994, #39995.


git-svn-id: https://develop.svn.wordpress.org/trunk@40640 602fd350-edb4-49c9-b593-d223f7449a82
2017-05-11 21:10:54 +00:00

69 lines
3.5 KiB
JavaScript

/* globals wp */
/* jshint qunit: true */
/* eslint-env qunit */
/* eslint-disable no-magic-numbers */
( function() {
'use strict';
module( 'Video Media Widget' );
test( 'video widget control', function() {
var VideoWidgetControl, videoWidgetControlInstance, videoWidgetModelInstance, mappedProps, testVideoUrl;
testVideoUrl = 'https://videos.files.wordpress.com/AHz0Ca46/wp4-7-vaughan-r8-mastered_hd.mp4';
equal( typeof wp.mediaWidgets.controlConstructors.media_video, 'function', 'wp.mediaWidgets.controlConstructors.media_video is a function' );
VideoWidgetControl = wp.mediaWidgets.controlConstructors.media_video;
ok( VideoWidgetControl.prototype instanceof wp.mediaWidgets.MediaWidgetControl, 'wp.mediaWidgets.controlConstructors.media_video subclasses wp.mediaWidgets.MediaWidgetControl' );
videoWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_video();
videoWidgetControlInstance = new VideoWidgetControl({
model: videoWidgetModelInstance
});
// Test mapModelToMediaFrameProps().
videoWidgetControlInstance.model.set({ error: false, url: testVideoUrl, loop: false, preload: 'meta' });
mappedProps = videoWidgetControlInstance.mapModelToMediaFrameProps( videoWidgetControlInstance.model.toJSON() );
equal( mappedProps.url, testVideoUrl, 'mapModelToMediaFrameProps should set url' );
equal( mappedProps.loop, false, 'mapModelToMediaFrameProps should set loop' );
equal( mappedProps.preload, 'meta', 'mapModelToMediaFrameProps should set preload' );
// Test mapMediaToModelProps().
mappedProps = videoWidgetControlInstance.mapMediaToModelProps( { loop: false, preload: 'meta', url: testVideoUrl, title: 'random movie file title' } );
equal( mappedProps.title, undefined, 'mapMediaToModelProps should ignore title inputs' );
equal( mappedProps.loop, false, 'mapMediaToModelProps should set loop' );
equal( mappedProps.preload, 'meta', 'mapMediaToModelProps should set preload' );
});
test( 'video widget control renderPreview', function( assert ) {
var videoWidgetControlInstance, videoWidgetModelInstance, done;
done = assert.async();
videoWidgetModelInstance = new wp.mediaWidgets.modelConstructors.media_video();
videoWidgetControlInstance = new wp.mediaWidgets.controlConstructors.media_video({
model: videoWidgetModelInstance
});
equal( videoWidgetControlInstance.$el.find( 'a' ).length, 0, 'No video links should be rendered' );
videoWidgetControlInstance.model.set({ error: false, url: 'https://videos.files.wordpress.com/AHz0Ca46/wp4-7-vaughan-r8-mastered_hd.mp4' });
// Due to renderPreview being deferred.
setTimeout( function() {
equal( videoWidgetControlInstance.$el.find( 'a[href="https://videos.files.wordpress.com/AHz0Ca46/wp4-7-vaughan-r8-mastered_hd.mp4"]' ).length, 1, 'One video link should be rendered' );
done();
}, 50 );
start();
});
test( 'video media model', function() {
var VideoWidgetModel, videoWidgetModelInstance;
equal( typeof wp.mediaWidgets.modelConstructors.media_video, 'function', 'wp.mediaWidgets.modelConstructors.media_video is a function' );
VideoWidgetModel = wp.mediaWidgets.modelConstructors.media_video;
ok( VideoWidgetModel.prototype instanceof wp.mediaWidgets.MediaWidgetModel, 'wp.mediaWidgets.modelConstructors.media_video subclasses wp.mediaWidgets.MediaWidgetModel' );
videoWidgetModelInstance = new VideoWidgetModel();
_.each( videoWidgetModelInstance.attributes, function( value, key ) {
equal( value, VideoWidgetModel.prototype.schema[ key ][ 'default' ], 'Should properly set default for ' + key );
});
});
})();