XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Major Major
    • None
    • 1.2
    • Unit tests
    • MOODLE_12_STABLE

      As discussed, we'd like to add unit-tests to the scripts in Moodle Mobile's lib directory, and suggest using [Jasmine](http://evanhahn.com/how-do-i-jasmine) as a test-runner.

      For the majority of the scripts we would add simple input/output tests.

      For the more complex functionality in mm.js, we would like to slightly re-factor the code to make testing easier. The proposed alterations are detailed below.

      We'd be delighted to here any thoughts or suggestions.

      Function: init

      Split into smaller functions:

      • setTouchHandlers
      • setDeviceType
      • setDeviceOS
      • setInComputerState
      • loadCordova
      • loadBackboneRouter
      • setUpAjaxErrorHandling
      • loadModels
      • loadSettings

      Add unit tests

      • Test that each function is called.
      • Test that each function sets properties correctly.
      • Test that MM.config is set.

      Function: deviceConnected

      Mock network states and test connection is reported correctly in each case.

      Function: loadLayout

      Split into smaller functions:

      • orientationChangeHandler
        Mock various heights and widths, test calculations.
      • mediaQueryChangeHandler
        Mock various MQs, test that the page is reloaded accordingly.
      • setUpTabletModeLayout, setUpPhoneModeLayout
        Mock MQs, test correct function is called.
      • setUpOverflowScrolling, setUpNativeScrolling, setUpJavascriptScrolling
        Mock device types, test correct function is called.

      Add unit tests

      • Test that backbone history is started
      • Test that event handlers have been added
      • Test that page is displayed
      • Test that MM.loadExtraJs is called

      Function: loadSite

      Split into smaller functions

      • setUpConfig
        Test that setConfig is called for current_site and current_token.
      • setUpLanguages
        Test that MM.lang.setup is called for each plugin.
      • loadCachedRemoteCSS
        Mock cache element, test that CSS URL is set accordingly.
      • loadCourses
        Split further based on comments. Mock WS. Test that each function is called.

      Add unit tests

      • Test that MM.sync.init is called
      • Test that MM.sync.css is called
      • Test that MM.lang.sync is called
      • Mock device type, test that tablet panels are shown or hidden accordingly.

      Function: addSite

      Mock input, test that MM.saveSite is called if input is valid and vice versa.

      Function: saveSite

      • Split out nested function to improve readability.
      • Mock WS calls, test handling of success and failure.

      Function: registerPlugin

      • Test that the plugin is added to this.plugins.
      • Test that the plugin's routes are added to the router.
      • Test that loadModels is called.
      • Test that MM.lang.loadPluginLang is called.
      • Test that MM.sync.registerHook is called (based on mocked plugin.sync attr).

      Function: loadModels

      • Test that this.models and this.collections are set based on mocked args.
      • Test that bbproperties is set based on mocked args.

      Function: moodleWSCall

      Split into smaller functions

      • addOperationToQueue
        Test that this is called when device is offline.
      • getDataFromCache
        Test that this is called if preSets.cache is set.
      • Inline function definitions for AJAX success and failure
        Mock AJAX call, test functions accordingly.

      Function: moodleUploadFile

      • Split out device not connected code. Test that this is called appropriately.
      • Test that ft.upload is called.
      • Split out success and failure functions. Mock ft.upload. Test calls.

      Function: moodleDownloadFile

      Mock ft.download. Test the success and error calls.

      Function: wsSync

      • Split out WS call, upload and download code and unit test each individually.
      • Mock device connected state and test that function exits when not connected.

      Function: displaySettings

      Test that settings panel is shown and includes all plugins.

      Function: getConfig

      Add simple output tests.

      Function: setConfig

      Test MM.db.insert is called with appropriate arguments.

      Function fixPluginFile

      Add simple output tests.

      Function: log

      Test that console.log is called and contains the passed message.

      Function: getFormattedLog

      Mock MM.logData. Test that each entry is returned and passed to console.log.

      Function: showLog

      • Test that MM.getFormattedLog is called.
      • Test that the panel is shown containing the log data and filter anchor.
      • Test that that the event handler is added to the filter anchor click.
      • Mock the filter anchor click and test that MM.showLog is called.

      Function: popErrorMessage

      • Test that routing is reset.
      • Test that popMessage is called with the passed message.

      Function: popMessage

      Test that MM.widgets.dialog is called with the passed message.

      Function: popConfirm

      Test that MM.popMessage is called with the appropriate options.

      Functions: handleExternalLinks and handleFiles

      • Split out the href replacement code. Test that it is called.
      • Split out the event handler and that it is attached.
      • Add unit tests to the handler for the various success and error states.

      Function: loadExtraJs

      • Test that the function exits if the device is not connected.
      • Test that each extra JS specified in the config is loaded.

      Function: getOS

      Mock the device. Test that the device platform is returned in lowercase.

      Function: showModalLoading

      Test that MM.widgets.dialog is called with the passed title and text.

      Function: closeModalLoading

      Test that MM.widgets.dialogClose is called.

      Function: refresh

      Test that the cache is purged and the site is reloaded.

            jleyva Juan Leyva
            tonyblundell Tony Blundell
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.