Browse Source
Merge pull request #2977 from mcottret/fix/fix-text-component-custom-rte-get-content Fixes #2916
Fix retrieval of text component content with custom RTE. Fixes #2916
pull/2997/head
Artur Arseniev
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
40 additions and
10 deletions
-
src/dom_components/view/ComponentTextView.js
-
test/specs/dom_components/view/ComponentTextView.js
|
|
|
@ -78,17 +78,13 @@ export default ComponentView.extend({ |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
getContent() { |
|
|
|
const { rte } = this; |
|
|
|
const { activeRte } = rte || {}; |
|
|
|
let content = ''; |
|
|
|
const { activeRte } = this; |
|
|
|
const canGetRteContent = |
|
|
|
activeRte && typeof activeRte.getContent === 'function'; |
|
|
|
|
|
|
|
if (activeRte && typeof activeRte.getContent === 'function') { |
|
|
|
content = activeRte.getContent(); |
|
|
|
} else { |
|
|
|
content = this.getChildrenContainer().innerHTML; |
|
|
|
} |
|
|
|
|
|
|
|
return content; |
|
|
|
return canGetRteContent |
|
|
|
? activeRte.getContent() |
|
|
|
: this.getChildrenContainer().innerHTML; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
@ -39,4 +39,38 @@ describe('ComponentTextView', () => { |
|
|
|
fixtures.appendChild(view.render().el); |
|
|
|
expect(view.el.innerHTML).toEqual('test'); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('.getContent', () => { |
|
|
|
let fakeRte, fakeRteContent, fakeChildContainer; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
fakeRteContent = 'fakeRteContent'; |
|
|
|
|
|
|
|
fakeRte = { |
|
|
|
getContent: jest.fn(() => fakeRteContent) |
|
|
|
}; |
|
|
|
|
|
|
|
fakeChildContainer = { |
|
|
|
innerHTML: 'fakeChildInnerHTML' |
|
|
|
}; |
|
|
|
|
|
|
|
spyOn(view, 'getChildrenContainer').and.returnValue(fakeChildContainer); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should get content from active RTE if available', () => { |
|
|
|
view.activeRte = fakeRte; |
|
|
|
expect(view.getContent()).toEqual(fakeRteContent); |
|
|
|
expect(fakeRte.getContent).toHaveBeenCalled(); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should get child container's `innerHTML` if active RTE is not available or if it has no `getContent` function", () => { |
|
|
|
expect(view.getContent()).toEqual(fakeChildContainer.innerHTML); |
|
|
|
|
|
|
|
fakeRte.getContent = null; |
|
|
|
view.activeRte = fakeRte; |
|
|
|
expect(view.getContent()).toEqual(fakeChildContainer.innerHTML); |
|
|
|
|
|
|
|
expect(view.getChildrenContainer).toHaveBeenCalledTimes(2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|