Skip to content

Commit

Permalink
Merge pull request #311 from ckeditor/ck/narrow-cdn-config
Browse files Browse the repository at this point in the history
Feature: Improve result type of `useCKEditorCloud` to make `CKEditorPremiumFeatures` and `CKBox` non-nullable when proper configuration is passed.   
Fix: Rename the `languages` configuration property to `translations` in `useCKEditorCloud`.
  • Loading branch information
Mati365 authored Sep 13, 2024
2 parents 289a5ac + 5a14cc2 commit 9432709
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 18 deletions.
13 changes: 8 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ commands:
name: Prepare environment variables
command: |
#!/bin/bash
# Non-secret environment variables needed for the pipeline scripts.
CKE5_GITHUB_ORGANIZATION="ckeditor"
CKE5_GITHUB_REPOSITORY="ckeditor5-vue"
CKE5_CIRCLE_APPROVAL_JOB_NAME="release_approval"
CKE5_GITHUB_RELEASE_BRANCH="master"
echo export CKE5_CIRCLE_APPROVAL_JOB_NAME=$CKE5_CIRCLE_APPROVAL_JOB_NAME >> $BASH_ENV
echo export CKE5_GITHUB_RELEASE_BRANCH=$CKE5_GITHUB_RELEASE_BRANCH >> $BASH_ENV
echo export CKE5_GITHUB_ORGANIZATION=$CKE5_GITHUB_ORGANIZATION >> $BASH_ENV
Expand Down Expand Up @@ -117,6 +117,9 @@ jobs:
- run:
name: Build demo app
command: yarn run build
- run:
name: Check types of tests
command: yarn run test:check:types
- run:
name: Verify the code coverage
command: |
Expand Down Expand Up @@ -205,13 +208,13 @@ jobs:
name: Verify if a releaser triggered the job
command: |
#!/bin/bash
# Do not fail if the Node script ends with non-zero exit code.
set +e
yarn ckeditor5-dev-ci-is-job-triggered-by-member
EXIT_CODE=$( echo $? )
if [ ${EXIT_CODE} -ne 0 ];
then
echo "Aborting the release due to failed verification of the approver (no rights to release)."
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"lodash-es": "^4.17.21",
"@ckeditor/ckeditor5-integrations-common": "^1.0.0"
"@ckeditor/ckeditor5-integrations-common": "^2.0.0"
},
"peerDependencies": {
"ckeditor5": ">=42.0.0 || ^0.0.0-nightly",
Expand Down Expand Up @@ -82,6 +82,7 @@
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
"test": "vitest run --coverage",
"test:watch": "vitest --ui --watch",
"test:check:types": "tsc --noEmit -p ./tests/tsconfig.json",
"lint": "eslint \"{demos,src,tests}/**/*.{ts,vue}\"",
"postinstall": "node ./scripts/postinstall.js",
"changelog": "node ./scripts/changelog.js",
Expand Down
11 changes: 5 additions & 6 deletions src/useCKEditorCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useAsync, type AsyncComposableResult } from './composables/useAsync';

import {
loadCKEditorCloud,
type CdnPluginsPacks,
type CKEditorCloudConfig,
type CKEditorCloudResult
} from '@ckeditor/ckeditor5-integrations-common';
Expand All @@ -18,7 +17,7 @@ import {
*
* @param config The configuration of the CKEditor Cloud services.
* @returns The result of the loaded CKEditor Cloud services.
* @template A The type of the additional resources to load.
* @template Config The type of the CKEditor Cloud configuration.
* @experimental
* @example
* ```ts
Expand All @@ -35,11 +34,11 @@ import {
* // ..
* }
*/
export default function useCKEditorCloud<A extends CdnPluginsPacks>(
config: MaybeRefOrGetter<CKEditorCloudConfig<A>>
): AsyncComposableResult<CKEditorCloudResult<A>> {
export default function useCKEditorCloud<Config extends CKEditorCloudConfig>(
config: MaybeRefOrGetter<Config>
): AsyncComposableResult<CKEditorCloudResult<Config>> {
return useAsync(
(): Promise<CKEditorCloudResult<A>> => loadCKEditorCloud(
(): Promise<CKEditorCloudResult<Config>> => loadCKEditorCloud(
toValue( config )
)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ckeditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { nextTick } from 'vue';
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { Ckeditor } from '../src/plugin.ts';
import { Ckeditor } from '../src/plugin';
import {
MockEditor,
ModelDocument,
Expand Down
12 changes: 12 additions & 0 deletions tests/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

declare module '*.vue' {
import type { DefineComponent } from 'vue';

const Component: DefineComponent<object, object, any>;

export default Component;
}
11 changes: 11 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noImplicitAny": false
},
"include": [
"./",
"../src"
]
}
78 changes: 77 additions & 1 deletion tests/useCKEditorCloud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

import { beforeEach, describe, it, vi, expect } from 'vitest';
import { beforeEach, describe, it, vi, expect, expectTypeOf } from 'vitest';
import { flushPromises } from '@vue/test-utils';
import { ref } from 'vue';

Expand Down Expand Up @@ -53,4 +53,80 @@ describe( 'useCKEditorCloud', () => {
expect( data.value?.CKEditorPremiumFeatures ).toBeDefined();
} );
} );

describe( 'typings', () => {
it( 'should return non-nullable premium features entry type if premium is enabled', async () => {
const { data } = useCKEditorCloud( {
version: '43.0.0',
premium: true
} );
await vi.waitFor( () => {
expect( data.value?.CKEditor ).toBeDefined();
} );

if ( data.value ) {
expectTypeOf( data.value?.CKEditorPremiumFeatures ).not.toBeNullable();
}
} );

it( 'should return nullable premium features entry type if premium is not passed', async () => {
const { data } = useCKEditorCloud( {
version: '43.0.0'
} );

await vi.waitFor( () => {
expect( data.value?.CKEditor ).toBeDefined();
} );

if ( data.value ) {
expectTypeOf( data.value.CKEditorPremiumFeatures ).toBeNullable();
}
} );

it( 'should return nullable premium features entry type if premium is false', async () => {
const { data } = useCKEditorCloud( {
version: '43.0.0',
premium: false
} );

await vi.waitFor( () => {
expect( data.value?.CKEditor ).toBeDefined();
} );

if ( data.value ) {
expectTypeOf( data.value.CKEditorPremiumFeatures ).toBeNullable();
}
} );

it( 'should return non-nullable ckbox entry type if ckbox enabled', async () => {
const { data } = useCKEditorCloud( {
version: '43.0.0',
ckbox: {
version: '2.5.1'
}
} );

await vi.waitFor( () => {
expect( data.value?.CKEditor ).toBeDefined();
} );

if ( data.value ) {
expectTypeOf( data.value.CKBox ).not.toBeNullable();
}
} );

it( 'should return nullable ckbox entry type if ckbox not configured', async () => {
const { data } = useCKEditorCloud( {
version: '43.0.0'
} );

await vi.waitFor( () => {
expect( data.value?.CKEditor ).toBeDefined();
} );

if ( data.value ) {
expectTypeOf( data.value.CKBox ).toBeNullable();
}
} );
} );
} );
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1195,10 +1195,10 @@
"@ckeditor/ckeditor5-utils" "42.0.2"
ckeditor5 "42.0.2"

"@ckeditor/ckeditor5-integrations-common@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-integrations-common/-/ckeditor5-integrations-common-1.0.0.tgz#f2f73509d029398929ee30da3ae23329de5a796a"
integrity sha512-HLToIJ7FAtKX0tu9GaGb1d39Kx0i0TFelAj2pQPiwPU/6DLgM5gi+m0WCZub+syruSonmZPONtWrrZZdUoDB/g==
"@ckeditor/ckeditor5-integrations-common@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@ckeditor/ckeditor5-integrations-common/-/ckeditor5-integrations-common-2.0.0.tgz#09ea8a6a6a3c01f601260a85d9af98ede78644cf"
integrity sha512-Gkt7tYVv168voQZFdN4PxVp6M5/ZgzIOrqI6uPRjuk73dYjdLCeotnEXYejE6cxyLi9m2UM2mvhXibOIKVcoPw==

"@ckeditor/ckeditor5-language@42.0.2":
version "42.0.2"
Expand Down

0 comments on commit 9432709

Please sign in to comment.