mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-09-25 03:10:18 +00:00
Merge "Add QUnit test for ext.wikiEditor.toolbar"
This commit is contained in:
commit
b906ebabda
|
@ -26,8 +26,9 @@
|
||||||
// Environment
|
// Environment
|
||||||
"browser": true,
|
"browser": true,
|
||||||
|
|
||||||
"predef": [
|
"globals": {
|
||||||
"mediaWiki",
|
"mediaWiki": false,
|
||||||
"jQuery"
|
"jQuery": false,
|
||||||
]
|
"QUnit": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,9 +225,6 @@ class WikiEditorHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MakeGlobalVariablesScript hook
|
|
||||||
*
|
|
||||||
* Adds enabled/disabled switches for WikiEditor modules
|
|
||||||
* @param $vars array
|
* @param $vars array
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -255,6 +252,28 @@ class WikiEditorHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* ResourceLoaderTestModules hook
|
||||||
|
*
|
||||||
|
* Registers JavaScript test modules
|
||||||
|
*
|
||||||
|
* @param $testModules array of javascript testing modules. 'qunit' is fed using tests/qunit/QUnitTestResources.php.
|
||||||
|
* @param $resourceLoader object
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function resourceLoaderTestModules( &$testModules, &$resourceLoader ) {
|
||||||
|
$testModules['qunit']['ext.wikiEditor.toolbar.test'] = array(
|
||||||
|
'scripts' => array( 'tests/qunit/ext.wikiEditor.toolbar.test.js' ),
|
||||||
|
'dependencies' => array( 'ext.wikiEditor.toolbar' ),
|
||||||
|
'localBasePath' => dirname( __FILE__ ),
|
||||||
|
'remoteExtPath' => 'WikiEditor',
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MakeGlobalVariablesScript hook
|
||||||
|
*
|
||||||
|
* Adds enabled/disabled switches for WikiEditor modules
|
||||||
* @param $vars array
|
* @param $vars array
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,7 @@ $GLOBALS['wgExtensionMessagesFiles']['WikiEditor'] = __DIR__ . '/WikiEditor.i18n
|
||||||
$GLOBALS['wgHooks']['EditPage::showEditForm:initial'][] = 'WikiEditorHooks::editPageShowEditFormInitial';
|
$GLOBALS['wgHooks']['EditPage::showEditForm:initial'][] = 'WikiEditorHooks::editPageShowEditFormInitial';
|
||||||
$GLOBALS['wgHooks']['GetPreferences'][] = 'WikiEditorHooks::getPreferences';
|
$GLOBALS['wgHooks']['GetPreferences'][] = 'WikiEditorHooks::getPreferences';
|
||||||
$GLOBALS['wgHooks']['ResourceLoaderGetConfigVars'][] = 'WikiEditorHooks::resourceLoaderGetConfigVars';
|
$GLOBALS['wgHooks']['ResourceLoaderGetConfigVars'][] = 'WikiEditorHooks::resourceLoaderGetConfigVars';
|
||||||
|
$GLOBALS['wgHooks']['ResourceLoaderTestModules'][] = 'WikiEditorHooks::resourceLoaderTestModules';
|
||||||
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'WikiEditorHooks::makeGlobalVariablesScript';
|
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'WikiEditorHooks::makeGlobalVariablesScript';
|
||||||
$GLOBALS['wgHooks']['EditPageBeforeEditToolbar'][] = 'WikiEditorHooks::EditPageBeforeEditToolbar';
|
$GLOBALS['wgHooks']['EditPageBeforeEditToolbar'][] = 'WikiEditorHooks::EditPageBeforeEditToolbar';
|
||||||
|
|
||||||
|
@ -413,10 +414,6 @@ $GLOBALS['wgResourceModules'] += array(
|
||||||
'wikieditor-publish-dialog-goback',
|
'wikieditor-publish-dialog-goback',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'ext.wikiEditor.tests.toolbar' => $wikiEditorTpl + array(
|
|
||||||
'scripts' => 'ext.wikiEditor.tests.toolbar.js',
|
|
||||||
'dependencies' => 'ext.wikiEditor.toolbar',
|
|
||||||
),
|
|
||||||
'ext.wikiEditor.toolbar' => $wikiEditorTpl + array(
|
'ext.wikiEditor.toolbar' => $wikiEditorTpl + array(
|
||||||
'scripts' => 'ext.wikiEditor.toolbar.js',
|
'scripts' => 'ext.wikiEditor.toolbar.js',
|
||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
|
|
|
@ -1,255 +0,0 @@
|
||||||
/**
|
|
||||||
* Test set for the edit toolbar
|
|
||||||
*/
|
|
||||||
var textareaId = '#wpTextbox1';
|
|
||||||
var wikiEditorTests = {
|
|
||||||
// Add emoticons section
|
|
||||||
'add_sections_toolbar': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
'sections': {
|
|
||||||
'emoticons': {
|
|
||||||
'type': 'toolbar',
|
|
||||||
'label': 'Emoticons'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=emoticons].section',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add faces group to emoticons section
|
|
||||||
'add_groups': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'emoticons',
|
|
||||||
'groups': {
|
|
||||||
'faces': {
|
|
||||||
'label': 'Faces'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=emoticons].section *[rel=faces].group',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add smile tool to faces group of emoticons section
|
|
||||||
'add_tools': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'emoticons',
|
|
||||||
'group': 'faces',
|
|
||||||
'tools': {
|
|
||||||
'smile': {
|
|
||||||
label: 'Smile!',
|
|
||||||
type: 'button',
|
|
||||||
icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
|
|
||||||
action: {
|
|
||||||
type: 'encapsulate',
|
|
||||||
options: {
|
|
||||||
pre: ':)'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=emoticons].section *[rel=faces].group *[rel=smile].tool',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add info section
|
|
||||||
'add_sections_booklet': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
'sections': {
|
|
||||||
'info': {
|
|
||||||
'type': 'booklet',
|
|
||||||
'label': 'Info'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add info section
|
|
||||||
'add_pages_table': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
pages: {
|
|
||||||
'colors': {
|
|
||||||
'layout': 'table',
|
|
||||||
'label': 'Colors',
|
|
||||||
'headings': [
|
|
||||||
{ text: 'Name' },
|
|
||||||
{ text: 'Temperature' },
|
|
||||||
{ text: 'Swatch' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=colors].page',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add colors rows
|
|
||||||
'add_rows': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
page: 'colors',
|
|
||||||
'rows': [
|
|
||||||
{
|
|
||||||
'name': { text: 'Red' },
|
|
||||||
'temp': { text: 'Warm' },
|
|
||||||
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': { text: 'Blue' },
|
|
||||||
'temp': { text: 'Cold' },
|
|
||||||
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': { text: 'Silver' },
|
|
||||||
'temp': { text: 'Neutral' },
|
|
||||||
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=colors].page tr td',
|
|
||||||
pre: 0,
|
|
||||||
post: 9
|
|
||||||
},
|
|
||||||
// Add
|
|
||||||
'add_pages_characters': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
pages: {
|
|
||||||
'emoticons': {
|
|
||||||
'layout': 'characters',
|
|
||||||
'label': 'Emoticons'
|
|
||||||
},
|
|
||||||
'removeme': {
|
|
||||||
'layout': 'characters',
|
|
||||||
'label': 'Remove Me!'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=emoticons].page',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Add
|
|
||||||
'add_characters': {
|
|
||||||
call: 'addToToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
page: 'emoticons',
|
|
||||||
characters: [ ':)', ':))', ':(', '<3', ';)' ]
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=emoticons].page *[rel=":)"]',
|
|
||||||
pre: 0,
|
|
||||||
post: 1
|
|
||||||
},
|
|
||||||
// Remove page
|
|
||||||
'remove_page': {
|
|
||||||
call: 'removeFromToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
page: 'removeme'
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=removeme].page',
|
|
||||||
pre: 1,
|
|
||||||
post: 0
|
|
||||||
},
|
|
||||||
// Remove :)) from emoticon characters
|
|
||||||
'remove_character': {
|
|
||||||
call: 'removeFromToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
page: 'emoticons',
|
|
||||||
'character': ':))'
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]',
|
|
||||||
pre: 1,
|
|
||||||
post: 0
|
|
||||||
},
|
|
||||||
// Remove row from colors table of info section
|
|
||||||
'remove_row': {
|
|
||||||
call: 'removeFromToolbar',
|
|
||||||
data: {
|
|
||||||
section: 'info',
|
|
||||||
page: 'colors',
|
|
||||||
'row': 0
|
|
||||||
},
|
|
||||||
test: '*[rel=info].section *[rel=colors].page tr td',
|
|
||||||
pre: 9,
|
|
||||||
post: 6
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
jQuery( document ).ready( function ( $ ) {
|
|
||||||
var $button = $( '<button>Run wikiEditor Tests!</button>' )
|
|
||||||
.css( {
|
|
||||||
position: 'fixed',
|
|
||||||
bottom: 0,
|
|
||||||
right: 0,
|
|
||||||
width: '100%',
|
|
||||||
backgroundColor: '#333',
|
|
||||||
opacity: 0.75,
|
|
||||||
color: '#DDDDDD',
|
|
||||||
padding: '0.7em',
|
|
||||||
border: 'none',
|
|
||||||
display: 'none',
|
|
||||||
cursor: 'pointer'
|
|
||||||
} )
|
|
||||||
.click( function () {
|
|
||||||
if ( $( this ).data( 'testDone' ) ) {
|
|
||||||
$( this ).slideUp( 'fast' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var test, pre, post, i,
|
|
||||||
messages = [ 'Running tests for wikiEditor API' ],
|
|
||||||
$target = $( textareaId ),
|
|
||||||
$ui = $target.data( 'wikiEditor-context' ).$ui,
|
|
||||||
passes = 0,
|
|
||||||
tests = 0;
|
|
||||||
|
|
||||||
for ( test in wikiEditorTests ) {
|
|
||||||
pre = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].pre;
|
|
||||||
messages.push ( test + '-pre: ' + ( pre ? 'PASS' : 'FAIL' ) );
|
|
||||||
$target.wikiEditor(
|
|
||||||
wikiEditorTests[test].call,
|
|
||||||
wikiEditorTests[test].data
|
|
||||||
);
|
|
||||||
post = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].post;
|
|
||||||
messages.push ( test + '-post: ' + ( post ? 'PASS' : 'FAIL' ) );
|
|
||||||
if ( pre && post ) {
|
|
||||||
passes++;
|
|
||||||
}
|
|
||||||
tests++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( window.console ) {
|
|
||||||
for ( i = 0; i < messages.length; i++ ) {
|
|
||||||
window.console.log( messages[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$( this )
|
|
||||||
.attr( 'title', messages.join( ' | ' ) )
|
|
||||||
.text( passes + ' / ' + tests + ' were successful' )
|
|
||||||
.css( 'backgroundColor', passes < tests ? 'red' : 'green' )
|
|
||||||
.data( 'testDone', 'true' )
|
|
||||||
.blur();
|
|
||||||
} )
|
|
||||||
.appendTo( $( 'body' ) );
|
|
||||||
|
|
||||||
setTimeout( function () {
|
|
||||||
$button.slideDown( 'fast' );
|
|
||||||
}, 1500 );
|
|
||||||
|
|
||||||
} );
|
|
|
@ -158,7 +158,7 @@ api : {
|
||||||
// Save for later checking if empty
|
// Save for later checking if empty
|
||||||
group = target;
|
group = target;
|
||||||
// Tool
|
// Tool
|
||||||
target = target + ' a[rel="' + data.tool + '"].tool, ' + target + ' img[rel="' + data.tool + '"].tool';
|
target = target + ' [rel="' + data.tool + '"].tool';
|
||||||
}
|
}
|
||||||
} else if ( typeof data.page === 'string' ) {
|
} else if ( typeof data.page === 'string' ) {
|
||||||
// Booklet page
|
// Booklet page
|
||||||
|
|
274
tests/qunit/ext.wikiEditor.toolbar.test.js
Normal file
274
tests/qunit/ext.wikiEditor.toolbar.test.js
Normal file
|
@ -0,0 +1,274 @@
|
||||||
|
( function ( $ ) {
|
||||||
|
QUnit.module( 'ext.wikiEditor.toolbar', QUnit.newMwEnvironment( {
|
||||||
|
setup: function () {
|
||||||
|
var $fixture = $( '#qunit-fixture' );
|
||||||
|
var $target = $( '<textarea id="wpTextBox1">' );
|
||||||
|
this.$target = $target;
|
||||||
|
$fixture.append( $target );
|
||||||
|
$target.wikiEditor( 'addModule', 'toolbar' );
|
||||||
|
this.$ui = $target.data( 'wikiEditor-context' ).$ui;
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
QUnit.test( 'Toolbars', 16, function ( assert ) {
|
||||||
|
// Add toolbar section
|
||||||
|
var data = {
|
||||||
|
sections: {
|
||||||
|
emoticons: {
|
||||||
|
type: 'toolbar',
|
||||||
|
label: 'Emoticons'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'Before adding toolbar section' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'After adding toolbar section' );
|
||||||
|
|
||||||
|
// Add toolbar group
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
groups: {
|
||||||
|
faces: {
|
||||||
|
label: 'Faces'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'Before adding toolbar group' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'After adding toolbar group' );
|
||||||
|
|
||||||
|
// Add button tool
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
group: 'faces',
|
||||||
|
tools: {
|
||||||
|
smile: {
|
||||||
|
label: 'Smile!',
|
||||||
|
type: 'button',
|
||||||
|
icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
|
||||||
|
action: {
|
||||||
|
type: 'encapsulate',
|
||||||
|
options: {
|
||||||
|
pre: ':)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'Before adding button' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'After adding button' );
|
||||||
|
|
||||||
|
// Remove button tool
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
group: 'faces',
|
||||||
|
tool: 'smile'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 1, 'Before removing button' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ).length, 0, 'After removing button' );
|
||||||
|
|
||||||
|
// Add select tool
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
group: 'faces',
|
||||||
|
tools: {
|
||||||
|
icons: {
|
||||||
|
label: 'Icons',
|
||||||
|
type: 'select',
|
||||||
|
list: {
|
||||||
|
wink : {
|
||||||
|
label: 'Wink',
|
||||||
|
action: {
|
||||||
|
type: 'encapsulate',
|
||||||
|
options: {
|
||||||
|
pre: ';)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
frown : {
|
||||||
|
label: 'Frown',
|
||||||
|
action: {
|
||||||
|
type: 'encapsulate',
|
||||||
|
options: {
|
||||||
|
pre: ':('
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bigSmile : {
|
||||||
|
label: 'Big smile',
|
||||||
|
action: {
|
||||||
|
type: 'encapsulate',
|
||||||
|
options: {
|
||||||
|
pre: ':D'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'Before adding select' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'After adding select' );
|
||||||
|
|
||||||
|
// Remove select tool
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
group: 'faces',
|
||||||
|
tool: 'icons'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 1, 'Before removing select' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ).length, 0, 'After removing select' );
|
||||||
|
|
||||||
|
// Remove toolbar group
|
||||||
|
data = {
|
||||||
|
section: 'emoticons',
|
||||||
|
group: 'faces'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 1, 'Before removing toolbar group' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section *[rel="faces"].group' ).length, 0, 'After removing toolbar group' );
|
||||||
|
|
||||||
|
// Remove toolbar section
|
||||||
|
data = {
|
||||||
|
section: 'emoticons'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 1, 'Before removing toolbar section' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="emoticons"].section' ).length, 0, 'After removing toolbar section' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
QUnit.test( 'Booklets', 20, function ( assert ) {
|
||||||
|
// Add booklet section
|
||||||
|
var data = {
|
||||||
|
sections: {
|
||||||
|
info: {
|
||||||
|
type: 'booklet',
|
||||||
|
label: 'Info'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 0, 'Before adding booklet section' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 1, 'After adding booklet section' );
|
||||||
|
|
||||||
|
// Add table page
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
pages: {
|
||||||
|
colors: {
|
||||||
|
layout: 'table',
|
||||||
|
label: 'Colors',
|
||||||
|
headings: [
|
||||||
|
{ text: 'Name' },
|
||||||
|
{ text: 'Temperature' },
|
||||||
|
{ text: 'Swatch' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'Before adding table page' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'After adding table page' );
|
||||||
|
|
||||||
|
// Add table rows
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'colors',
|
||||||
|
rows: [
|
||||||
|
{
|
||||||
|
name: { text: 'Red' },
|
||||||
|
temp: { text: 'Warm' },
|
||||||
|
swatch: { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: { text: 'Blue' },
|
||||||
|
temp: { text: 'Cold' },
|
||||||
|
swatch: { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: { text: 'Silver' },
|
||||||
|
temp: { text: 'Neutral' },
|
||||||
|
swatch: { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 0, 'Before adding table rows' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'After adding table rows' );
|
||||||
|
|
||||||
|
// Remove table row
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'colors',
|
||||||
|
row: 0
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 9, 'Before removing table row' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page tr td' ).length, 6, 'After removing table row' );
|
||||||
|
|
||||||
|
// Remove table page
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'colors'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 1, 'Before removing table page' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="colors"].page' ).length, 0, 'After removing table page' );
|
||||||
|
|
||||||
|
// Add character page
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
pages: {
|
||||||
|
emoticons: {
|
||||||
|
layout: 'characters',
|
||||||
|
label: 'Emoticons'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'Before adding character page' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'After adding character page' );
|
||||||
|
|
||||||
|
// Add characters
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'emoticons',
|
||||||
|
characters: [ ':)', ':))', ':(', '<3', ';)' ]
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'Before adding characters' );
|
||||||
|
this.$target.wikiEditor( 'addToToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'After adding characters' );
|
||||||
|
|
||||||
|
// Remove character
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'emoticons',
|
||||||
|
character: ':))'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 1, 'Before removing character' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ).length, 0, 'After removing character' );
|
||||||
|
|
||||||
|
// Remove character page
|
||||||
|
data = {
|
||||||
|
section: 'info',
|
||||||
|
page: 'emoticons'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 1, 'Before removing character page' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section *[rel="emoticons"].page' ).length, 0, 'After removing character page' );
|
||||||
|
|
||||||
|
// Remove booklet section
|
||||||
|
data = {
|
||||||
|
section: 'info'
|
||||||
|
};
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 1, 'Before removing booklet section' );
|
||||||
|
this.$target.wikiEditor( 'removeFromToolbar', data );
|
||||||
|
assert.equal( this.$ui.find( '*[rel="info"].section' ).length, 0, 'After removing booklet section' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
}( jQuery ) );
|
Loading…
Reference in a new issue