WordPress.org

Make WordPress Core

Changeset 40109


Ignore:
Timestamp:
02/24/2017 06:39:39 PM (15 months ago)
Author:
adamsilverstein
Message:

REST API: JS client - QUnit tests for custom namespace route discovery.

Add QUnit tests for the parsing of custom namespace routes. Add a custom schema fixture based on the wp-js-widgets plugin. Test that the client can parse the widget namespace in the schema and correctly construct the expected group of models and collections. Also includes a small unrelated QUnit fix to ensure nav-menu test passes when it is loaded without its tests executing as well as a small jshint fix, adding a missing semicolon since [40107].

Props jnylen0.
Fixes #39561.

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/theme.js

    r40107 r40109  
    19291929                self.view.collection.once( 'query:success', function() {
    19301930                    $( 'div[data-slug="' + slug + '"]' ).trigger( 'click' );
    1931                 })
     1931                });
    19321932
    19331933            }
  • trunk/tests/qunit/fixtures/wp-api.js

    r40058 r40109  
    1 /* global mockedApiResponse, Backbone */
     1/* global mockedApiResponse, Backbone, jsWidgetsEndpointSchema */
    22/**
    33 * @var mockedApiResponse defined in wp-api-generated.js
     
    2424    'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel,
    2525    'wp-json/wp/v2/status': mockedApiResponse.StatusModel,
    26     'wp-json/wp/v2/type': mockedApiResponse.TypeModel
     26    'wp-json/wp/v2/type': mockedApiResponse.TypeModel,
     27    'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema
    2728};
    2829
  • trunk/tests/qunit/index.html

    r40058 r40109  
    4141            <script src="fixtures/customize-widgets.js"></script>
    4242            <script src="fixtures/wp-api-generated.js"></script>
     43            <script src="fixtures/js-widgets-endpoint.js"></script>
    4344            <script src="fixtures/wp-api.js"></script>
    4445        </div>
  • trunk/tests/qunit/wp-admin/js/nav-menu.js

    r39928 r40109  
    88    // Fail if we don't see the expected number of events triggered in 1500 ms.
    99    setTimeout( function() {
    10         assert.equal(
     10        // QUnit may load this file without running it, in which case `assert`
     11        // will never be set to `assertPassed` below.
     12        assert && assert.equal(
    1113            eventsFired,
    1214            eventsExpected,
  • trunk/tests/qunit/wp-includes/js/wp-api.js

    r40058 r40109  
    193193    } );
    194194
     195// Test the jswidget custom namespace and endpoints.
     196wp.api.init( {
     197    'versionString': 'js-widgets/v1/'
     198} ).done( function() {
     199        var customClasses = [
     200            'WidgetsArchives',
     201            'WidgetsCalendar',
     202            'WidgetsCategories',
     203            'WidgetsMeta',
     204            'WidgetsNav_menu',
     205            'WidgetsPages',
     206            'WidgetsPostCollection',
     207            'WidgetsRecentComments',
     208            'WidgetsRecentPosts',
     209            'WidgetsRss',
     210            'WidgetsSearch',
     211            'WidgetsTag_cloud',
     212            'WidgetsText'
     213        ];
     214
     215        // Check that we have and can get each model type.
     216        _.each( customClasses, function( className ) {
     217            QUnit.test( 'Checking ' + className + ' class name.' , function( assert ) {
     218                var done = assert.async();
     219
     220                assert.expect( 2 );
     221
     222                wp.api.loadPromise.done( function() {
     223                    var theModel = new wp.api.models[ className ]();
     224                    assert.ok( theModel, 'We can instantiate wp.api.models.' + className );
     225                    var theCollection = new wp.api.collections[ className ]();
     226                    assert.ok( theCollection, 'We can instantiate wp.api.collections.' + className );
     227                    // Trigger Qunit async completion.
     228                    done();
     229                } );
     230            } );
     231        } );
     232
     233    } );
     234
    195235} )( window.QUnit );
Note: See TracChangeset for help on using the changeset viewer.