| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
QUnit.module( 've.dm.MWImageModel' ); |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
QUnit.test( 'Create and manipulate image nodes', ( assert ) => { |
| 13 |
const imageNode = {}, |
| 14 |
images = { |
| 15 |
mwInlineImage: { |
| 16 |
dir: 'ltr', |
| 17 |
attrs: { |
| 18 |
type: 'frameless', |
| 19 |
href: './File:Foo.jpg', |
| 20 |
src: 'http://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Foo.jpg/229px-Foo.jpg', |
| 21 |
resource: './File:Foo.jpg', |
| 22 |
align: 'left', |
| 23 |
width: '100', |
| 24 |
height: '150', |
| 25 |
mediaType: 'BITMAP', |
| 26 |
defaultSize: true |
| 27 |
}, |
| 28 |
tests: [ |
| 29 |
{ |
| 30 |
methods: { |
| 31 |
setType: 'thumb', |
| 32 |
setAlignment: 'default' |
| 33 |
}, |
| 34 |
results: { |
| 35 |
expect: { |
| 36 |
getImageNodeType: 'mwBlockImage', |
| 37 |
isBorderable: false |
| 38 |
}, |
| 39 |
position: 'oppositeToText' |
| 40 |
} |
| 41 |
} |
| 42 |
] |
| 43 |
}, |
| 44 |
mwBlockImage: { |
| 45 |
dir: 'rtl', |
| 46 |
attrs: { |
| 47 |
href: './File:Foo.jpg', |
| 48 |
src: 'http://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Foo.jpg/229px-Foo.jpg', |
| 49 |
resource: './File:Foo.jpg', |
| 50 |
type: 'thumb', |
| 51 |
align: 'default', |
| 52 |
width: '100', |
| 53 |
height: '150', |
| 54 |
mediaType: 'DRAWING', |
| 55 |
defaultSize: false |
| 56 |
}, |
| 57 |
tests: [ |
| 58 |
{ |
| 59 |
methods: { |
| 60 |
setType: 'frameless', |
| 61 |
setAlignment: 'none' |
| 62 |
}, |
| 63 |
results: { |
| 64 |
expect: { |
| 65 |
getImageNodeType: 'mwInlineImage', |
| 66 |
getAlignment: 'none' |
| 67 |
}, |
| 68 |
position: 'none' |
| 69 |
} |
| 70 |
}, |
| 71 |
{ |
| 72 |
methods: { |
| 73 |
setType: 'none', |
| 74 |
setAlignment: 'default', |
| 75 |
toggleBorder: true |
| 76 |
}, |
| 77 |
results: { |
| 78 |
expect: { |
| 79 |
getImageNodeType: 'mwInlineImage', |
| 80 |
isBorderable: true, |
| 81 |
isDefaultSize: false |
| 82 |
}, |
| 83 |
position: 'none' |
| 84 |
} |
| 85 |
}, |
| 86 |
{ |
| 87 |
methods: { |
| 88 |
setType: 'frame', |
| 89 |
setAlignment: 'default', |
| 90 |
toggleDefaultSize: true |
| 91 |
}, |
| 92 |
results: { |
| 93 |
expect: { |
| 94 |
getImageNodeType: 'mwBlockImage', |
| 95 |
isBorderable: false, |
| 96 |
isDefaultSize: true |
| 97 |
}, |
| 98 |
position: 'oppositeToText' |
| 99 |
} |
| 100 |
}, |
| 101 |
{ |
| 102 |
methods: { |
| 103 |
setType: 'frame', |
| 104 |
setAlignment: 'right' |
| 105 |
}, |
| 106 |
results: { |
| 107 |
expect: { |
| 108 |
getImageNodeType: 'mwBlockImage' |
| 109 |
}, |
| 110 |
position: 'withText' |
| 111 |
} |
| 112 |
} |
| 113 |
] |
| 114 |
} |
| 115 |
}; |
| 116 |
|
| 117 |
for ( const imageType in images ) { |
| 118 |
|
| 119 |
imageNode[ imageType ] = ve.dm.MWImageModel.static.createImageNode( |
| 120 |
images[ imageType ].attrs, |
| 121 |
imageType |
| 122 |
); |
| 123 |
|
| 124 |
|
| 125 |
assert.strictEqual( |
| 126 |
imageNode[ imageType ].type, |
| 127 |
imageType, |
| 128 |
'createImageNode node type: ' + imageType |
| 129 |
); |
| 130 |
|
| 131 |
|
| 132 |
for ( let i = 0; i < images[ imageType ].tests.length; i++ ) { |
| 133 |
const dir = images[ imageType ].dir, |
| 134 |
dummyDoc = new ve.dm.Document( [], null, null, null, null, 'en', images[ imageType ].dir ); |
| 135 |
|
| 136 |
|
| 137 |
const imageModel = ve.dm.MWImageModel.static.newFromImageAttributes( images[ imageType ].attrs, dummyDoc ); |
| 138 |
|
| 139 |
|
| 140 |
for ( const method in images[ imageType ].tests[ i ].methods ) { |
| 141 |
const value = images[ imageType ].tests[ i ].methods[ method ]; |
| 142 |
imageModel[ method ]( value ); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
for ( const method in images[ imageType ].tests[ i ].results.expect ) { |
| 147 |
const result = imageModel[ method ](), |
| 148 |
expected = images[ imageType ].tests[ i ].results.expect[ method ]; |
| 149 |
assert.deepEqual( |
| 150 |
result, |
| 151 |
expected, |
| 152 |
method |
| 153 |
); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
if ( images[ imageType ].tests[ i ].results.position ) { |
| 158 |
let expectedAlignment; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
switch ( images[ imageType ].tests[ i ].results.position ) { |
| 164 |
case 'withText': |
| 165 |
expectedAlignment = dir === 'ltr' ? 'left' : 'right'; |
| 166 |
break; |
| 167 |
case 'oppositeToText': |
| 168 |
expectedAlignment = dir === 'ltr' ? 'right' : 'left'; |
| 169 |
break; |
| 170 |
case 'none': |
| 171 |
expectedAlignment = 'none'; |
| 172 |
break; |
| 173 |
} |
| 174 |
|
| 175 |
assert.strictEqual( |
| 176 |
imageModel.getAlignment(), |
| 177 |
expectedAlignment, |
| 178 |
'getAlignment' |
| 179 |
); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
} ); |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|