2011-04-28 04:35:10 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
2011-06-07 01:52:22 +00:00
|
|
|
class SpriteMapTest < Test::Unit::TestCase
|
2011-06-16 03:37:23 +00:00
|
|
|
include SpriteHelper
|
2011-04-28 04:35:10 +00:00
|
|
|
|
|
|
|
def setup
|
2011-05-10 23:20:38 +00:00
|
|
|
Hash.send(:include, Compass::SassExtensions::Functions::Sprites::VariableReader)
|
2011-05-10 22:02:32 +00:00
|
|
|
@images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images')
|
|
|
|
@images_tmp_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images-tmp')
|
2011-04-28 04:35:10 +00:00
|
|
|
FileUtils.cp_r @images_src_path, @images_tmp_path
|
|
|
|
config = Compass::Configuration::Data.new('config')
|
|
|
|
config.images_path = @images_tmp_path
|
|
|
|
Compass.add_configuration(config)
|
|
|
|
Compass.configure_sass_plugin!
|
2011-05-11 01:04:57 +00:00
|
|
|
@options = {'cleanup' => Sass::Script::Bool.new(true)}
|
2011-06-19 16:26:38 +00:00
|
|
|
@base = sprite_map_test(@options)
|
2011-04-28 04:35:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
FileUtils.rm_r @images_tmp_path
|
2011-06-16 03:37:23 +00:00
|
|
|
@base = nil
|
2011-04-28 04:35:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should have the correct size" do
|
|
|
|
assert_equal [10,40], @base.size
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have the sprite names" do
|
2011-06-16 03:37:23 +00:00
|
|
|
assert_equal Compass::SpriteImporter.sprite_names(URI), @base.sprite_names
|
2011-04-28 04:35:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have image filenames' do
|
|
|
|
assert_equal Dir["#{@images_tmp_path}/selectors/*.png"].sort, @base.image_filenames
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should need generation' do
|
|
|
|
assert @base.generation_required?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'uniqueness_hash' do
|
|
|
|
assert_equal 'ef52c5c63a', @base.uniqueness_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be outdated' do
|
|
|
|
assert @base.outdated?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have correct filename' do
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal File.join(@images_tmp_path, "#{@base.path}-s#{@base.uniqueness_hash}.png"), @base.filename
|
2011-04-28 04:35:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the 'ten-by-ten' image" do
|
|
|
|
assert_equal 'ten-by-ten', @base.image_for('ten-by-ten').name
|
|
|
|
assert @base.image_for('ten-by-ten').is_a?(Compass::SassExtensions::Sprites::Image)
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(target hover active).each do |selector|
|
|
|
|
it "should have a #{selector}" do
|
|
|
|
assert @base.send(:"has_#{selector}?", 'ten-by-ten')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return #{selector} image class" do
|
|
|
|
assert_equal "ten-by-ten_#{selector}", @base.image_for('ten-by-ten').send(:"#{selector}").name
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should generate sprite" do
|
|
|
|
@base.generate
|
|
|
|
assert File.exists?(@base.filename)
|
|
|
|
assert !@base.generation_required?
|
|
|
|
assert !@base.outdated?
|
|
|
|
end
|
|
|
|
|
2011-05-10 22:01:12 +00:00
|
|
|
it "should remove old sprite when generating new" do
|
|
|
|
@base.generate
|
|
|
|
file = @base.filename
|
|
|
|
assert File.exists?(file), "Original file does not exist"
|
|
|
|
file_to_remove = File.join(@images_tmp_path, 'selectors', 'ten-by-ten.png')
|
|
|
|
FileUtils.rm file_to_remove
|
|
|
|
assert !File.exists?(file_to_remove), "Failed to remove sprite file"
|
2011-06-19 16:26:38 +00:00
|
|
|
@base = sprite_map_test(@options)
|
2011-05-10 22:01:12 +00:00
|
|
|
@base.generate
|
|
|
|
assert !File.exists?(file), "Sprite file did not get removed"
|
|
|
|
end
|
|
|
|
|
2011-04-28 04:35:10 +00:00
|
|
|
end
|