test-media-widgets.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* globals wp, Backbone */
  2. /* jshint qunit: true */
  3. /* eslint-env qunit */
  4. ( function() {
  5. 'use strict';
  6. QUnit.module( 'Media Widgets' );
  7. QUnit.test( 'namespace', function( assert ) {
  8. assert.equal( typeof wp.mediaWidgets, 'object', 'wp.mediaWidgets is an object' );
  9. assert.equal( typeof wp.mediaWidgets.controlConstructors, 'object', 'wp.mediaWidgets.controlConstructors is an object' );
  10. assert.equal( typeof wp.mediaWidgets.modelConstructors, 'object', 'wp.mediaWidgets.modelConstructors is an object' );
  11. assert.equal( typeof wp.mediaWidgets.widgetControls, 'object', 'wp.mediaWidgets.widgetControls is an object' );
  12. assert.equal( typeof wp.mediaWidgets.handleWidgetAdded, 'function', 'wp.mediaWidgets.handleWidgetAdded is an function' );
  13. assert.equal( typeof wp.mediaWidgets.handleWidgetUpdated, 'function', 'wp.mediaWidgets.handleWidgetUpdated is an function' );
  14. assert.equal( typeof wp.mediaWidgets.init, 'function', 'wp.mediaWidgets.init is an function' );
  15. });
  16. QUnit.test( 'media widget control', function( assert ) {
  17. assert.equal( typeof wp.mediaWidgets.MediaWidgetControl, 'function', 'wp.mediaWidgets.MediaWidgetControl' );
  18. assert.ok( wp.mediaWidgets.MediaWidgetControl.prototype instanceof Backbone.View, 'wp.mediaWidgets.MediaWidgetControl subclasses Backbone.View' );
  19. });
  20. QUnit.test( 'media widget model', function( assert ) {
  21. var widgetModelInstance;
  22. assert.equal( typeof wp.mediaWidgets.MediaWidgetModel, 'function', 'wp.mediaWidgets.MediaWidgetModel is a function' );
  23. assert.ok( wp.mediaWidgets.MediaWidgetModel.prototype instanceof Backbone.Model, 'wp.mediaWidgets.MediaWidgetModel subclasses Backbone.Model' );
  24. widgetModelInstance = new wp.mediaWidgets.MediaWidgetModel();
  25. assert.equal( widgetModelInstance.get( 'title' ), '', 'wp.mediaWidgets.MediaWidgetModel defaults title to empty string' );
  26. assert.equal( widgetModelInstance.get( 'attachment_id' ), 0, 'wp.mediaWidgets.MediaWidgetModel defaults attachment_id to 0' );
  27. assert.equal( widgetModelInstance.get( 'url' ), 0, 'wp.mediaWidgets.MediaWidgetModel defaults url to empty string' );
  28. widgetModelInstance.set({
  29. title: 'chicken and ribs',
  30. attachment_id: '1',
  31. url: 'https://wordpress.org'
  32. });
  33. assert.equal( widgetModelInstance.get( 'title' ), 'chicken and ribs', 'wp.mediaWidgets.MediaWidgetModel properly sets the title attribute' );
  34. assert.equal( widgetModelInstance.get( 'url' ), 'https://wordpress.org', 'wp.mediaWidgets.MediaWidgetModel properly sets the url attribute' );
  35. assert.equal( widgetModelInstance.get( 'attachment_id' ), 1, 'wp.mediaWidgets.MediaWidgetModel properly sets and casts the attachment_id attribute' );
  36. });
  37. })();