test_asset.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @gif_path = File.expand_path("../fixtures/frog.gif", __FILE__)
  7. @jpg_asset = Fotos::Asset.new(@jpg_path)
  8. @heic_asset = Fotos::Asset.new(@heic_path)
  9. @gif_asset = Fotos::Asset.new(@gif_path)
  10. end
  11. def test_initializes_with_file_path
  12. assert_equal @jpg_path, @jpg_asset.file_path
  13. assert_equal @heic_path, @heic_asset.file_path
  14. assert_equal @gif_path, @gif_asset.file_path
  15. end
  16. def test_dirname_returns_parent_directory_name
  17. assert_equal "fixtures", @jpg_asset.dirname
  18. assert_equal "fixtures", @heic_asset.dirname
  19. assert_equal "fixtures", @gif_asset.dirname
  20. end
  21. def test_file_name_returns_basename
  22. assert_equal "cockapoo.jpg", @jpg_asset.file_name
  23. assert_equal "mammoth.heic", @heic_asset.file_name
  24. assert_equal "frog.gif", @gif_asset.file_name
  25. end
  26. def test_ext_name_returns_file_extension
  27. assert_equal ".jpg", @jpg_asset.ext_name
  28. assert_equal ".heic", @heic_asset.ext_name
  29. assert_equal ".gif", @gif_asset.ext_name
  30. end
  31. def test_supported_returns_true_for_jpeg_jpg
  32. assert @jpg_asset.supported?
  33. assert @heic_asset.supported?
  34. refute @gif_asset.supported?
  35. end
  36. def test_web_supported
  37. assert @jpg_asset.web_supported?
  38. refute @heic_asset.web_supported?
  39. assert @gif_asset.web_supported?
  40. end
  41. def test_thumbnail_name_adds_prefix
  42. assert_equal "TH_cockapoo.jpg", @jpg_asset.thumbnail_name
  43. assert_equal "TH_mammoth.heic", @heic_asset.thumbnail_name
  44. end
  45. def test_path_returns_relative_path
  46. assert_equal "fixtures/cockapoo.jpg", @jpg_asset.path
  47. assert_equal "fixtures/mammoth.heic", @heic_asset.path
  48. end
  49. def test_thumbnail_path_with_default_target
  50. assert_equal "fixtures/TH_cockapoo.jpg", @jpg_asset.thumbnail_path
  51. assert_equal "fixtures/TH_mammoth.heic", @heic_asset.thumbnail_path
  52. end
  53. def test_thumbnail_path_with_custom_target
  54. assert_equal "/tmp/TH_cockapoo.jpg", @jpg_asset.thumbnail_path("/tmp")
  55. assert_equal "output/TH_mammoth.heic", @heic_asset.thumbnail_path("output")
  56. end
  57. def test_is_thumbnail_detects_thumbnail_prefix
  58. thumbnail_asset = Fotos::Asset.new("/path/TH_image.jpg")
  59. regular_asset = Fotos::Asset.new("/path/image.jpg")
  60. assert thumbnail_asset.is_thumbnail?
  61. refute regular_asset.is_thumbnail?
  62. end
  63. end