闭社主体 forked from https://github.com/tootsuite/mastodon
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.

224 lines
5.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe StreamEntriesHelper, type: :helper do
  3. describe '#display_name' do
  4. it 'uses the display name when it exists' do
  5. account = Account.new(display_name: "Display", username: "Username")
  6. expect(helper.display_name(account)).to eq "Display"
  7. end
  8. it 'uses the username when display name is nil' do
  9. account = Account.new(display_name: nil, username: "Username")
  10. expect(helper.display_name(account)).to eq "Username"
  11. end
  12. end
  13. describe '#stream_link_target' do
  14. it 'returns nil if it is not an embedded view' do
  15. set_not_embedded_view
  16. expect(helper.stream_link_target).to be_nil
  17. end
  18. it 'returns _blank if it is an embedded view' do
  19. set_embedded_view
  20. expect(helper.stream_link_target).to eq '_blank'
  21. end
  22. end
  23. describe '#acct' do
  24. it 'is fully qualified for embedded local accounts' do
  25. allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
  26. set_embedded_view
  27. account = Account.new(domain: nil, username: 'user')
  28. acct = helper.acct(account)
  29. expect(acct).to eq '@user@local_domain'
  30. end
  31. it 'is fully qualified for embedded foreign accounts' do
  32. set_embedded_view
  33. account = Account.new(domain: 'foreign_server.com', username: 'user')
  34. acct = helper.acct(account)
  35. expect(acct).to eq '@user@foreign_server.com'
  36. end
  37. it 'is fully qualified for non embedded foreign accounts' do
  38. set_not_embedded_view
  39. account = Account.new(domain: 'foreign_server.com', username: 'user')
  40. acct = helper.acct(account)
  41. expect(acct).to eq '@user@foreign_server.com'
  42. end
  43. it 'is fully qualified for non embedded local accounts' do
  44. allow(Rails.configuration.x).to receive(:local_domain).and_return('local_domain')
  45. set_not_embedded_view
  46. account = Account.new(domain: nil, username: 'user')
  47. acct = helper.acct(account)
  48. expect(acct).to eq '@user@local_domain'
  49. end
  50. end
  51. def set_not_embedded_view
  52. params[:controller] = "not_#{StreamEntriesHelper::EMBEDDED_CONTROLLER}"
  53. params[:action] = "not_#{StreamEntriesHelper::EMBEDDED_ACTION}"
  54. end
  55. def set_embedded_view
  56. params[:controller] = StreamEntriesHelper::EMBEDDED_CONTROLLER
  57. params[:action] = StreamEntriesHelper::EMBEDDED_ACTION
  58. end
  59. describe '#style_classes' do
  60. it do
  61. status = double(reblog?: false)
  62. classes = helper.style_classes(status, false, false, false)
  63. expect(classes).to eq 'entry'
  64. end
  65. it do
  66. status = double(reblog?: true)
  67. classes = helper.style_classes(status, false, false, false)
  68. expect(classes).to eq 'entry entry-reblog'
  69. end
  70. it do
  71. status = double(reblog?: false)
  72. classes = helper.style_classes(status, true, false, false)
  73. expect(classes).to eq 'entry entry-predecessor'
  74. end
  75. it do
  76. status = double(reblog?: false)
  77. classes = helper.style_classes(status, false, true, false)
  78. expect(classes).to eq 'entry entry-successor'
  79. end
  80. it do
  81. status = double(reblog?: false)
  82. classes = helper.style_classes(status, false, false, true)
  83. expect(classes).to eq 'entry entry-center'
  84. end
  85. it do
  86. status = double(reblog?: true)
  87. classes = helper.style_classes(status, true, true, true)
  88. expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
  89. end
  90. end
  91. describe '#microformats_classes' do
  92. it do
  93. status = double(reblog?: false)
  94. classes = helper.microformats_classes(status, false, false)
  95. expect(classes).to eq ''
  96. end
  97. it do
  98. status = double(reblog?: false)
  99. classes = helper.microformats_classes(status, true, false)
  100. expect(classes).to eq 'p-in-reply-to'
  101. end
  102. it do
  103. status = double(reblog?: false)
  104. classes = helper.microformats_classes(status, false, true)
  105. expect(classes).to eq 'p-comment'
  106. end
  107. it do
  108. status = double(reblog?: true)
  109. classes = helper.microformats_classes(status, true, false)
  110. expect(classes).to eq 'p-in-reply-to p-repost-of'
  111. end
  112. it do
  113. status = double(reblog?: true)
  114. classes = helper.microformats_classes(status, true, true)
  115. expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
  116. end
  117. end
  118. describe '#microformats_h_class' do
  119. it do
  120. status = double(reblog?: false)
  121. css_class = helper.microformats_h_class(status, false, false, false)
  122. expect(css_class).to eq 'h-entry'
  123. end
  124. it do
  125. status = double(reblog?: true)
  126. css_class = helper.microformats_h_class(status, false, false, false)
  127. expect(css_class).to eq 'h-cite'
  128. end
  129. it do
  130. status = double(reblog?: false)
  131. css_class = helper.microformats_h_class(status, true, false, false)
  132. expect(css_class).to eq 'h-cite'
  133. end
  134. it do
  135. status = double(reblog?: false)
  136. css_class = helper.microformats_h_class(status, false, true, false)
  137. expect(css_class).to eq 'h-cite'
  138. end
  139. it do
  140. status = double(reblog?: false)
  141. css_class = helper.microformats_h_class(status, false, false, true)
  142. expect(css_class).to eq ''
  143. end
  144. it do
  145. status = double(reblog?: true)
  146. css_class = helper.microformats_h_class(status, true, true, true)
  147. expect(css_class).to eq 'h-cite'
  148. end
  149. end
  150. describe '#rtl?' do
  151. it 'is false if text is empty' do
  152. expect(helper).not_to be_rtl ''
  153. end
  154. it 'is false if there are no right to left characters' do
  155. expect(helper).not_to be_rtl 'hello world'
  156. end
  157. it 'is false if right to left characters are fewer than 1/3 of total text' do
  158. expect(helper).not_to be_rtl 'hello ݟ world'
  159. end
  160. it 'is true if right to left characters are greater than 1/3 of total text' do
  161. expect(helper).to be_rtl 'aaݟaaݟ'
  162. end
  163. end
  164. end