Sha256: 444da53ff88a968bee7383680463ee0d3d4c4c6c10a696f947cee81a3a39d330

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe CKEditor5::Rails::Editor::PropsBasePlugin do
  describe '.normalize' do
    it 'converts string to plugin instance' do
      plugin = described_class.normalize('Bold')
      expect(plugin).to be_a(described_class)
      expect(plugin.name).to eq('Bold')
    end

    it 'converts symbol to plugin instance' do
      plugin = described_class.normalize(:Bold)
      expect(plugin).to be_a(described_class)
      expect(plugin.name).to eq(:Bold)
    end

    it 'returns existing plugin instances unchanged' do
      original = described_class.new(:Bold)
      plugin = described_class.normalize(original)
      expect(plugin).to be(original)
    end

    it 'returns inline plugin instances unchanged' do
      inline = CKEditor5::Rails::Editor::PropsInlinePlugin.new(:Custom, 'export default class {}')
      plugin = described_class.normalize(inline)
      expect(plugin).to be(inline)
    end

    it 'raises error for invalid input' do
      expect { described_class.normalize({}) }.to raise_error(ArgumentError)
    end
  end

  describe '#preload_assets_urls' do
    it 'returns empty array' do
      plugin = described_class.new(:Bold)

      expect(plugin.preload_assets_urls).to eq([])
    end
  end

  describe '#to_h' do
    it 'raises NotImplementedError' do
      plugin = described_class.new(:Bold)
      expect do
        plugin.to_h
      end.to raise_error(NotImplementedError, 'Method #to_h must be implemented in a subclass')
    end
  end

  describe '#name' do
    it 'returns the plugin name' do
      plugin = described_class.new(:Bold)
      expect(plugin.name).to eq(:Bold)
    end

    it 'preserves the type of name argument' do
      string_plugin = described_class.new('Bold')
      symbol_plugin = described_class.new(:Bold)

      expect(string_plugin.name).to eq('Bold')
      expect(symbol_plugin.name).to eq(:Bold)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ckeditor5-1.18.3 spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
ckeditor5-1.18.1 spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
ckeditor5-1.18.0 spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb