Sha256: 9eb9e22bb108973220cf9b380185d579f9af1cf996444a246bb663a3b435e8a9

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Roadie
  describe StyleAttributeBuilder do
    it "sorts the added properties" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "green", true, 1)
      builder << StyleProperty.new("font-size", "110%", false, 15)
      builder << StyleProperty.new("color", "red", false, 15)

      expect(builder.attribute_string).to eq "font-size:110%;color:red;color:green !important"
    end

    it "preserves the order of added attributes with the same specificity" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "pink",  false, 50)
      builder << StyleProperty.new("color", "red",   false, 50)
      builder << StyleProperty.new("color", "green", false, 50)

      # We need one different element to trigger the problem with Ruby's
      # unstable sort
      builder << StyleProperty.new("background", "white", false, 1)

      expect(builder.attribute_string).to eq "background:white;color:pink;color:red;color:green"
    end

    it "removes duplicate properties" do
      builder = StyleAttributeBuilder.new

      builder << StyleProperty.new("color", "pink",  false, 10)
      builder << StyleProperty.new("color", "green", false, 20)
      builder << StyleProperty.new("color", "pink",  false, 50)

      expect(builder.attribute_string).to eq "color:green;color:pink"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roadie-4.0.0 spec/lib/roadie/style_attribute_builder_spec.rb