[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/WikiEditor/modules/ -> ext.wikiEditor.tests.toolbar.js (source)

   1  /**
   2   * Test set for the edit toolbar
   3   */
   4  var textareaId = '#wpTextbox1';
   5  var wikiEditorTests = {
   6      // Add emoticons section
   7      'add_sections_toolbar': {
   8          call: 'addToToolbar',
   9          data: {
  10              'sections': {
  11                  'emoticons': {
  12                      'type': 'toolbar',
  13                      'label': 'Emoticons'
  14                  }
  15              }
  16          },
  17          test: '*[rel=emoticons].section',
  18          pre: 0,
  19          post: 1
  20      },
  21      // Add faces group to emoticons section
  22      'add_groups': {
  23          call: 'addToToolbar',
  24          data: {
  25              section: 'emoticons',
  26              'groups': {
  27                  'faces': {
  28                      'label': 'Faces'
  29                  }
  30              }
  31          },
  32          test: '*[rel=emoticons].section *[rel=faces].group',
  33          pre: 0,
  34          post: 1
  35      },
  36      // Add smile tool to faces group of emoticons section
  37      'add_tools': {
  38          call: 'addToToolbar',
  39          data: {
  40              section: 'emoticons',
  41              'group': 'faces',
  42              'tools': {
  43                  'smile': {
  44                      label: 'Smile!',
  45                      type: 'button',
  46                      icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
  47                      action: {
  48                          type: 'encapsulate',
  49                          options: {
  50                              pre: ':)'
  51                          }
  52                      }
  53                  }
  54              }
  55          },
  56          test: '*[rel=emoticons].section *[rel=faces].group *[rel=smile].tool',
  57          pre: 0,
  58          post: 1
  59      },
  60      // Add info section
  61      'add_sections_booklet': {
  62          call: 'addToToolbar',
  63          data: {
  64              'sections': {
  65                  'info': {
  66                      'type': 'booklet',
  67                      'label': 'Info'
  68                  }
  69              }
  70          },
  71          test: '*[rel=info].section',
  72          pre: 0,
  73          post: 1
  74      },
  75      // Add info section
  76      'add_pages_table': {
  77          call: 'addToToolbar',
  78          data: {
  79              section: 'info',
  80              pages: {
  81                  'colors': {
  82                      'layout': 'table',
  83                      'label': 'Colors',
  84                      'headings': [
  85                          { text: 'Name' },
  86                          { text: 'Temperature' },
  87                          { text: 'Swatch' }
  88                      ]
  89                  }
  90              }
  91          },
  92          test: '*[rel=info].section *[rel=colors].page',
  93          pre: 0,
  94          post: 1
  95      },
  96      // Add colors rows
  97      'add_rows': {
  98          call: 'addToToolbar',
  99          data: {
 100              section: 'info',
 101              page: 'colors',
 102                  'rows': [
 103                      {
 104                          'name': { text: 'Red' },
 105                          'temp': { text: 'Warm' },
 106                          'swatch': { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
 107                      },
 108                      {
 109                          'name': { text: 'Blue' },
 110                          'temp': { text: 'Cold' },
 111                          'swatch': { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
 112                      },
 113                      {
 114                          'name': { text: 'Silver' },
 115                          'temp': { text: 'Neutral' },
 116                          'swatch': { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
 117                      }
 118                  ]
 119          },
 120          test: '*[rel=info].section *[rel=colors].page tr td',
 121          pre: 0,
 122          post: 9
 123      },
 124      // Add
 125      'add_pages_characters': {
 126          call: 'addToToolbar',
 127          data: {
 128              section: 'info',
 129              pages: {
 130                  'emoticons': {
 131                      'layout': 'characters',
 132                      'label': 'Emoticons'
 133                  },
 134                  'removeme': {
 135                      'layout': 'characters',
 136                      'label': 'Remove Me!'
 137                  }
 138              }
 139          },
 140          test: '*[rel=info].section *[rel=emoticons].page',
 141          pre: 0,
 142          post: 1
 143      },
 144      // Add
 145      'add_characters': {
 146          call: 'addToToolbar',
 147          data: {
 148              section: 'info',
 149              page: 'emoticons',
 150              characters: [ ':)', ':))', ':(', '<3', ';)' ]
 151          },
 152          test: '*[rel=info].section *[rel=emoticons].page *[rel=":)"]',
 153          pre: 0,
 154          post: 1
 155      },
 156      // Remove page
 157      'remove_page': {
 158          call: 'removeFromToolbar',
 159          data: {
 160              section: 'info',
 161              page: 'removeme'
 162          },
 163          test: '*[rel=info].section *[rel=removeme].page',
 164          pre: 1,
 165          post: 0
 166      },
 167      // Remove :)) from emoticon characters
 168      'remove_character': {
 169          call: 'removeFromToolbar',
 170          data: {
 171              section: 'info',
 172              page: 'emoticons',
 173              'character': ':))'
 174          },
 175          test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]',
 176          pre: 1,
 177          post: 0
 178      },
 179      // Remove row from colors table of info section
 180      'remove_row': {
 181          call: 'removeFromToolbar',
 182          data: {
 183              section: 'info',
 184              page: 'colors',
 185              'row': 0
 186          },
 187          test: '*[rel=info].section *[rel=colors].page tr td',
 188          pre: 9,
 189          post: 6
 190      }
 191  };
 192  
 193  jQuery( document ).ready( function ( $ ) {
 194      var $button = $( '<button>Run wikiEditor Tests!</button>' )
 195          .css( {
 196              position: 'fixed',
 197              bottom: 0,
 198              right: 0,
 199              width: '100%',
 200              backgroundColor: '#333',
 201              opacity: 0.75,
 202              color: '#DDDDDD',
 203              padding: '0.7em',
 204              border: 'none',
 205              display: 'none',
 206              cursor: 'pointer'
 207          } )
 208          .click( function () {
 209              if ( $( this ).data( 'testDone' ) ) {
 210                  $( this ).slideUp( 'fast' );
 211                  return false;
 212              }
 213  
 214              var test, pre, post, i,
 215                  messages = [ 'Running tests for wikiEditor API' ],
 216                  $target = $( textareaId ),
 217                  $ui = $target.data( 'wikiEditor-context' ).$ui,
 218                  passes = 0,
 219                  tests = 0;
 220  
 221              for ( test in wikiEditorTests ) {
 222                  pre = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].pre;
 223                  messages.push ( test + '-pre: ' + ( pre ? 'PASS' : 'FAIL' ) );
 224                  $target.wikiEditor(
 225                      wikiEditorTests[test].call,
 226                      wikiEditorTests[test].data
 227                  );
 228                  post = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].post;
 229                  messages.push ( test + '-post: ' + ( post ? 'PASS' : 'FAIL' ) );
 230                  if ( pre && post ) {
 231                      passes++;
 232                  }
 233                  tests++;
 234              }
 235  
 236              if ( window.console ) {
 237                  for ( i = 0; i < messages.length; i++ ) {
 238                      window.console.log( messages[i] );
 239                  }
 240              }
 241  
 242              $( this )
 243                  .attr( 'title', messages.join( ' | ' ) )
 244                  .text( passes + ' / ' + tests + ' were successful' )
 245                  .css( 'backgroundColor', passes < tests ? 'red' : 'green' )
 246                  .data( 'testDone', 'true' )
 247                  .blur();
 248          } )
 249          .appendTo( $( 'body' ) );
 250  
 251      setTimeout( function () {
 252          $button.slideDown( 'fast' );
 253      }, 1500 );
 254  
 255  } );


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1