Back to Repositories

Testing Wysihtml5 Field Integration in rails_admin

This test suite validates the Wysihtml5 rich text editor field integration within Rails Admin. It ensures proper initialization and configuration of the WYSIWYG editor component through integration testing.

Test Coverage Overview

The test suite covers essential functionality of the Wysihtml5 rich text editor field integration:
  • Basic editor initialization and rendering
  • Custom configuration options handling
  • Toolbar component presence verification
  • Error-free operation validation

Implementation Analysis

The testing approach utilizes RSpec request specs with JavaScript support to validate the editor’s client-side behavior. It implements configuration testing through Rails Admin’s DSL for field customization, verifying both default and custom setups.

Key patterns include DOM element verification and configuration option validation.

Technical Details

Testing tools and configuration:
  • RSpec for test framework
  • Capybara for browser simulation
  • JavaScript-enabled testing
  • Rails Admin configuration DSL
  • Custom CSS/JS location specification

Best Practices Demonstrated

The test suite demonstrates several testing best practices:
  • Isolated test cases for distinct functionality
  • Explicit error checking
  • Clear separation of basic and advanced configuration testing
  • Proper use of subject for cleaner specs
  • Effective use of expectation matchers

railsadminteam/rails_admin

spec/integration/fields/wysihtml5_spec.rb

            
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Wysihtml5 field', type: :request do
  subject { page }

  it 'works without error', js: true do
    RailsAdmin.config Draft do
      edit do
        field :notes, :wysihtml5
      end
    end
    expect { visit new_path(model_name: 'draft') }.not_to raise_error
    is_expected.to have_selector('.wysihtml5-toolbar')
  end

  it 'should include custom wysihtml5 configuration' do
    RailsAdmin.config Draft do
      edit do
        field :notes, :wysihtml5 do
          config_options image: false
          css_location 'stub_css.css'
          js_location 'stub_js.js'
        end
      end
    end

    visit new_path(model_name: 'draft')
    is_expected.to have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"][data-options]')
  end
end