作業中のwordpressプラグインのjavascriptコードベース全体をリファクタリングして、単体テストを実行できるようにする必要があります。開始する場所を探していました。ユニットテストを適切に行うにはMVCフレームワークの使用を開始する必要があることを理解しており、少し「キックスタート」が必要でした。非常に基本的なjQueryAJAX呼び出しがあるとすると、ユニットをテストできるように、MVCフレームワークで同じコードをどのように記述しますか?
// Refreshes the multiselect with data from facebook.
$( '.ai1ec-facebook-refresh-multiselect' ).click( function( e ) {
e.preventDefault();
// Find the spinner and show it
$( this ).closest( '.ai1ec-facebook-multiselect-title-wrapper' )
.find( '.ajax-loading' )
.css( 'visibility', 'visible' );
var type = $( this ).closest( '.ai1ec-facebook-multiselect-container' ).data( 'type' );
var that = this;
var data = {
"action" : 'ai1ec_refresh_facebook_objects',
"ai1ec_type" : type
}
$.post(
ajaxurl,
data,
function( response ) {
$( that ).closest( '.ai1ec-facebook-multiselect-title-wrapper' )
.find( '.ajax-loading' )
.css( 'visibility', 'hidden' );
if ( response.errors === true ) {
var alert = AI1EC_UTILS.make_alert( response.error_messages.join( '<br/>'), 'error' );
$( '#alerts' ).append( $alert );
return;
}
$( ' .ai1ec-facebook-multiselect-container[data-type=' + type + '] .ai1ec-facebook-multiselect ').replaceWith( response.html );
var $ok_alert = AI1EC_UTILS.make_alert( response.message, 'success' );
$( '#alerts' ).append( $ok_alert );
},
'json'
);
} );
javascriptMVCの例ならどれでも完璧です。