require "test_helper" class TestAsset < Minitest::Test def setup @jpg_path = File.expand_path("../fixtures/cockapoo.jpg", __FILE__) @heic_path = File.expand_path("../fixtures/mammoth.heic", __FILE__) @gif_path = File.expand_path("../fixtures/frog.gif", __FILE__) @jpg_asset = Fotos::Asset.new(@jpg_path) @heic_asset = Fotos::Asset.new(@heic_path) @gif_asset = Fotos::Asset.new(@gif_path) end def test_initializes_with_file_path assert_equal @jpg_path, @jpg_asset.file_path assert_equal @heic_path, @heic_asset.file_path assert_equal @gif_path, @gif_asset.file_path end def test_dirname_returns_parent_directory_name assert_equal "fixtures", @jpg_asset.dirname assert_equal "fixtures", @heic_asset.dirname assert_equal "fixtures", @gif_asset.dirname end def test_file_name_returns_basename assert_equal "cockapoo.jpg", @jpg_asset.file_name assert_equal "mammoth.heic", @heic_asset.file_name assert_equal "frog.gif", @gif_asset.file_name end def test_ext_name_returns_file_extension assert_equal ".jpg", @jpg_asset.ext_name assert_equal ".heic", @heic_asset.ext_name assert_equal ".gif", @gif_asset.ext_name end def test_supported_returns_true_for_jpeg_jpg assert @jpg_asset.supported? assert @heic_asset.supported? refute @gif_asset.supported? end def test_thumbnail_name_adds_prefix assert_equal "TH_cockapoo.jpg", @jpg_asset.thumbnail_name assert_equal "TH_mammoth.heic", @heic_asset.thumbnail_name end def test_path_returns_relative_path assert_equal "fixtures/cockapoo.jpg", @jpg_asset.path assert_equal "fixtures/mammoth.heic", @heic_asset.path end def test_thumbnail_path_with_default_target assert_equal "fixtures/TH_cockapoo.jpg", @jpg_asset.thumbnail_path assert_equal "fixtures/TH_mammoth.heic", @heic_asset.thumbnail_path end def test_thumbnail_path_with_custom_target assert_equal "/tmp/TH_cockapoo.jpg", @jpg_asset.thumbnail_path("/tmp") assert_equal "output/TH_mammoth.heic", @heic_asset.thumbnail_path("output") end def test_is_thumbnail_detects_thumbnail_prefix thumbnail_asset = Fotos::Asset.new("/path/TH_image.jpg") regular_asset = Fotos::Asset.new("/path/image.jpg") assert thumbnail_asset.is_thumbnail? refute regular_asset.is_thumbnail? end end