闭社主体 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.

170 lines
4.2 KiB

  1. require 'rails_helper'
  2. RSpec.describe StatusesHelper, type: :helper do
  3. describe '#stream_link_target' do
  4. it 'returns nil if it is not an embedded view' do
  5. set_not_embedded_view
  6. expect(helper.stream_link_target).to be_nil
  7. end
  8. it 'returns _blank if it is an embedded view' do
  9. set_embedded_view
  10. expect(helper.stream_link_target).to eq '_blank'
  11. end
  12. end
  13. def set_not_embedded_view
  14. params[:controller] = "not_#{StatusesHelper::EMBEDDED_CONTROLLER}"
  15. params[:action] = "not_#{StatusesHelper::EMBEDDED_ACTION}"
  16. end
  17. def set_embedded_view
  18. params[:controller] = StatusesHelper::EMBEDDED_CONTROLLER
  19. params[:action] = StatusesHelper::EMBEDDED_ACTION
  20. end
  21. describe '#style_classes' do
  22. it do
  23. status = double(reblog?: false)
  24. classes = helper.style_classes(status, false, false, false)
  25. expect(classes).to eq 'entry'
  26. end
  27. it do
  28. status = double(reblog?: true)
  29. classes = helper.style_classes(status, false, false, false)
  30. expect(classes).to eq 'entry entry-reblog'
  31. end
  32. it do
  33. status = double(reblog?: false)
  34. classes = helper.style_classes(status, true, false, false)
  35. expect(classes).to eq 'entry entry-predecessor'
  36. end
  37. it do
  38. status = double(reblog?: false)
  39. classes = helper.style_classes(status, false, true, false)
  40. expect(classes).to eq 'entry entry-successor'
  41. end
  42. it do
  43. status = double(reblog?: false)
  44. classes = helper.style_classes(status, false, false, true)
  45. expect(classes).to eq 'entry entry-center'
  46. end
  47. it do
  48. status = double(reblog?: true)
  49. classes = helper.style_classes(status, true, true, true)
  50. expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
  51. end
  52. end
  53. describe '#microformats_classes' do
  54. it do
  55. status = double(reblog?: false)
  56. classes = helper.microformats_classes(status, false, false)
  57. expect(classes).to eq ''
  58. end
  59. it do
  60. status = double(reblog?: false)
  61. classes = helper.microformats_classes(status, true, false)
  62. expect(classes).to eq 'p-in-reply-to'
  63. end
  64. it do
  65. status = double(reblog?: false)
  66. classes = helper.microformats_classes(status, false, true)
  67. expect(classes).to eq 'p-comment'
  68. end
  69. it do
  70. status = double(reblog?: true)
  71. classes = helper.microformats_classes(status, true, false)
  72. expect(classes).to eq 'p-in-reply-to p-repost-of'
  73. end
  74. it do
  75. status = double(reblog?: true)
  76. classes = helper.microformats_classes(status, true, true)
  77. expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
  78. end
  79. end
  80. describe '#microformats_h_class' do
  81. it do
  82. status = double(reblog?: false)
  83. css_class = helper.microformats_h_class(status, false, false, false)
  84. expect(css_class).to eq 'h-entry'
  85. end
  86. it do
  87. status = double(reblog?: true)
  88. css_class = helper.microformats_h_class(status, false, false, false)
  89. expect(css_class).to eq 'h-cite'
  90. end
  91. it do
  92. status = double(reblog?: false)
  93. css_class = helper.microformats_h_class(status, true, false, false)
  94. expect(css_class).to eq 'h-cite'
  95. end
  96. it do
  97. status = double(reblog?: false)
  98. css_class = helper.microformats_h_class(status, false, true, false)
  99. expect(css_class).to eq 'h-cite'
  100. end
  101. it do
  102. status = double(reblog?: false)
  103. css_class = helper.microformats_h_class(status, false, false, true)
  104. expect(css_class).to eq ''
  105. end
  106. it do
  107. status = double(reblog?: true)
  108. css_class = helper.microformats_h_class(status, true, true, true)
  109. expect(css_class).to eq 'h-cite'
  110. end
  111. end
  112. describe '#rtl?' do
  113. it 'is false if text is empty' do
  114. expect(helper).not_to be_rtl ''
  115. end
  116. it 'is false if there are no right to left characters' do
  117. expect(helper).not_to be_rtl 'hello world'
  118. end
  119. it 'is false if right to left characters are fewer than 1/3 of total text' do
  120. expect(helper).not_to be_rtl 'hello ݟ world'
  121. end
  122. it 'is true if right to left characters are greater than 1/3 of total text' do
  123. expect(helper).to be_rtl 'aaݟaaݟ'
  124. end
  125. end
  126. end