Sha256: f07500b255e83a141f3ebf93fb9e2860f9b20e48229b0b104d5d7177c8e736ea

Contents?: true

Size: 1.94 KB

Versions: 25

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CKEditor5::Rails::Context::PresetSerializer do
  let(:preset) do
    CKEditor5::Rails::Context::PresetBuilder.new do
      plugin 'Plugin1', import_name: '@ckeditor/plugin1'
      inline_plugin 'plugin2', 'export default class Plugin2 {}'

      configure :toolbar, { items: %w[bold italic] }
      configure :language, 'en'
    end
  end

  subject(:serializer) { described_class.new(preset) }

  describe '#initialize' do
    it 'accepts a preset instance' do
      expect { described_class.new(preset) }.not_to raise_error
    end
  end

  describe '#to_attributes' do
    subject(:attributes) { serializer.to_attributes }

    it 'returns a hash with plugins and config keys' do
      expect(attributes).to be_a(Hash)
      expect(attributes.keys).to match_array(%i[plugins config])
    end

    describe ':plugins key' do
      subject(:plugins_json) { attributes[:plugins] }

      it 'serializes plugins array to JSON' do
        expect(plugins_json).to be_a(String)
        expect(JSON.parse(plugins_json)).to be_an(Array)
      end

      it 'normalizes and includes all plugins' do
        plugins = JSON.parse(plugins_json)
        expect(plugins.size).to eq(2)
        expect(plugins.first).to include(
          'type' => 'external',
          'import_name' => '@ckeditor/plugin1'
        )
        expect(plugins.last).to include(
          'type' => 'inline',
          'name' => 'plugin2',
          'code' => 'export default class Plugin2 {}'
        )
      end
    end

    describe ':config key' do
      subject(:config_json) { attributes[:config] }

      it 'serializes config to JSON excluding plugins' do
        expect(config_json).to be_a(String)
        parsed = JSON.parse(config_json)
        expect(parsed).to include(
          'toolbar' => { 'items' => %w[bold italic] },
          'language' => 'en'
        )
        expect(parsed).not_to include('plugins')
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ckeditor5-1.23.5 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.23.4 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.23.3 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.23.2 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.23.1 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.23.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.22.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.21.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.20.1 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.20.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.5 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.4 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.3 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.2 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.1 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.19.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.18.3 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.18.1 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.18.0 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
ckeditor5-1.17.4 spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb