2022-05-02 23:07:28 +00:00
QUnit . module ( 'ext.wikiEditor.toolbar' , function ( hooks ) {
hooks . beforeEach ( function ( ) {
var $target = $ ( '<textarea>' )
. attr ( 'id' , 'wpTextBox1' )
. appendTo ( '#qunit-fixture' ) ;
this . $target = $target ;
$target . wikiEditor ( 'addModule' , 'toolbar' ) ;
this . $ui = $target . data ( 'wikiEditor-context' ) . $ui ;
} ) ;
2014-09-01 14:07:28 +00:00
2017-10-25 11:24:53 +00:00
QUnit . test ( 'Toolbars' , function ( assert ) {
2014-09-01 14:07:28 +00:00
// Add toolbar section
var data = {
sections : {
emoticons : {
type : 'toolbar' ,
label : 'Emoticons'
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section' ) . length , 0 , 'Before adding toolbar section' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section' ) . length , 1 , 'After adding toolbar section' ) ;
2014-09-01 14:07:28 +00:00
// Add toolbar group
data = {
section : 'emoticons' ,
groups : {
faces : {
label : 'Faces'
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group' ) . length , 0 , 'Before adding toolbar group' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group' ) . length , 1 , 'After adding toolbar group' ) ;
2014-09-01 14:07:28 +00:00
// 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 : ':)'
}
}
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ) . length , 0 , 'Before adding button' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ) . length , 1 , 'After adding button' ) ;
2014-09-01 14:07:28 +00:00
// Remove button tool
data = {
section : 'emoticons' ,
group : 'faces' ,
tool : 'smile'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ) . length , 1 , 'Before removing button' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="smile"].tool' ) . length , 0 , 'After removing button' ) ;
2014-09-01 14:07:28 +00:00
// Add select tool
data = {
section : 'emoticons' ,
group : 'faces' ,
tools : {
icons : {
label : 'Icons' ,
type : 'select' ,
list : {
2015-11-15 14:30:18 +00:00
wink : {
2014-09-01 14:07:28 +00:00
label : 'Wink' ,
action : {
type : 'encapsulate' ,
options : {
pre : ';)'
}
}
} ,
2015-11-15 14:30:18 +00:00
frown : {
2014-09-01 14:07:28 +00:00
label : 'Frown' ,
action : {
type : 'encapsulate' ,
options : {
pre : ':('
}
}
} ,
2015-11-15 14:30:18 +00:00
bigSmile : {
2014-09-01 14:07:28 +00:00
label : 'Big smile' ,
action : {
type : 'encapsulate' ,
options : {
pre : ':D'
}
}
}
}
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ) . length , 0 , 'Before adding select' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ) . length , 1 , 'After adding select' ) ;
2014-09-01 14:07:28 +00:00
// Remove select tool
data = {
section : 'emoticons' ,
group : 'faces' ,
tool : 'icons'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ) . length , 1 , 'Before removing select' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group *[rel="icons"].tool' ) . length , 0 , 'After removing select' ) ;
2014-09-01 14:07:28 +00:00
// Remove toolbar group
data = {
section : 'emoticons' ,
group : 'faces'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group' ) . length , 1 , 'Before removing toolbar group' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section *[rel="faces"].group' ) . length , 0 , 'After removing toolbar group' ) ;
2014-09-01 14:07:28 +00:00
// Remove toolbar section
data = {
section : 'emoticons'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section' ) . length , 1 , 'Before removing toolbar section' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="emoticons"].section' ) . length , 0 , 'After removing toolbar section' ) ;
2014-09-01 14:07:28 +00:00
} ) ;
2017-10-25 11:24:53 +00:00
QUnit . test ( 'Booklets' , function ( assert ) {
2014-09-01 14:07:28 +00:00
// Add booklet section
var data = {
sections : {
info : {
type : 'booklet' ,
label : 'Info'
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section' ) . length , 0 , 'Before adding booklet section' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section' ) . length , 1 , 'After adding booklet section' ) ;
2014-09-01 14:07:28 +00:00
// Add table page
data = {
section : 'info' ,
pages : {
colors : {
layout : 'table' ,
label : 'Colors' ,
headings : [
{ text : 'Name' } ,
{ text : 'Temperature' } ,
{ text : 'Swatch' }
]
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page' ) . length , 0 , 'Before adding table page' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page' ) . length , 1 , 'After adding table page' ) ;
2014-09-01 14:07:28 +00:00
// Add table rows
data = {
section : 'info' ,
page : 'colors' ,
2015-11-15 14:30:18 +00:00
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;">' }
}
]
2014-09-01 14:07:28 +00:00
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page tr td' ) . length , 0 , 'Before adding table rows' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page tr td' ) . length , 9 , 'After adding table rows' ) ;
2014-09-01 14:07:28 +00:00
// Remove table row
data = {
section : 'info' ,
page : 'colors' ,
row : 0
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page tr td' ) . length , 9 , 'Before removing table row' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page tr td' ) . length , 6 , 'After removing table row' ) ;
2014-09-01 14:07:28 +00:00
// Remove table page
data = {
section : 'info' ,
page : 'colors'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page' ) . length , 1 , 'Before removing table page' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="colors"].page' ) . length , 0 , 'After removing table page' ) ;
2014-09-01 14:07:28 +00:00
// Add character page
data = {
section : 'info' ,
pages : {
emoticons : {
layout : 'characters' ,
label : 'Emoticons'
}
}
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page' ) . length , 0 , 'Before adding character page' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page' ) . length , 1 , 'After adding character page' ) ;
2014-09-01 14:07:28 +00:00
// Add characters
data = {
section : 'info' ,
page : 'emoticons' ,
2021-10-04 13:49:36 +00:00
characters : [
':)' , ':))' , ':(' , '<3' , ';)' ,
{
label : ':-s' ,
title : 'unsure-face' ,
action : {
type : 'replace' ,
options : {
peri : ':-s' ,
selectPeri : false
}
}
} ]
2014-09-01 14:07:28 +00:00
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ) . length , 0 , 'Before adding characters' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'addToToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ) . length , 1 , 'After adding characters' ) ;
2021-10-04 13:49:36 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page *[title="unsure-face"]' ) . length , 1 , 'After adding characters find the set title' ) ;
2014-09-01 14:07:28 +00:00
// Remove character
data = {
section : 'info' ,
page : 'emoticons' ,
character : ':))'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ) . length , 1 , 'Before removing character' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page *[rel=":))"]' ) . length , 0 , 'After removing character' ) ;
2014-09-01 14:07:28 +00:00
// Remove character page
data = {
section : 'info' ,
page : 'emoticons'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page' ) . length , 1 , 'Before removing character page' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section *[rel="emoticons"].page' ) . length , 0 , 'After removing character page' ) ;
2014-09-01 14:07:28 +00:00
// Remove booklet section
data = {
section : 'info'
} ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section' ) . length , 1 , 'Before removing booklet section' ) ;
2014-09-01 14:07:28 +00:00
this . $target . wikiEditor ( 'removeFromToolbar' , data ) ;
2018-09-13 21:03:26 +00:00
assert . strictEqual ( this . $ui . find ( '*[rel="info"].section' ) . length , 0 , 'After removing booklet section' ) ;
2014-09-01 14:07:28 +00:00
} ) ;
2022-05-02 23:07:28 +00:00
} ) ;