|
| 1 | +import { |
| 2 | + compileAndStringify, |
| 3 | + prepareRuntime, |
| 4 | + resetRuntime, |
| 5 | + createInstance |
| 6 | +} from '../../helpers/index' |
| 7 | + |
| 8 | +function compileSnippet (runtime, snippet) { |
| 9 | + const { render, staticRenderFns } = compileAndStringify(`<div>${snippet}</div>`) |
| 10 | + const instance = createInstance(runtime, ` |
| 11 | + new Vue({ |
| 12 | + render: ${render}, |
| 13 | + staticRenderFns: ${staticRenderFns}, |
| 14 | + el: 'body' |
| 15 | + }) |
| 16 | + `) |
| 17 | + const result = instance.getRealRoot().children[0] |
| 18 | + return result |
| 19 | +} |
| 20 | + |
| 21 | +describe('richtext component', () => { |
| 22 | + let runtime |
| 23 | + |
| 24 | + beforeAll(() => { |
| 25 | + runtime = prepareRuntime() |
| 26 | + }) |
| 27 | + |
| 28 | + afterAll(() => { |
| 29 | + resetRuntime() |
| 30 | + runtime = null |
| 31 | + }) |
| 32 | + |
| 33 | + it('with no child', () => { |
| 34 | + // pending('work in progress') |
| 35 | + expect(compileSnippet(runtime, ` |
| 36 | + <richtext></richtext> |
| 37 | + `)).toEqual({ |
| 38 | + type: 'richtext' |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + it('with single text node', () => { |
| 43 | + // pending('work in progress') |
| 44 | + expect(compileSnippet(runtime, ` |
| 45 | + <richtext>single</richtext> |
| 46 | + `)).toEqual({ |
| 47 | + type: 'richtext', |
| 48 | + attr: { |
| 49 | + value: [{ |
| 50 | + type: 'span', |
| 51 | + attr: { |
| 52 | + value: 'single' |
| 53 | + } |
| 54 | + }] |
| 55 | + } |
| 56 | + }) |
| 57 | + }) |
| 58 | + |
| 59 | + describe('span', () => { |
| 60 | + // pending('work in progress') |
| 61 | + |
| 62 | + it('single node', () => { |
| 63 | + expect(compileSnippet(runtime, ` |
| 64 | + <richtext> |
| 65 | + <span>single</span> |
| 66 | + </richtext> |
| 67 | + `)).toEqual({ |
| 68 | + type: 'richtext', |
| 69 | + attr: { |
| 70 | + value: [{ |
| 71 | + type: 'span', |
| 72 | + attr: { |
| 73 | + value: 'single' |
| 74 | + } |
| 75 | + }] |
| 76 | + } |
| 77 | + }) |
| 78 | + }) |
| 79 | + |
| 80 | + it('multiple node', () => { |
| 81 | + expect(compileSnippet(runtime, ` |
| 82 | + <richtext> |
| 83 | + <span>AAA</span> |
| 84 | + <span>BBB</span> |
| 85 | + </richtext> |
| 86 | + `)).toEqual({ |
| 87 | + type: 'richtext', |
| 88 | + attr: { |
| 89 | + value: [{ |
| 90 | + type: 'span', |
| 91 | + attr: { value: 'AAA' } |
| 92 | + }, { |
| 93 | + type: 'span', |
| 94 | + attr: { value: 'BBB' } |
| 95 | + }] |
| 96 | + } |
| 97 | + }) |
| 98 | + }) |
| 99 | + |
| 100 | + it('with raw text', () => { |
| 101 | + expect(compileSnippet(runtime, ` |
| 102 | + <richtext> |
| 103 | + AAA |
| 104 | + <span>BBB</span>CCC |
| 105 | + <span>DDD</span> |
| 106 | + </richtext> |
| 107 | + `)).toEqual({ |
| 108 | + type: 'richtext', |
| 109 | + attr: { |
| 110 | + value: [{ |
| 111 | + type: 'span', |
| 112 | + attr: { value: 'AAA' } |
| 113 | + }, { |
| 114 | + type: 'span', |
| 115 | + attr: { value: 'BBB' } |
| 116 | + }, { |
| 117 | + type: 'span', |
| 118 | + attr: { value: 'CCC' } |
| 119 | + }, { |
| 120 | + type: 'span', |
| 121 | + attr: { value: 'DDD' } |
| 122 | + }] |
| 123 | + } |
| 124 | + }) |
| 125 | + }) |
| 126 | + }) |
| 127 | + |
| 128 | + describe('a', () => { |
| 129 | + // pending('work in progress') |
| 130 | + |
| 131 | + it('single node', () => { |
| 132 | + expect(compileSnippet(runtime, ` |
| 133 | + <richtext> |
| 134 | + <a href="http://whatever.com"></a> |
| 135 | + </richtext> |
| 136 | + `)).toEqual({ |
| 137 | + type: 'richtext', |
| 138 | + attr: { |
| 139 | + value: [{ |
| 140 | + type: 'a', |
| 141 | + attr: { href: 'http://whatever.com' } |
| 142 | + }] |
| 143 | + } |
| 144 | + }) |
| 145 | + }) |
| 146 | + |
| 147 | + it('multiple node', () => { |
| 148 | + expect(compileSnippet(runtime, ` |
| 149 | + <richtext> |
| 150 | + <a href="http://a.whatever.com"></a> |
| 151 | + <a href="http://b.whatever.com"></a> |
| 152 | + </richtext> |
| 153 | + `)).toEqual({ |
| 154 | + type: 'richtext', |
| 155 | + attr: { |
| 156 | + value: [{ |
| 157 | + type: 'a', |
| 158 | + attr: { href: 'http://a.whatever.com' } |
| 159 | + }, { |
| 160 | + type: 'a', |
| 161 | + attr: { href: 'http://b.whatever.com' } |
| 162 | + }] |
| 163 | + } |
| 164 | + }) |
| 165 | + }) |
| 166 | + }) |
| 167 | + |
| 168 | + describe('image', () => { |
| 169 | + pending('work in progress') |
| 170 | + |
| 171 | + it('single node', () => { |
| 172 | + expect(compileSnippet(runtime, ` |
| 173 | + <richtext> |
| 174 | + <image src="path/to/profile.png"></image> |
| 175 | + </richtext> |
| 176 | + `)).toEqual({ |
| 177 | + type: 'richtext', |
| 178 | + attr: { |
| 179 | + value: [{ |
| 180 | + type: 'image', |
| 181 | + attr: { src: 'path/to/profile.png' } |
| 182 | + }] |
| 183 | + } |
| 184 | + }) |
| 185 | + }) |
| 186 | + |
| 187 | + it('multiple node', () => { |
| 188 | + // pending('work in progress') |
| 189 | + expect(compileSnippet(runtime, ` |
| 190 | + <richtext> |
| 191 | + <image src="path/to/A.png"></image> |
| 192 | + <image src="path/to/B.png"></image> |
| 193 | + </richtext> |
| 194 | + `)).toEqual({ |
| 195 | + type: 'richtext', |
| 196 | + attr: { |
| 197 | + value: [{ |
| 198 | + type: 'image', |
| 199 | + attr: { src: 'path/to/A.png' } |
| 200 | + }, { |
| 201 | + type: 'image', |
| 202 | + attr: { src: 'path/to/B.png' } |
| 203 | + }] |
| 204 | + } |
| 205 | + }) |
| 206 | + }) |
| 207 | + |
| 208 | + it('with width and height', () => { |
| 209 | + expect(compileSnippet(runtime, ` |
| 210 | + <richtext> |
| 211 | + <image |
| 212 | + style="width:150px;height:150px;" |
| 213 | + src="path/to/profile.png"> |
| 214 | + </image> |
| 215 | + </richtext> |
| 216 | + `)).toEqual({ |
| 217 | + type: 'richtext', |
| 218 | + attr: { |
| 219 | + value: [{ |
| 220 | + type: 'image', |
| 221 | + style: { width: '150px', height: '150px' }, |
| 222 | + attr: { src: 'path/to/profile.png' } |
| 223 | + }] |
| 224 | + } |
| 225 | + }) |
| 226 | + }) |
| 227 | + }) |
| 228 | + |
| 229 | + describe('nested', () => { |
| 230 | + pending('work in progress') |
| 231 | + |
| 232 | + it('span', () => { |
| 233 | + expect(compileSnippet(runtime, ` |
| 234 | + <richtext> |
| 235 | + <span>AAA |
| 236 | + <span> |
| 237 | + <span>BBB</span> |
| 238 | + <span><span>CCC</span>DDD</span> |
| 239 | + </span> |
| 240 | + </span> |
| 241 | + </richtext> |
| 242 | + `)).toEqual({ |
| 243 | + type: 'richtext', |
| 244 | + attr: { |
| 245 | + value: [{ |
| 246 | + type: 'span', |
| 247 | + children: [{ |
| 248 | + type: 'span', |
| 249 | + attr: { value: 'AAA' } |
| 250 | + }, { |
| 251 | + type: 'span', |
| 252 | + children: [{ |
| 253 | + type: 'span', |
| 254 | + attr: { value: 'BBB' } |
| 255 | + }, { |
| 256 | + type: 'span', |
| 257 | + children: [{ |
| 258 | + type: 'span', |
| 259 | + attr: { value: 'CCC' } |
| 260 | + }, { |
| 261 | + type: 'span', |
| 262 | + attr: { value: 'DDD' } |
| 263 | + }] |
| 264 | + }] |
| 265 | + }] |
| 266 | + }] |
| 267 | + } |
| 268 | + }) |
| 269 | + }) |
| 270 | + |
| 271 | + it('image and a', () => { |
| 272 | + expect(compileSnippet(runtime, ` |
| 273 | + <richtext> |
| 274 | + <span>title</span> |
| 275 | + <a href="http://remote.com/xx.js"> |
| 276 | + <span>name</span> |
| 277 | + <image src="path/to/yy.gif"></image> |
| 278 | + </a> |
| 279 | + </richtext> |
| 280 | + `)).toEqual({ |
| 281 | + type: 'richtext', |
| 282 | + attr: { |
| 283 | + value: [{ |
| 284 | + type: 'span', |
| 285 | + attr: { value: 'title' } |
| 286 | + }, { |
| 287 | + type: 'a', |
| 288 | + attr: { href: 'http://remote.com/xx.js' }, |
| 289 | + children: [{ |
| 290 | + type: 'span', |
| 291 | + attr: { value: 'name' } |
| 292 | + }, { |
| 293 | + type: 'image', |
| 294 | + attr: { src: 'path/to/yy.gif' } |
| 295 | + }] |
| 296 | + }] |
| 297 | + } |
| 298 | + }) |
| 299 | + }) |
| 300 | + }) |
| 301 | + |
| 302 | + describe('with styles', () => { |
| 303 | + pending('work in progress') |
| 304 | + }) |
| 305 | +}) |
0 commit comments