ckeditor5 1.15.8 → 1.15.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -5
- data/README.md +3 -0
- data/lib/ckeditor5/rails/cdn/ckbox_bundle.rb +2 -2
- data/lib/ckeditor5/rails/cdn/helpers.rb +6 -0
- data/lib/ckeditor5/rails/context/helpers.rb +1 -1
- data/lib/ckeditor5/rails/editor/editable_height_normalizer.rb +50 -0
- data/lib/ckeditor5/rails/editor/helpers/config_helpers.rb +3 -3
- data/lib/ckeditor5/rails/editor/helpers/editor_helpers.rb +5 -4
- data/lib/ckeditor5/rails/editor/props.rb +3 -20
- data/lib/ckeditor5/rails/plugins/simple_upload_adapter.rb +1 -1
- data/lib/ckeditor5/rails/presets/preset_builder.rb +2 -3
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/lib/ckeditor5/rails/version_detector.rb +6 -0
- data/spec/lib/ckeditor5/rails/assets/asset_bundle_hml_serializer_spec.rb +104 -0
- data/spec/lib/ckeditor5/rails/assets/assets_bundle_spec.rb +191 -0
- data/spec/lib/ckeditor5/rails/cdn/ckbox_bundle_spec.rb +69 -0
- data/spec/lib/ckeditor5/rails/cdn/ckeditor_bundle_spec.rb +72 -0
- data/spec/lib/ckeditor5/rails/cdn/helpers_spec.rb +217 -0
- data/spec/lib/ckeditor5/rails/context/helpers_spec.rb +67 -0
- data/spec/lib/ckeditor5/rails/context/props_spec.rb +70 -0
- data/spec/lib/ckeditor5/rails/editor/editable_height_normalizer_spec.rb +50 -0
- data/spec/lib/ckeditor5/rails/editor/helpers/config_helpers_spec.rb +52 -0
- data/spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb +192 -0
- data/spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb +43 -0
- data/spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb +66 -0
- data/spec/lib/ckeditor5/rails/editor/props_spec.rb +104 -0
- data/spec/lib/ckeditor5/rails/hooks/form_spec.rb +47 -0
- data/spec/lib/ckeditor5/rails/presets/manager_spec.rb +100 -0
- data/spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb +98 -0
- data/spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb +337 -0
- data/spec/lib/ckeditor5/rails/presets/toolbar_builder_spec.rb +70 -0
- data/spec/lib/ckeditor5/rails/semver_spec.rb +58 -0
- data/spec/lib/ckeditor5/rails/version_detector_spec.rb +131 -0
- data/spec/lib/ckeditor5/rails/version_spec.rb +25 -0
- data/spec/spec_helper.rb +8 -2
- data/spec/support/test_models.rb +6 -0
- metadata +44 -1
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Cdn::CKEditorBundle do
|
6
|
+
let(:version) { CKEditor5::Rails::Semver.new('34.1.0') }
|
7
|
+
let(:import_name) { '@ckeditor/ckeditor5-build-classic' }
|
8
|
+
let(:translations) { %w[pl de] }
|
9
|
+
let(:cdn) { 'https://cdn.example.com' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(CKEditor5::Rails::Engine.default_preset).to receive(:cdn).and_return(cdn)
|
13
|
+
allow_any_instance_of(described_class).to receive(:create_cdn_url) do |_, pkg, ver, file|
|
14
|
+
"#{cdn}/npm/#{pkg}@#{ver}/build/#{file}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#initialize' do
|
19
|
+
it 'creates instance with valid parameters' do
|
20
|
+
expect do
|
21
|
+
described_class.new(version, import_name, translations: translations)
|
22
|
+
end.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises error when version is not Semver' do
|
26
|
+
expect do
|
27
|
+
described_class.new('34.1.0', import_name)
|
28
|
+
end.to raise_error(ArgumentError, 'version must be semver')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises error when import_name is not string' do
|
32
|
+
expect do
|
33
|
+
described_class.new(version, :invalid)
|
34
|
+
end.to raise_error(ArgumentError, 'import_name must be a string')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises error when translations is not array' do
|
38
|
+
expect do
|
39
|
+
described_class.new(version, import_name, translations: 'invalid')
|
40
|
+
end.to raise_error(ArgumentError, 'translations must be an array')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#scripts' do
|
45
|
+
subject(:bundle) { described_class.new(version, import_name, translations: translations) }
|
46
|
+
|
47
|
+
it 'returns main script and translation scripts' do
|
48
|
+
expect(bundle.scripts.count).to eq(3)
|
49
|
+
expect(bundle.scripts.first.url).to eq("#{cdn}/npm/#{import_name}@#{version}/build/#{import_name}.js")
|
50
|
+
expect(bundle.scripts.first).not_to be_translation
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'includes translation scripts' do
|
54
|
+
translation_scripts = bundle.scripts.select(&:translation?)
|
55
|
+
expect(translation_scripts.count).to eq(2)
|
56
|
+
expect(translation_scripts.map(&:url)).to contain_exactly(
|
57
|
+
"#{cdn}/npm/#{import_name}@#{version}/build/translations/pl.js",
|
58
|
+
"#{cdn}/npm/#{import_name}@#{version}/build/translations/de.js"
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#stylesheets' do
|
64
|
+
subject(:bundle) { described_class.new(version, import_name) }
|
65
|
+
|
66
|
+
it 'returns stylesheet URL' do
|
67
|
+
expect(bundle.stylesheets).to eq(
|
68
|
+
["#{cdn}/npm/#{import_name}@#{version}/build/#{import_name}.css"]
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Cdn::Helpers do
|
6
|
+
let(:test_class) { Class.new { include CKEditor5::Rails::Cdn::Helpers } }
|
7
|
+
let(:helper) { test_class.new }
|
8
|
+
let(:preset) do
|
9
|
+
instance_double(
|
10
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
11
|
+
to_h_with_overrides: {
|
12
|
+
cdn: :cloud,
|
13
|
+
version: '34.1.0',
|
14
|
+
type: 'classic',
|
15
|
+
translations: %w[pl],
|
16
|
+
ckbox: nil,
|
17
|
+
license_key: nil,
|
18
|
+
premium: false
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
let(:bundle_html) { '<script src="test.js"></script>' }
|
23
|
+
let(:serializer) do
|
24
|
+
instance_double(CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer, to_html: bundle_html)
|
25
|
+
end
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(CKEditor5::Rails::Engine).to receive(:find_preset).and_return(preset)
|
29
|
+
allow(CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer).to receive(:new).and_return(serializer)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#ckeditor5_assets' do
|
33
|
+
context 'with valid preset' do
|
34
|
+
it 'returns serialized bundle html' do
|
35
|
+
expect(helper.ckeditor5_assets(preset: :default)).to eq(bundle_html)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'creates base bundle' do
|
39
|
+
expect(CKEditor5::Rails::Cdn::CKEditorBundle).to receive(:new)
|
40
|
+
.with(
|
41
|
+
instance_of(CKEditor5::Rails::Semver),
|
42
|
+
'ckeditor5',
|
43
|
+
translations: %w[pl],
|
44
|
+
cdn: :cloud
|
45
|
+
)
|
46
|
+
.and_call_original
|
47
|
+
|
48
|
+
helper.ckeditor5_assets(preset: :default)
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with premium features' do
|
52
|
+
let(:preset) do
|
53
|
+
instance_double(
|
54
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
55
|
+
to_h_with_overrides: {
|
56
|
+
cdn: :cloud,
|
57
|
+
version: '34.1.0',
|
58
|
+
type: 'classic',
|
59
|
+
translations: %w[pl],
|
60
|
+
ckbox: nil,
|
61
|
+
license_key: nil,
|
62
|
+
premium: true
|
63
|
+
}
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'creates base and premium bundles' do
|
68
|
+
expect(CKEditor5::Rails::Cdn::CKEditorBundle).to receive(:new)
|
69
|
+
.with(
|
70
|
+
instance_of(CKEditor5::Rails::Semver),
|
71
|
+
'ckeditor5',
|
72
|
+
translations: %w[pl],
|
73
|
+
cdn: :cloud
|
74
|
+
)
|
75
|
+
.and_call_original
|
76
|
+
.ordered
|
77
|
+
|
78
|
+
expect(CKEditor5::Rails::Cdn::CKEditorBundle).to receive(:new)
|
79
|
+
.with(
|
80
|
+
instance_of(CKEditor5::Rails::Semver),
|
81
|
+
'ckeditor5-premium-features',
|
82
|
+
translations: %w[pl],
|
83
|
+
cdn: :cloud
|
84
|
+
)
|
85
|
+
.and_call_original
|
86
|
+
.ordered
|
87
|
+
|
88
|
+
helper.ckeditor5_assets(preset: :default)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with ckbox' do
|
93
|
+
let(:preset) do
|
94
|
+
instance_double(
|
95
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
96
|
+
to_h_with_overrides: {
|
97
|
+
cdn: :cloud,
|
98
|
+
version: '34.1.0',
|
99
|
+
type: 'classic',
|
100
|
+
translations: %w[pl],
|
101
|
+
ckbox: { version: '1.0.0', theme: :lark },
|
102
|
+
license_key: nil,
|
103
|
+
premium: false
|
104
|
+
}
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'creates ckbox bundle' do
|
109
|
+
expect(CKEditor5::Rails::Cdn::CKBoxBundle).to receive(:new)
|
110
|
+
.with(
|
111
|
+
instance_of(CKEditor5::Rails::Semver),
|
112
|
+
theme: :lark,
|
113
|
+
cdn: :ckbox
|
114
|
+
)
|
115
|
+
.and_call_original
|
116
|
+
|
117
|
+
helper.ckeditor5_assets(preset: :default)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when destructuring preset hash' do
|
122
|
+
let(:preset) do
|
123
|
+
instance_double(
|
124
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
125
|
+
to_h_with_overrides: {
|
126
|
+
cdn: :cloud,
|
127
|
+
version: '34.1.0',
|
128
|
+
type: 'classic',
|
129
|
+
translations: %w[pl],
|
130
|
+
ckbox: nil,
|
131
|
+
license_key: nil,
|
132
|
+
premium: false,
|
133
|
+
extra: 'value'
|
134
|
+
}
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'successfully matches and extracts required parameters' do
|
139
|
+
expect { helper.ckeditor5_assets(preset: :default) }.not_to raise_error
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'with invalid preset' do
|
145
|
+
before do
|
146
|
+
allow(CKEditor5::Rails::Engine).to receive(:find_preset).and_return(nil)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'raises error' do
|
150
|
+
expect { helper.ckeditor5_assets(preset: :invalid) }
|
151
|
+
.to raise_error(ArgumentError, /forgot to define your invalid preset/)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'with missing required parameters' do
|
156
|
+
let(:preset) do
|
157
|
+
instance_double(
|
158
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
159
|
+
to_h_with_overrides: { cdn: :cloud }
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'raises error when version is missing' do
|
164
|
+
expect { helper.ckeditor5_assets(preset: :default) }
|
165
|
+
.to raise_error(ArgumentError, /forgot to define version/)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when overriding preset values with kwargs' do
|
171
|
+
let(:preset) do
|
172
|
+
CKEditor5::Rails::Presets::PresetBuilder.new do
|
173
|
+
version '34.1.0'
|
174
|
+
type :classic
|
175
|
+
translations :pl
|
176
|
+
cdn :cloud
|
177
|
+
license_key 'preset-license'
|
178
|
+
premium false
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
before do
|
183
|
+
allow(CKEditor5::Rails::Engine).to receive(:find_preset).and_return(preset)
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'allows overriding preset values with kwargs' do
|
187
|
+
result = helper.send(:merge_with_editor_preset, :default, license_key: 'overridden-license')
|
188
|
+
expect(result).to include(license_key: 'overridden-license')
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'preserves non-overridden preset values' do
|
192
|
+
result = helper.send(:merge_with_editor_preset, :default, license_key: 'overridden-license')
|
193
|
+
expect(result).to eq(
|
194
|
+
version: '34.1.0',
|
195
|
+
premium: false,
|
196
|
+
cdn: :cloud,
|
197
|
+
translations: [:pl],
|
198
|
+
license_key: 'overridden-license',
|
199
|
+
type: :classic,
|
200
|
+
ckbox: nil,
|
201
|
+
config: { plugins: [], toolbar: [] }
|
202
|
+
)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'cdn helper methods' do
|
207
|
+
it 'generates helper methods for third-party CDNs' do
|
208
|
+
expect(helper).to respond_to(:ckeditor5_unpkg_assets)
|
209
|
+
expect(helper).to respond_to(:ckeditor5_jsdelivr_assets)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'calls main helper with proper cdn parameter' do
|
213
|
+
expect(helper).to receive(:ckeditor5_assets).with(cdn: :unpkg, version: '34.1.0')
|
214
|
+
helper.ckeditor5_unpkg_assets(version: '34.1.0')
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'action_view'
|
5
|
+
|
6
|
+
RSpec.describe CKEditor5::Rails::Context::Helpers do
|
7
|
+
let(:test_class) do
|
8
|
+
Class.new do
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
include CKEditor5::Rails::Context::Helpers
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:helper) { test_class.new }
|
15
|
+
|
16
|
+
describe '#ckeditor5_context' do
|
17
|
+
it 'creates context component with default attributes' do
|
18
|
+
expect(helper.ckeditor5_context).to have_tag(
|
19
|
+
'ckeditor-context-component',
|
20
|
+
with: {
|
21
|
+
plugins: '[]',
|
22
|
+
config: '{}'
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'creates context component with preset configuration' do
|
28
|
+
expect(helper.ckeditor5_context(preset: :custom)).to have_tag(
|
29
|
+
'ckeditor-context-component',
|
30
|
+
with: {
|
31
|
+
plugins: '[]',
|
32
|
+
config: '{"preset":"custom"}'
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'creates context component with cdn configuration' do
|
38
|
+
expect(helper.ckeditor5_context(cdn: :jsdelivr)).to have_tag(
|
39
|
+
'ckeditor-context-component',
|
40
|
+
with: {
|
41
|
+
plugins: '[]',
|
42
|
+
config: '{"cdn":"jsdelivr"}'
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'creates context component with multiple configurations' do
|
48
|
+
result = helper.ckeditor5_context(preset: :custom, cdn: :jsdelivr)
|
49
|
+
|
50
|
+
expect(result).to have_tag(
|
51
|
+
'ckeditor-context-component',
|
52
|
+
with: {
|
53
|
+
plugins: '[]',
|
54
|
+
config: '{"preset":"custom","cdn":"jsdelivr"}'
|
55
|
+
}
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'accepts block content' do
|
60
|
+
result = helper.ckeditor5_context { 'Content' }
|
61
|
+
|
62
|
+
expect(result).to have_tag('ckeditor-context-component') do
|
63
|
+
with_text 'Content'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Context::Props do
|
6
|
+
let(:config) do
|
7
|
+
{
|
8
|
+
plugins: [
|
9
|
+
CKEditor5::Rails::Editor::PropsPlugin.new('Plugin1', import_name: '@ckeditor/plugin1'),
|
10
|
+
CKEditor5::Rails::Editor::PropsInlinePlugin.new('plugin2', 'export default class Plugin2 {}')
|
11
|
+
],
|
12
|
+
toolbar: { items: %w[bold italic] },
|
13
|
+
language: 'en'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
subject(:props) { described_class.new(config) }
|
18
|
+
|
19
|
+
describe '#initialize' do
|
20
|
+
it 'accepts a config hash' do
|
21
|
+
expect { described_class.new({}) }.not_to raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#to_attributes' do
|
26
|
+
subject(:attributes) { props.to_attributes }
|
27
|
+
|
28
|
+
it 'returns a hash with plugins and config keys' do
|
29
|
+
expect(attributes).to be_a(Hash)
|
30
|
+
expect(attributes.keys).to match_array(%i[plugins config])
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ':plugins key' do
|
34
|
+
subject(:plugins_json) { attributes[:plugins] }
|
35
|
+
|
36
|
+
it 'serializes plugins array to JSON' do
|
37
|
+
expect(plugins_json).to be_a(String)
|
38
|
+
expect(JSON.parse(plugins_json)).to be_an(Array)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'normalizes and includes all plugins' do
|
42
|
+
plugins = JSON.parse(plugins_json)
|
43
|
+
expect(plugins.size).to eq(2)
|
44
|
+
expect(plugins.first).to include(
|
45
|
+
'type' => 'external',
|
46
|
+
'import_name' => '@ckeditor/plugin1'
|
47
|
+
)
|
48
|
+
expect(plugins.last).to include(
|
49
|
+
'type' => 'inline',
|
50
|
+
'name' => 'plugin2',
|
51
|
+
'code' => 'export default class Plugin2 {}'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe ':config key' do
|
57
|
+
subject(:config_json) { attributes[:config] }
|
58
|
+
|
59
|
+
it 'serializes config to JSON excluding plugins' do
|
60
|
+
expect(config_json).to be_a(String)
|
61
|
+
parsed = JSON.parse(config_json)
|
62
|
+
expect(parsed).to include(
|
63
|
+
'toolbar' => { 'items' => %w[bold italic] },
|
64
|
+
'language' => 'en'
|
65
|
+
)
|
66
|
+
expect(parsed).not_to include('plugins')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Editor::EditableHeightNormalizer do
|
6
|
+
subject(:normalizer) { described_class.new(editor_type) }
|
7
|
+
|
8
|
+
describe '#normalize' do
|
9
|
+
context 'when editor type is classic' do
|
10
|
+
let(:editor_type) { :classic }
|
11
|
+
|
12
|
+
it 'returns nil when value is nil' do
|
13
|
+
expect(normalizer.normalize(nil)).to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'converts integer to pixel string' do
|
17
|
+
expect(normalizer.normalize(500)).to eq('500px')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts valid pixel string' do
|
21
|
+
expect(normalizer.normalize('300px')).to eq('300px')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises error for invalid string format' do
|
25
|
+
expect { normalizer.normalize('500') }.to raise_error(
|
26
|
+
CKEditor5::Rails::Editor::InvalidEditableHeightError,
|
27
|
+
/editable_height must be an integer representing pixels or string ending with 'px'/
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises error for invalid value type' do
|
32
|
+
expect { normalizer.normalize([]) }.to raise_error(
|
33
|
+
CKEditor5::Rails::Editor::InvalidEditableHeightError,
|
34
|
+
/editable_height must be an integer representing pixels or string ending with 'px'/
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when editor type is not classic' do
|
40
|
+
let(:editor_type) { :inline }
|
41
|
+
|
42
|
+
it 'raises error' do
|
43
|
+
expect { normalizer.normalize(500) }.to raise_error(
|
44
|
+
CKEditor5::Rails::Editor::InvalidEditableHeightError,
|
45
|
+
'editable_height can be used only with ClassicEditor'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Editor::Helpers::Config do
|
6
|
+
let(:test_class) { Class.new { include CKEditor5::Rails::Editor::Helpers::Config } }
|
7
|
+
let(:helper) { test_class.new }
|
8
|
+
|
9
|
+
describe '#ckeditor5_element_ref' do
|
10
|
+
it 'returns a hash with $element key' do
|
11
|
+
expect(helper.ckeditor5_element_ref('#editor')).to eq({ '$element': '#editor' })
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts any selector string' do
|
15
|
+
expect(helper.ckeditor5_element_ref('.custom-editor')).to eq({ '$element': '.custom-editor' })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#ckeditor5_preset' do
|
20
|
+
let(:preset_builder) { instance_double(CKEditor5::Rails::Presets::PresetBuilder) }
|
21
|
+
|
22
|
+
context 'when name is provided' do
|
23
|
+
before do
|
24
|
+
allow(CKEditor5::Rails::Engine).to receive(:find_preset).with(:default).and_return(preset_builder)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns preset from engine' do
|
28
|
+
expect(helper.ckeditor5_preset(:default)).to eq(preset_builder)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when block is provided' do
|
33
|
+
it 'returns new PresetBuilder instance' do
|
34
|
+
expect(CKEditor5::Rails::Presets::PresetBuilder).to receive(:new)
|
35
|
+
helper.ckeditor5_preset {}
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'yields the block to PresetBuilder' do
|
39
|
+
expect { |b| helper.ckeditor5_preset(&b) }.to yield_control
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when neither name nor block is provided' do
|
44
|
+
it 'raises ArgumentError' do
|
45
|
+
expect { helper.ckeditor5_preset }.to raise_error(
|
46
|
+
ArgumentError,
|
47
|
+
'Configuration block is required for preset definition'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|