• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ckeditor / ckeditor5 / 25927

pending completion
25927

Pull #14763

CKEditor5 code coverage

web-flow
Merge pull request #14753 from ckeditor/ck/14743-enablePlaceholder-API-should-remain-backward-compatible-for-some-time

Fix (engine): Made the `enablePlaceholder()` API to remain backward compatible for the deprecation period. It will be removed in the future. Closes #14743.
Pull Request #14763: Support for image height attribute

12436 of 12436 branches covered (100.0%)

Branch coverage included in aggregate %.

147 of 147 new or added lines in 10 files covered. (100.0%)

32669 of 32669 relevant lines covered (100.0%)

12002.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/packages/ckeditor5-alignment/src/utils.ts
1
/**
2
 * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
 */
5

6
import { CKEditorError, logWarning, type Locale } from 'ckeditor5/src/utils.js';
7
import type { AlignmentFormat, AlignmentSupportedOption } from './alignmentconfig.js';
8

9
/**
10
 * @module alignment/utils
11
 */
12

13
/**
14
 * The list of supported alignment options:
15
 *
16
 * * `'left'`,
17
 * * `'right'`,
18
 * * `'center'`,
19
 * * `'justify'`
20
 *
21
 * @internal
1✔
22
 */
23
export const supportedOptions: ReadonlyArray<AlignmentSupportedOption> = [ 'left', 'right', 'center', 'justify' ];
24

25
/**
26
 * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
27
 *
28
 * @internal
29
 * @param option The option value to check.
554✔
30
 */
31
export function isSupported( option: string ): boolean {
32
        return ( supportedOptions as Array<string> ).includes( option );
33
}
34

35
/**
36
 * Checks whether alignment is the default one considering the direction
37
 * of the editor content.
38
 *
39
 * @internal
40
 * @param alignment The name of the alignment to check.
41
 * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
42
 */
429✔
43
export function isDefault( alignment: string, locale: Locale ): boolean {
45✔
44
        // Right now only LTR is supported so the 'left' value is always the default one.
45

384✔
46
        if ( locale.contentLanguageDirection == 'rtl' ) {
47
                return alignment === 'right';
48
        } else {
49
                return alignment === 'left';
50
        }
51
}
52

53
/**
54
 * Brings the configuration to the common form, an array of objects.
55
 *
56
 * @internal
147✔
57
 * @param configuredOptions Alignment plugin configuration.
58
 * @returns Normalized object holding the configuration.
59
 */
60
export function normalizeAlignmentOptions( configuredOptions: Array<string | AlignmentFormat> ): Array<AlignmentFormat> {
560✔
61
        const normalizedOptions = configuredOptions
25✔
62
                .map( option => {
63
                        let result;
535✔
64

65
                        if ( typeof option == 'string' ) {
66
                                result = { name: option };
560✔
67
                        } else {
68
                                result = option;
69
                        }
70

560✔
71
                        return result as AlignmentFormat;
72
                } )
560✔
73
                // Remove all unknown options.
74
                .filter( option => {
75
                        const isNameValid = supportedOptions.includes( option.name );
76

77
                        if ( !isNameValid ) {
78
                                /**
79
                                 * The `name` in one of the `alignment.options` is not recognized.
80
                                 * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`.
1✔
81
                                 *
82
                                 * @error alignment-config-name-not-recognized
83
                                 * @param {object} option Options with unknown value of the `name` property.
560✔
84
                                 */
85
                                logWarning( 'alignment-config-name-not-recognized', { option } );
86
                        }
559✔
87

88
                        return isNameValid;
89
                } );
147✔
90

91
        const classNameCount = normalizedOptions.filter( option => Boolean( option.className ) ).length;
92

93
        // We either use classes for all styling options or for none.
94
        if ( classNameCount && classNameCount < normalizedOptions.length ) {
95
                /**
96
                 * The `className` property has to be defined for all options once at least one option declares `className`.
1✔
97
                 *
98
                 * @error alignment-config-classnames-are-missing
99
                 * @param {object} configuredOptions Contents of `alignment.options`.
100
                 */
146✔
101
                throw new CKEditorError( 'alignment-config-classnames-are-missing', { configuredOptions } );
555✔
102
        }
810✔
103

104
        // Validate resulting config.
555✔
105
        normalizedOptions.forEach( ( option, index, allOptions ) => {
106
                const succeedingOptions = allOptions.slice( index + 1 );
107
                const nameAlreadyExists = succeedingOptions.some( item => item.name == option.name );
108

109
                if ( nameAlreadyExists ) {
110
                        /**
111
                         * The same `name` in one of the `alignment.options` was already declared.
112
                         * Each `name` representing one alignment option can be set exactly once.
113
                         *
1✔
114
                         * @error alignment-config-name-already-defined
115
                         * @param {object} option First option that declares given `name`.
116
                         * @param {object} configuredOptions Contents of `alignment.options`.
117
                         */
554✔
118
                        throw new CKEditorError( 'alignment-config-name-already-defined', { option, configuredOptions } );
73✔
119
                }
120

49✔
121
                // The `className` property is present. Check for duplicates then.
122
                if ( option.className ) {
123
                        const classNameAlreadyExists = succeedingOptions.some( item => item.className == option.className );
124

125
                        if ( classNameAlreadyExists ) {
126
                                /**
127
                                 * The same `className` in one of the `alignment.options` was already declared.
128
                                 *
129
                                 * @error alignment-config-classname-already-defined
1✔
130
                                 * @param {object} option First option that declares given `className`.
131
                                 * @param {object} configuredOptions
132
                                 * Contents of `alignment.options`.
133
                                 */
134
                                throw new CKEditorError( 'alignment-config-classname-already-defined', { option, configuredOptions } );
144✔
135
                        }
136
                }
137
        } );
138

139
        return normalizedOptions;
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc