You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.5 KiB

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