show.html.haml_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'statuses/show.html.haml', without_verify_partial_doubles: true do
  4. before do
  5. double(:api_oembed_url => '')
  6. allow(view).to receive(:show_landing_strip?).and_return(true)
  7. allow(view).to receive(:site_title).and_return('example site')
  8. allow(view).to receive(:site_hostname).and_return('example.com')
  9. allow(view).to receive(:full_asset_url).and_return('//asset.host/image.svg')
  10. allow(view).to receive(:local_time)
  11. allow(view).to receive(:local_time_ago)
  12. allow(view).to receive(:current_account).and_return(nil)
  13. assign(:instance_presenter, InstancePresenter.new)
  14. end
  15. it 'has valid author h-card and basic data for a detailed_status' do
  16. alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
  17. bob = Fabricate(:account, username: 'bob', display_name: 'Bob')
  18. status = Fabricate(:status, account: alice, text: 'Hello World')
  19. media = Fabricate(:media_attachment, account: alice, status: status, type: :video)
  20. reply = Fabricate(:status, account: bob, thread: status, text: 'Hello Alice')
  21. assign(:status, status)
  22. assign(:account, alice)
  23. assign(:descendant_threads, [])
  24. render
  25. mf2 = Microformats.parse(rendered)
  26. expect(mf2.entry.url.to_s).not_to be_empty
  27. expect(mf2.entry.author.name.to_s).to eq alice.display_name
  28. expect(mf2.entry.author.url.to_s).not_to be_empty
  29. end
  30. it 'has valid h-cites for p-in-reply-to and p-comment' do
  31. alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
  32. bob = Fabricate(:account, username: 'bob', display_name: 'Bob')
  33. carl = Fabricate(:account, username: 'carl', display_name: 'Carl')
  34. status = Fabricate(:status, account: alice, text: 'Hello World')
  35. media = Fabricate(:media_attachment, account: alice, status: status, type: :video)
  36. reply = Fabricate(:status, account: bob, thread: status, text: 'Hello Alice')
  37. comment = Fabricate(:status, account: carl, thread: reply, text: 'Hello Bob')
  38. assign(:status, reply)
  39. assign(:account, alice)
  40. assign(:ancestors, reply.ancestors(1, bob))
  41. assign(:descendant_threads, [{ statuses: reply.descendants(1) }])
  42. render
  43. mf2 = Microformats.parse(rendered)
  44. expect(mf2.entry.url.to_s).not_to be_empty
  45. expect(mf2.entry.comment.url.to_s).not_to be_empty
  46. expect(mf2.entry.comment.author.name.to_s).to eq carl.display_name
  47. expect(mf2.entry.comment.author.url.to_s).not_to be_empty
  48. expect(mf2.entry.in_reply_to.url.to_s).not_to be_empty
  49. expect(mf2.entry.in_reply_to.author.name.to_s).to eq alice.display_name
  50. expect(mf2.entry.in_reply_to.author.url.to_s).not_to be_empty
  51. end
  52. it 'has valid opengraph tags' do
  53. alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
  54. status = Fabricate(:status, account: alice, text: 'Hello World')
  55. media = Fabricate(:media_attachment, account: alice, status: status, type: :video)
  56. assign(:status, status)
  57. assign(:account, alice)
  58. assign(:descendant_threads, [])
  59. render
  60. header_tags = view.content_for(:header_tags)
  61. expect(header_tags).to match(%r{<meta content=".+" property="og:title" />})
  62. expect(header_tags).to match(%r{<meta content="article" property="og:type" />})
  63. expect(header_tags).to match(%r{<meta content=".+" property="og:image" />})
  64. expect(header_tags).to match(%r{<meta content="http://.+" property="og:url" />})
  65. end
  66. it 'has twitter player tag' do
  67. alice = Fabricate(:account, username: 'alice', display_name: 'Alice')
  68. status = Fabricate(:status, account: alice, text: 'Hello World')
  69. media = Fabricate(:media_attachment, account: alice, status: status, type: :video)
  70. assign(:status, status)
  71. assign(:account, alice)
  72. assign(:descendant_threads, [])
  73. render
  74. header_tags = view.content_for(:header_tags)
  75. expect(header_tags).to match(%r{<meta content="http://.+/media/.+/player" property="twitter:player" />})
  76. expect(header_tags).to match(%r{<meta content="player" property="twitter:card" />})
  77. end
  78. end