test_asset.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_thumbnail_name_adds_prefix
  37. assert_equal "TH_cockapoo.jpg", @jpg_asset.thumbnail_name
  38. assert_equal "TH_mammoth.heic", @heic_asset.thumbnail_name
  39. end
  40. def test_path_returns_relative_path
  41. assert_equal "fixtures/cockapoo.jpg", @jpg_asset.path
  42. assert_equal "fixtures/mammoth.heic", @heic_asset.path
  43. end
  44. def test_thumbnail_path_with_default_target
  45. assert_equal "fixtures/TH_cockapoo.jpg", @jpg_asset.thumbnail_path
  46. assert_equal "fixtures/TH_mammoth.heic", @heic_asset.thumbnail_path
  47. end
  48. def test_thumbnail_path_with_custom_target
  49. assert_equal "/tmp/TH_cockapoo.jpg", @jpg_asset.thumbnail_path("/tmp")
  50. assert_equal "output/TH_mammoth.heic", @heic_asset.thumbnail_path("output")
  51. end
  52. def test_is_thumbnail_detects_thumbnail_prefix
  53. thumbnail_asset = Fotos::Asset.new("/path/TH_image.jpg")
  54. regular_asset = Fotos::Asset.new("/path/image.jpg")
  55. assert thumbnail_asset.is_thumbnail?
  56. refute regular_asset.is_thumbnail?
  57. end
  58. end