-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delay parsing htmlValue when RTE is attached but not rendered (#…
…7890) * fix: delay parsing htmlValue when RTE is attached but not rendered * refactor: simplify test setup * refactor: move attach tests to own file * refactor: remove condition not needed
- Loading branch information
1 parent
0482721
commit f5682ab
Showing
5 changed files
with
124 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '../theme/lumo/vaadin-rich-text-editor-styles.js'; | ||
import '../src/vaadin-lit-rich-text-editor.js'; | ||
import './attach.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '../theme/lumo/vaadin-rich-text-editor-styles.js'; | ||
import '../src/vaadin-rich-text-editor.js'; | ||
import './attach.common.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { expect } from '@vaadin/chai-plugins'; | ||
import { fixtureSync, nextRender, nextUpdate } from '@vaadin/testing-helpers'; | ||
import sinon from 'sinon'; | ||
|
||
describe('attach/detach', () => { | ||
let rte, editor; | ||
|
||
const flushValueDebouncer = () => rte.__debounceSetValue && rte.__debounceSetValue.flush(); | ||
|
||
async function attach(shadow = false) { | ||
const parent = fixtureSync('<div></div>'); | ||
if (shadow) { | ||
parent.attachShadow({ mode: 'open' }); | ||
} | ||
parent.appendChild(rte); | ||
await nextRender(); | ||
flushValueDebouncer(); | ||
} | ||
|
||
beforeEach(async () => { | ||
rte = fixtureSync('<vaadin-rich-text-editor></vaaddin-rich-text-editor>'); | ||
await nextRender(); | ||
flushValueDebouncer(); | ||
editor = rte._editor; | ||
}); | ||
|
||
describe('detach and re-attach', () => { | ||
it('should disconnect the emitter when detached', () => { | ||
const spy = sinon.spy(editor.emitter, 'disconnect'); | ||
|
||
rte.parentNode.removeChild(rte); | ||
|
||
expect(spy).to.be.calledOnce; | ||
}); | ||
|
||
it('should re-connect the emitter when detached and re-attached', async () => { | ||
const parent = rte.parentNode; | ||
parent.removeChild(rte); | ||
|
||
const spy = sinon.spy(editor.emitter, 'connect'); | ||
|
||
parent.appendChild(rte); | ||
await nextUpdate(rte); | ||
|
||
expect(spy).to.be.calledOnce; | ||
}); | ||
|
||
it('should parse htmlValue correctly when element is attached but not rendered', async () => { | ||
await attach(true); | ||
rte.dangerouslySetHtmlValue('<p>Foo</p><ul><li>Bar</li><li>Baz</li></ul>'); | ||
rte.parentNode.shadowRoot.innerHTML = '<slot></slot>'; | ||
await nextRender(); | ||
flushValueDebouncer(); | ||
expect(rte.htmlValue).to.equal('<p>Foo</p><ul><li>Bar</li><li>Baz</li></ul>'); | ||
}); | ||
}); | ||
|
||
describe('unattached rich text editor', () => { | ||
beforeEach(() => { | ||
rte = document.createElement('vaadin-rich-text-editor'); | ||
}); | ||
|
||
it('should not throw when setting html value', () => { | ||
expect(() => rte.dangerouslySetHtmlValue('<h1>Foo</h1>')).to.not.throw(Error); | ||
}); | ||
|
||
it('should have the html value once attached', async () => { | ||
rte.dangerouslySetHtmlValue('<h1>Foo</h1>'); | ||
await attach(); | ||
|
||
expect(rte.htmlValue).to.equal('<h1>Foo</h1>'); | ||
}); | ||
|
||
it('should override the htmlValue', async () => { | ||
rte.dangerouslySetHtmlValue('<h1>Foo</h1>'); | ||
rte.value = JSON.stringify([{ insert: 'Vaadin' }]); | ||
await attach(); | ||
|
||
expect(rte.htmlValue).to.equal('<p>Vaadin</p>'); | ||
}); | ||
|
||
it('should override the value', async () => { | ||
rte.value = JSON.stringify([{ insert: 'Vaadin' }]); | ||
rte.dangerouslySetHtmlValue('<h1>Foo</h1>'); | ||
await attach(); | ||
|
||
expect(rte.htmlValue).to.equal('<h1>Foo</h1>'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters