Add unit tests for AiAssistUI class to ensure functionality and reliability of UI components #34
Open
Add unit tests for AiAssistUI class to ensure functionality and reliability of UI components #34
Conversation
…ternal access for testing and integration purposes test(aiassistui.ts): add unit tests for AiAssistUI class to ensure functionality and reliability of UI components and interactions
jjroelofs
requested changes
Nov 18, 2024
Contributor
jjroelofs
left a comment
There was a problem hiding this comment.
I installed sinon but get an error message about a missing sinon config file and another failure, please check it out. I recommend using a separate PR or just commit to 1.x with the required file, however if you update packages please use yarn, not npm, and commit changes to the yarn.lock file to ensure we are on the same versions of dependencies.
(base) jur@jurs-MacBook-Pro ckeditor5-ai-assist % yarn run test
yarn run v1.22.22
warning ../package.json: No license field
$ ckeditor5-package-tools test
Entry file saved in "/Users/jur/www/ckeditor5-ai-assist/tmp/tests-entry-point.js".
START:
Webpack bundling...
asset commons.js 6.4 MiB [emitted] (name: commons) (id hint: commons)
asset runtime.js 8.53 KiB [emitted] (name: runtime)
asset tests-entry-point.3893782553.js 1.04 KiB [emitted] (name: tests-entry-point.3893782553)
Entrypoint tests-entry-point.3893782553 6.41 MiB = runtime.js 8.53 KiB commons.js 6.4 MiB tests-entry-point.3893782553.js 1.04 KiB
ERROR in /Users/jur/www/ckeditor5-ai-assist/tests/aiassistui.ts
./tests/aiassistui.ts 6:18-25
[tsl] ERROR in /Users/jur/www/ckeditor5-ai-assist/tests/aiassistui.ts(6,19)
TS7016: Could not find a declaration file for module 'sinon'. '/Users/jur/www/ckeditor5-ai-assist/node_modules/sinon/pkg/sinon-esm.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/sinon` if it exists or add a new declaration (.d.ts) file containing `declare module 'sinon';`
ts-loader-default_aadc0d91f92e8c5c
@ ./tmp/tests-entry-point.js 2:0-64
webpack 5.96.1 compiled with 1 error in 2858 ms
18 11 2024 14:45:00.082:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
18 11 2024 14:45:00.082:INFO [launcher]: Launching browsers CHROME_LOCAL with concurrency unlimited
18 11 2024 14:45:00.085:INFO [launcher]: Starting browser Chrome
18 11 2024 14:45:00.988:INFO [Chrome 130.0.0.0 (Mac OS 10.15.7)]: Connected on socket 7dp7RiH8-FXgf5LyAAAB with id 82012254
AiAssist
✔ should be named
init()
✖ "before each" hook for "should load AiAssist"
✖ "after each" hook for "should load AiAssist"
AiAssistUI
✔ should be loaded
✔ should handle inline-slash element correctly
initializeUIComponents()
✔ should register inline-slash schema and conversions
✔ should initialize UI components
✔ should add aiAssistButton to the toolbar
attachListener()
✔ should attach event listeners to the editor
PlaceHolder For AI prompt
✔ should show placeholder at the specified position
✔ should hide placeholder if no position is specified
✔ should hide the placeholder element
AI request loader
✔ should show loader at the specified position
✔ should hide loader if no position is specified
✔ should hide the loader element
LOG: 'Showing error message...', 'Test error message'
AI request error
✔ should show error tooltip with the specified message
✔ should hide the error tooltip element
applyPlaceholderToCurrentLine()
✔ should show placeholder for empty lines
✔ should hide placeholder for non-empty lines
CKEditor5 AiAssist DLL
✔ exports AiAssist
icons
✔ exports the "ckeditor" icon
Finished in 2.296 secs / 2.034 secs @ 14:45:03 GMT+0100 (Central European Standard Time)
SUMMARY:
✔ 19 tests completed
✖ 2 tests failed
FAILED TESTS:
AiAssist
init()
✖ "before each" hook for "should load AiAssist"
Chrome 130.0.0.0 (Mac OS 10.15.7)
Error: AiAssist: apiKey is required.
at AiAssist.validateConfiguration (webpack://@dxpr/ckeditor5-ai-assist/./src/aiassist.js?:54:19)
at new AiAssist (webpack://@dxpr/ckeditor5-ai-assist/./src/aiassist.js?:44:14)
at eval (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-core/src/plugincollection.js?:334:52)
at Array.map (<anonymous>)
at loadPlugins (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-core/src/plugincollection.js?:332:39)
at PluginCollection.init (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-core/src/plugincollection.js?:161:33)
at ClassicEditor.initPlugins (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-core/src/editor/editor.js?:301:29)
at eval (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-editor-classic/src/classiceditor.js?:173:28)
at new Promise (<anonymous>)
at ClassicEditor.create (webpack://@dxpr/ckeditor5-ai-assist/./node_modules/@ckeditor/ckeditor5-editor-classic/src/classiceditor.js?:171:16)
✖ "after each" hook for "should load AiAssist"
Chrome 130.0.0.0 (Mac OS 10.15.7)
TypeError: Cannot read properties of undefined (reading 'destroy')
at Context.eval (webpack://@dxpr/ckeditor5-ai-assist/./tests/aiassist.ts?:37:27)
/Users/jur/www/ckeditor5-ai-assist/node_modules/@ckeditor/ckeditor5-package-tools/lib/tasks/test.js:36
reject( new Error( `Karma finished with "${ exitCode }" code.` ) );
^
Error: Karma finished with "1" code.
at /Users/jur/www/ckeditor5-ai-assist/node_modules/@ckeditor/ckeditor5-package-tools/lib/tasks/test.js:36:13
at removeAllListeners (/Users/jur/www/ckeditor5-ai-assist/node_modules/karma/lib/server.js:468:9)
at Server.<anonymous> (/Users/jur/www/ckeditor5-ai-assist/node_modules/karma/lib/server.js:475:9)
at Object.onceWrapper (node:events:633:28)
at Server.emit (node:events:531:35)
at Server.emit (node:domain:488:12)
at emitCloseNT (node:net:2376:8)
at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
Node.js v22.9.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
(base) jur@jurs-MacBook-Pro ckeditor5-ai-assist %
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure the following dependencies are added to the project to prevent errors and maintain consistency across all pull requests:
This is a common requirement, and including these dependencies in the project setup will avoid the need to include them individually in each pull request.