Skip to content

Commit

Permalink
Add section for more integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Sep 3, 2024
1 parent 5f8b8d3 commit 8d7eb82
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
39 changes: 39 additions & 0 deletions docs/getting-started/integrations/angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,45 @@ The `moduleResolution` option of the TypeScript configuration determines the alg
* You can update Angular to version 18, where the `moduleResolution` option is set to `bundler` by default.
* You can import translations directly from our CDN, like: `import ‘https://cdn.ckeditor.com/ckeditor5/{@var ckeditor5-version}/translations/es.umd.js’;`. This way, the editor will load the translations automatically, so you do not need to pass them manually into the config.

### Potential issues with Jest testing

Jest is the default test runner used by many Vue apps. Unfortunately, Jest does not use a real browser. Instead, it runs tests in Node.js with the use of JSDOM. JSDOM is not a complete DOM implementation and while it is apparently sufficient for standard apps, it is not able to polyfill all the DOM APIs that CKEditor 5 requires.

A better approach to test the component inside a fully-fledged web browser, implementing a complete DOM, is to use [`jest-puppeteer`](https://github.com/smooth-code/jest-puppeteer).

If this is not possible, you can use the following mocks to make the tests pass:

```ts
window.scrollTo = jest.fn();

window.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};

for (const key of ['InputEvent', 'KeyboardEvent']) {
window[key].prototype.getTargetRanges = () => {
const range = new StaticRange({
startContainer: document.body.querySelector('.ck-editor__editable p')!,
startOffset: 0,
endContainer: document.body.querySelector('.ck-editor__editable p')!,
endOffset: 0,
});

return [range];
};
}

Range.prototype.getClientRects = () => ({
item: () => null,
length: 0,
[Symbol.iterator]: function* () {},
});
```

These mocks are not perfect and may not cover all the cases, but they should be sufficient for basic initialization and rendering editor. Keep in mind that they are not a replacement for proper browser testing and cover only the initialization and rendering of the editor.

## Contributing and reporting issues

The source code of the CKEditor 5 rich text editor component for Angular is available on GitHub in [https://github.com/ckeditor/ckeditor5-angular](https://github.com/ckeditor/ckeditor5-angular).
6 changes: 3 additions & 3 deletions docs/getting-started/integrations/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ import { userEvent } from '@testing-library/user-event';
import { DecoupledEditor, Essentials, Paragraph } from 'ckeditor5';
import { CKEditor } from '@ckeditor/ckeditor5-react';

global.window.scrollTo = jest.fn();
window.scrollTo = jest.fn();

global.window.ResizeObserver = class ResizeObserver {
window.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};

for (const key of ['InputEvent', 'KeyboardEvent']) {
global.window[key].prototype.getTargetRanges = () => {
window[key].prototype.getTargetRanges = () => {
const range = new StaticRange({
startContainer: document.body.querySelector('.ck-editor__editable p')!,
startOffset: 0,
Expand Down
41 changes: 40 additions & 1 deletion docs/getting-started/integrations/vuejs-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Since accessing the editor toolbar is not possible until after the editor instan
<script>
import { DecoupledEditor, Bold, Essentials, Italic, Paragraph, Undo } from 'ckeditor5';
import CKEditor from '@ckeditor/ckeditor5-vue';
import 'ckeditor5/ckeditor5.css';
export default {
Expand Down Expand Up @@ -476,6 +476,45 @@ export default {

For more information, refer to the {@link getting-started/setup/ui-language Setting the UI language} guide.

### Potential issues with Jest testing

Jest is the default test runner used by many Vue apps. Unfortunately, Jest does not use a real browser. Instead, it runs tests in Node.js with the use of JSDOM. JSDOM is not a complete DOM implementation and while it is apparently sufficient for standard apps, it is not able to polyfill all the DOM APIs that CKEditor&nbsp;5 requires.

A better approach to test the component inside a fully-fledged web browser, implementing a complete DOM, is to use [`jest-puppeteer`](https://github.com/smooth-code/jest-puppeteer).

If this is not possible, you can use the following mocks to make the tests pass:

```ts
window.scrollTo = jest.fn();

window.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};

for (const key of ['InputEvent', 'KeyboardEvent']) {
window[key].prototype.getTargetRanges = () => {
const range = new StaticRange({
startContainer: document.body.querySelector('.ck-editor__editable p')!,
startOffset: 0,
endContainer: document.body.querySelector('.ck-editor__editable p')!,
endOffset: 0,
});

return [range];
};
}

Range.prototype.getClientRects = () => ({
item: () => null,
length: 0,
[Symbol.iterator]: function* () {},
});
```

These mocks are not perfect and may not cover all the cases, but they should be sufficient for basic initialization and rendering editor. Keep in mind that they are not a replacement for proper browser testing and cover only the initialization and rendering of the editor.

## Contributing and reporting issues

The source code of this component is available on GitHub in [https://github.com/ckeditor/ckeditor5-vue](https://github.com/ckeditor/ckeditor5-vue).

0 comments on commit 8d7eb82

Please sign in to comment.