test_asset.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require "test_helper"
  2. class TestAsset < Minitest::Test
  3. def setup
  4. @jpg_path = File.expand_path("../fixtures/cockapoo.jpg", __FILE__)
  5. @heic_path = File.expand_path("../fixtures/mammoth.heic", __FILE__)
  6. @jpg_asset = Fotos::Asset.new(@jpg_path)
  7. @heic_asset = Fotos::Asset.new(@heic_path)
  8. end
  9. def test_initializes_with_file_path
  10. assert_equal @jpg_path, @jpg_asset.file_path
  11. assert_equal @heic_path, @heic_asset.file_path
  12. end
  13. def test_dirname_returns_parent_directory_name
  14. assert_equal "fixtures", @jpg_asset.dirname
  15. assert_equal "fixtures", @heic_asset.dirname
  16. end
  17. def test_file_name_returns_basename
  18. assert_equal "cockapoo.jpg", @jpg_asset.file_name
  19. assert_equal "mammoth.heic", @heic_asset.file_name
  20. end
  21. def test_ext_name_returns_file_extension
  22. assert_equal ".jpg", @jpg_asset.ext_name
  23. assert_equal ".heic", @heic_asset.ext_name
  24. end
  25. def test_supported_returns_true_for_jpeg_jpg
  26. assert @jpg_asset.supported?
  27. refute @heic_asset.supported?
  28. end
  29. def test_thumbnail_name_adds_prefix
  30. assert_equal "TH_cockapoo.jpg", @jpg_asset.thumbnail_name
  31. assert_equal "TH_mammoth.heic", @heic_asset.thumbnail_name
  32. end
  33. def test_path_returns_relative_path
  34. assert_equal "fixtures/cockapoo.jpg", @jpg_asset.path
  35. assert_equal "fixtures/mammoth.heic", @heic_asset.path
  36. end
  37. def test_thumbnail_path_with_default_target
  38. assert_equal "fixtures/TH_cockapoo.jpg", @jpg_asset.thumbnail_path
  39. assert_equal "fixtures/TH_mammoth.heic", @heic_asset.thumbnail_path
  40. end
  41. def test_thumbnail_path_with_custom_target
  42. assert_equal "/tmp/TH_cockapoo.jpg", @jpg_asset.thumbnail_path("/tmp")
  43. assert_equal "output/TH_mammoth.heic", @heic_asset.thumbnail_path("output")
  44. end
  45. def test_is_thumbnail_detects_thumbnail_prefix
  46. thumbnail_asset = Fotos::Asset.new("/path/TH_image.jpg")
  47. regular_asset = Fotos::Asset.new("/path/image.jpg")
  48. assert thumbnail_asset.is_thumbnail?
  49. refute regular_asset.is_thumbnail?
  50. end
  51. end