2010-09-15 03:08:35 +00:00
|
|
|
/**
|
|
|
|
* Test set for the edit toolbar
|
|
|
|
*/
|
|
|
|
var textareaId = '#wpTextbox1';
|
|
|
|
var wikiEditorTests = {
|
|
|
|
// Add emoticons section
|
2012-07-03 05:52:27 +00:00
|
|
|
add_sections_toolbar: {
|
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
2010-09-15 03:08:35 +00:00
|
|
|
'sections': {
|
|
|
|
'emoticons': {
|
|
|
|
'type': 'toolbar',
|
|
|
|
'label': 'Emoticons'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=emoticons].section',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Add faces group to emoticons section
|
|
|
|
'add_groups': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'emoticons',
|
2010-09-15 03:08:35 +00:00
|
|
|
'groups': {
|
|
|
|
'faces': {
|
|
|
|
'label': 'Faces'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=emoticons].section *[rel=faces].group',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Add smile tool to faces group of emoticons section
|
|
|
|
'add_tools': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'emoticons',
|
2010-09-15 03:08:35 +00:00
|
|
|
'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: {
|
2012-07-03 05:52:27 +00:00
|
|
|
pre: ':)'
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=emoticons].section *[rel=faces].group *[rel=smile].tool',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Add info section
|
|
|
|
'add_sections_booklet': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
2010-09-15 03:08:35 +00:00
|
|
|
'sections': {
|
|
|
|
'info': {
|
|
|
|
'type': 'booklet',
|
|
|
|
'label': 'Info'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Add info section
|
|
|
|
'add_pages_table': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
pages: {
|
2010-09-15 03:08:35 +00:00
|
|
|
'colors': {
|
|
|
|
'layout': 'table',
|
|
|
|
'label': 'Colors',
|
|
|
|
'headings': [
|
|
|
|
{ text: 'Name' },
|
|
|
|
{ text: 'Temperature' },
|
|
|
|
{ text: 'Swatch' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=colors].page',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Add colors rows
|
|
|
|
'add_rows': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
page: 'colors',
|
2010-09-15 03:08:35 +00:00
|
|
|
'rows': [
|
|
|
|
{
|
|
|
|
'name': { text: 'Red' },
|
|
|
|
'temp': { text: 'Warm' },
|
2012-07-03 05:52:27 +00:00
|
|
|
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': { text: 'Blue' },
|
|
|
|
'temp': { text: 'Cold' },
|
2012-07-03 05:52:27 +00:00
|
|
|
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': { text: 'Silver' },
|
|
|
|
'temp': { text: 'Neutral' },
|
2012-07-03 05:52:27 +00:00
|
|
|
'swatch': { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=colors].page tr td',
|
|
|
|
pre: 0,
|
|
|
|
post: 9
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
2011-09-13 08:56:32 +00:00
|
|
|
// Add
|
2010-09-15 03:08:35 +00:00
|
|
|
'add_pages_characters': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
pages: {
|
2010-09-15 03:08:35 +00:00
|
|
|
'emoticons': {
|
|
|
|
'layout': 'characters',
|
|
|
|
'label': 'Emoticons'
|
|
|
|
},
|
|
|
|
'removeme': {
|
|
|
|
'layout': 'characters',
|
|
|
|
'label': 'Remove Me!'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=emoticons].page',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
2011-09-13 08:56:32 +00:00
|
|
|
// Add
|
2010-09-15 03:08:35 +00:00
|
|
|
'add_characters': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'addToToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
page: 'emoticons',
|
|
|
|
characters: [ ':)', ':))', ':(', '<3', ';)' ]
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=emoticons].page *[rel=":)"]',
|
|
|
|
pre: 0,
|
|
|
|
post: 1
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Remove page
|
|
|
|
'remove_page': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'removeFromToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
page: 'removeme'
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=removeme].page',
|
|
|
|
pre: 1,
|
|
|
|
post: 0
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Remove :)) from emoticon characters
|
|
|
|
'remove_character': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'removeFromToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
page: 'emoticons',
|
2010-09-15 03:08:35 +00:00
|
|
|
'character': ':))'
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]',
|
|
|
|
pre: 1,
|
|
|
|
post: 0
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Remove row from colors table of info section
|
|
|
|
'remove_row': {
|
2012-07-03 05:52:27 +00:00
|
|
|
call: 'removeFromToolbar',
|
|
|
|
data: {
|
|
|
|
section: 'info',
|
|
|
|
page: 'colors',
|
2010-09-15 03:08:35 +00:00
|
|
|
'row': 0
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
test: '*[rel=info].section *[rel=colors].page tr td',
|
|
|
|
pre: 9,
|
|
|
|
post: 6
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-03 05:52:27 +00:00
|
|
|
|
|
|
|
jQuery(document).ready( function ( $ ) {
|
|
|
|
var $button = $( '<button>Run wikiEditor Tests!</button>' )
|
2010-09-15 03:08:35 +00:00
|
|
|
.css( {
|
2012-07-03 05:52:27 +00:00
|
|
|
position: 'fixed',
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
width: '100%',
|
|
|
|
backgroundColor: '#333',
|
|
|
|
opacity: 0.75,
|
|
|
|
color: '#DDDDDD',
|
|
|
|
padding: '0.7em',
|
|
|
|
border: 'none',
|
|
|
|
display: 'none'
|
2010-09-15 03:08:35 +00:00
|
|
|
} )
|
2012-07-03 05:52:27 +00:00
|
|
|
.click( function () {
|
|
|
|
if ( $(this).data( 'testDone' ) ) {
|
2010-09-20 20:06:18 +00:00
|
|
|
$(this).slideUp( 'fast' );
|
2010-09-15 03:08:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 05:52:27 +00:00
|
|
|
|
|
|
|
var test, pre, post,
|
|
|
|
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;
|
2010-09-15 03:08:35 +00:00
|
|
|
messages.push ( test + '-pre: ' + ( pre ? 'PASS' : 'FAIL' ) );
|
|
|
|
$target.wikiEditor(
|
|
|
|
wikiEditorTests[test].call,
|
|
|
|
wikiEditorTests[test].data
|
|
|
|
);
|
2012-07-03 05:52:27 +00:00
|
|
|
post = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].post;
|
2010-09-15 03:08:35 +00:00
|
|
|
messages.push ( test + '-post: ' + ( post ? 'PASS' : 'FAIL' ) );
|
|
|
|
if ( pre && post ) {
|
|
|
|
passes++;
|
|
|
|
}
|
|
|
|
tests++;
|
|
|
|
}
|
2012-07-03 05:52:27 +00:00
|
|
|
|
|
|
|
if ( window.console ) {
|
2011-07-02 09:09:05 +00:00
|
|
|
for ( var i = 0; i < messages.length; i++ ) {
|
2012-07-03 05:52:27 +00:00
|
|
|
window.console.log( messages[i] );
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-03 05:52:27 +00:00
|
|
|
|
2010-09-20 20:06:18 +00:00
|
|
|
$(this)
|
2010-09-15 03:08:35 +00:00
|
|
|
.attr( 'title', messages.join( " | " ) )
|
|
|
|
.text( passes + ' / ' + tests + ' were successful' )
|
|
|
|
.css( 'backgroundColor', passes < tests ? 'red' : 'green' )
|
2012-07-03 05:52:27 +00:00
|
|
|
.data( 'testDone', 'true' )
|
2010-09-15 03:08:35 +00:00
|
|
|
.blur();
|
|
|
|
} )
|
2010-09-20 20:06:18 +00:00
|
|
|
.appendTo( $( 'body' ) );
|
2012-07-03 05:52:27 +00:00
|
|
|
|
|
|
|
setTimeout( function () {
|
|
|
|
$button.slideDown( 'fast' );
|
|
|
|
}, 1500 );
|
|
|
|
|
2010-09-15 03:08:35 +00:00
|
|
|
} );
|