Add a view component for rendering thumbnails for media assets. This lets us properly show thumbnails on the upload listing page and the media assets listing page, including support for high pixel density thumbnails and video length icons for videos. Fixes not being able to see thumbnails on the /media_assets page. This is mostly copy/pasted from the post preview component. FIXME: don't duplicate code.
33 lines
1.2 KiB
Ruby
33 lines
1.2 KiB
Ruby
require "test_helper"
|
|
|
|
class MediaAssetPreviewComponentTest < ViewComponent::TestCase
|
|
include Rails.application.routes.url_helpers
|
|
|
|
def render_preview(media_asset, **options)
|
|
render_inline(MediaAssetPreviewComponent.new(media_asset: media_asset, **options))
|
|
end
|
|
|
|
context "The MediaAssetPreviewComponent" do
|
|
context "for an image" do
|
|
should "render the preview" do
|
|
media_asset = create(:media_asset)
|
|
node = render_preview(media_asset)
|
|
|
|
assert_equal(media_asset_path(media_asset), node.css("article a").attr("href").value)
|
|
assert_equal(media_asset.variant("180x180").file_url, node.css("article img").attr("src").value)
|
|
end
|
|
end
|
|
|
|
context "for a video" do
|
|
should "render the icon" do
|
|
media_asset = create(:media_asset, file_ext: "mp4", duration: 30)
|
|
node = render_preview(media_asset)
|
|
|
|
assert_equal(media_asset_path(media_asset), node.css("article a").attr("href").value)
|
|
assert_equal(media_asset.variant("180x180").file_url, node.css("article img").attr("src").value)
|
|
assert_equal("0:30", node.css("article .media-asset-duration").text.strip)
|
|
end
|
|
end
|
|
end
|
|
end
|