Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:32:03+00:00 2026-06-04T16:32:03+00:00

I need to refactor the whole javascript codebase of the wordpress plugin i’m working

  • 0

I need to refactor the whole javascript codebase of the wordpress plugin i’m working on so that i can run unit test on it and i was looking for a place to start. I understand that i need to start using a MVC framework to do unit testing properly and i wanted a little “kick-start”. Suppose i have a very basic jQuery AJAX call, how would you write the same code in a MVC framework so that it’s unit testable?

// 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'
    );
} );

Any javascript MVC example would be perfect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:32:05+00:00Added an answer on June 4, 2026 at 4:32 pm

    There is not any association between using a MVC framework and having a testable code.

    Neither there is a reason for thinking a non MVC framework based code can not be very testable.

    It is completely possible to move all this code into a MVC implementation and having a result as tedious to test as this one.

    The problem I’m seeing in the example code you showed to us is that it lacks in modularity. I’m not very pattern religious but maybe we can talk about Single responsibility here.

    What I recommend here is to create isolated methods for all the logic there, organize them, put them into a Class or Utils module, then you will see how easy is to test them, in insolation and in collaboration.

    Once you achieve this you can move to a MVC or not, but only because the testability of the code it is not a reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with some legacy C code which I need to refactor and
I need to refactor my project in order to make it immune to OutOfMemory
I am probably going to need to refactor in two steps since I'm still
I am trying to refactor a working code. The code basically derives an interface
So the site I'm working on has a filter system that operates by passing
I have been perpetually intrigued by test-driven development, but I can never follow through
I'm looking for ideas on the best way to refactor this scenario (better design,
I need to implement an application that is simultaneously communicating with multiple clients using
So I have this query written by someone else that I'm trying to refactor,
I need to refactor this code to not use a parameter when using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.