Skip to content

Commit ba2101d

Browse files
committed
chore(link+bold): add tests
1 parent d6a022a commit ba2101d

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

spec/content.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ describe('Content', function () {
293293
it('works with a partially selected tag', function () {
294294
// <div>|a<em>b|b</em></div>
295295
const host = createElement('<div>a<em>bb</em></div>')
296-
this.range.setStart(host.firstChild, 0)
296+
this.range.setStart(host.querySelector('em').firstChild, 0)
297297
this.range.setEnd(host.querySelector('em').firstChild, 1)
298298

299299
this.range = content.deleteCharacter(host, this.range, 'b')

spec/selection.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,71 @@ describe('Selection', function () {
290290
const html = getHtml(linkTags[0])
291291
expect(html).to.equal('<a class="foo bar" href="https://livingdocs.io">foobar</a>')
292292
})
293+
294+
describe('with bold:', function () {
295+
beforeEach(function () {
296+
this.oldBoldMarkup = config.boldMarkup
297+
config.boldMarkup = {
298+
type: 'tag',
299+
name: 'strong',
300+
attribs: {
301+
'class': 'foo'
302+
}
303+
}
304+
})
305+
306+
afterEach(function () {
307+
config.boldMarkup = this.oldBoldMarkup
308+
})
309+
310+
it('toggles a link bold', function () {
311+
this.selection.link('https://livingdocs.io')
312+
this.selection.makeBold()
313+
const boldTags = this.selection.getTagsByName('strong')
314+
const html = getHtml(boldTags[0])
315+
expect(html).to.equal('<strong class="foo"><a class="foo bar" href="https://livingdocs.io">foobar</a></strong>')
316+
})
317+
318+
it('toggles a link bold in a selection with text after', function () {
319+
// set foo in <div>|foo|bar</div> as the selection
320+
let range = rangy.createRange()
321+
range.setStart(this.oneWord.firstChild, 0)
322+
range.setEnd(this.oneWord.firstChild, 3)
323+
let selection = new Selection(this.oneWord, range)
324+
// link foo
325+
selection.link('https://livingdocs.io')
326+
// select 1 char more to the right (b)
327+
range = rangy.createRange()
328+
// Note: we need to use firstChild twice to get the textNode inside the a tag which is
329+
// also what the normal browser select behavior does
330+
range.setStart(this.oneWord.firstChild.firstChild, 0)
331+
range.setEnd(this.oneWord.lastChild, 1)
332+
selection = new Selection(this.oneWord, range)
333+
// make link + b char bold
334+
selection.toggleBold()
335+
const html = getHtml(this.oneWord)
336+
expect(html).to.equal('<div><strong class="foo"><a class="foo bar" href="https://livingdocs.io">foo</a>b</strong>ar</div>')
337+
})
338+
339+
it('toggles a link bold in a selection with text before', function () {
340+
// set bar in <div>foo|bar|</div> as the selection
341+
let range = rangy.createRange()
342+
range.setStart(this.oneWord.firstChild, 3)
343+
range.setEnd(this.oneWord.firstChild, 6)
344+
let selection = new Selection(this.oneWord, range)
345+
// link bar
346+
selection.link('https://livingdocs.io')
347+
// select 1 char more to the left (o)
348+
range = rangy.createRange()
349+
range.setStart(this.oneWord.firstChild, 2)
350+
range.setEnd(this.oneWord.lastChild.firstChild, 3)
351+
selection = new Selection(this.oneWord, range)
352+
// make o char + link bold
353+
selection.toggleBold()
354+
const html = getHtml(this.oneWord)
355+
expect(html).to.equal('<div>fo<strong class="foo">o<a class="foo bar" href="https://livingdocs.io">bar</a></strong></div>')
356+
})
357+
})
293358
})
294359

295360
})

0 commit comments

Comments
 (0)