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.

223 lines
5.7 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 the shortname for non embedded local accounts' do
  44. set_not_embedded_view
  45. account = Account.new(domain: nil, username: 'user')
  46. acct = helper.acct(account)
  47. expect(acct).to eq '@user'
  48. end
  49. end
  50. def set_not_embedded_view
  51. params[:controller] = "not_#{StreamEntriesHelper::EMBEDDED_CONTROLLER}"
  52. params[:action] = "not_#{StreamEntriesHelper::EMBEDDED_ACTION}"
  53. end
  54. def set_embedded_view
  55. params[:controller] = StreamEntriesHelper::EMBEDDED_CONTROLLER
  56. params[:action] = StreamEntriesHelper::EMBEDDED_ACTION
  57. end
  58. describe '#style_classes' do
  59. it do
  60. status = double(reblog?: false)
  61. classes = helper.style_classes(status, false, false, false)
  62. expect(classes).to eq 'entry'
  63. end
  64. it do
  65. status = double(reblog?: true)
  66. classes = helper.style_classes(status, false, false, false)
  67. expect(classes).to eq 'entry entry-reblog'
  68. end
  69. it do
  70. status = double(reblog?: false)
  71. classes = helper.style_classes(status, true, false, false)
  72. expect(classes).to eq 'entry entry-predecessor'
  73. end
  74. it do
  75. status = double(reblog?: false)
  76. classes = helper.style_classes(status, false, true, false)
  77. expect(classes).to eq 'entry entry-successor'
  78. end
  79. it do
  80. status = double(reblog?: false)
  81. classes = helper.style_classes(status, false, false, true)
  82. expect(classes).to eq 'entry entry-center'
  83. end
  84. it do
  85. status = double(reblog?: true)
  86. classes = helper.style_classes(status, true, true, true)
  87. expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
  88. end
  89. end
  90. describe '#microformats_classes' do
  91. it do
  92. status = double(reblog?: false)
  93. classes = helper.microformats_classes(status, false, false)
  94. expect(classes).to eq ''
  95. end
  96. it do
  97. status = double(reblog?: false)
  98. classes = helper.microformats_classes(status, true, false)
  99. expect(classes).to eq 'p-in-reply-to'
  100. end
  101. it do
  102. status = double(reblog?: false)
  103. classes = helper.microformats_classes(status, false, true)
  104. expect(classes).to eq 'p-comment'
  105. end
  106. it do
  107. status = double(reblog?: true)
  108. classes = helper.microformats_classes(status, true, false)
  109. expect(classes).to eq 'p-in-reply-to p-repost-of'
  110. end
  111. it do
  112. status = double(reblog?: true)
  113. classes = helper.microformats_classes(status, true, true)
  114. expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
  115. end
  116. end
  117. describe '#microformats_h_class' do
  118. it do
  119. status = double(reblog?: false)
  120. css_class = helper.microformats_h_class(status, false, false, false)
  121. expect(css_class).to eq 'h-entry'
  122. end
  123. it do
  124. status = double(reblog?: true)
  125. css_class = helper.microformats_h_class(status, false, false, false)
  126. expect(css_class).to eq 'h-cite'
  127. end
  128. it do
  129. status = double(reblog?: false)
  130. css_class = helper.microformats_h_class(status, true, false, false)
  131. expect(css_class).to eq 'h-cite'
  132. end
  133. it do
  134. status = double(reblog?: false)
  135. css_class = helper.microformats_h_class(status, false, true, false)
  136. expect(css_class).to eq 'h-cite'
  137. end
  138. it do
  139. status = double(reblog?: false)
  140. css_class = helper.microformats_h_class(status, false, false, true)
  141. expect(css_class).to eq ''
  142. end
  143. it do
  144. status = double(reblog?: true)
  145. css_class = helper.microformats_h_class(status, true, true, true)
  146. expect(css_class).to eq 'h-cite'
  147. end
  148. end
  149. describe '#rtl?' do
  150. it 'is false if text is empty' do
  151. expect(helper).not_to be_rtl ''
  152. end
  153. it 'is false if there are no right to left characters' do
  154. expect(helper).not_to be_rtl 'hello world'
  155. end
  156. it 'is false if right to left characters are fewer than 1/3 of total text' do
  157. expect(helper).not_to be_rtl 'hello ݟ world'
  158. end
  159. it 'is true if right to left characters are greater than 1/3 of total text' do
  160. expect(helper).to be_rtl 'aaݟaaݟ'
  161. end
  162. end
  163. end