• 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, SupportedOption } 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
export const supportedOptions: ReadonlyArray<SupportedOption> = [ 'left', 'right', 'center', 'justify' ];
1✔
22

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

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

42
        if ( locale.contentLanguageDirection == 'rtl' ) {
429✔
43
                return alignment === 'right';
45✔
44
        } else {
45
                return alignment === 'left';
384✔
46
        }
47
}
48

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

60
                        if ( typeof option == 'string' ) {
560✔
61
                                result = { name: option };
25✔
62
                        } else {
63
                                result = option;
535✔
64
                        }
65

66
                        return result as AlignmentFormat;
560✔
67
                } )
68
                // Remove all unknown options.
69
                .filter( option => {
70
                        const isNameValid = supportedOptions.includes( option.name );
560✔
71

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

83
                        return isNameValid;
560✔
84
                } );
85

86
        const classNameCount = normalizedOptions.filter( option => Boolean( option.className ) ).length;
559✔
87

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

99
        // Validate resulting config.
100
        normalizedOptions.forEach( ( option, index, allOptions ) => {
146✔
101
                const succeedingOptions = allOptions.slice( index + 1 );
555✔
102
                const nameAlreadyExists = succeedingOptions.some( item => item.name == option.name );
810✔
103

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

116
                // The `className` property is present. Check for duplicates then.
117
                if ( option.className ) {
554✔
118
                        const classNameAlreadyExists = succeedingOptions.some( item => item.className == option.className );
73✔
119

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

134
        return normalizedOptions;
144✔
135
}
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