about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorJoël Quenneville <joel.quen@gmail.com>2017-04-23 00:04:32 -0400
committerEugen <eugen@zeonfederated.com>2017-04-23 06:04:32 +0200
commit0c2fe22bc19a82899c7577410bc869db7d42955a (patch)
tree10961704fdb4a80524a00cd180864c3d9a16e578 /spec
parent6f0b3b069f3ee9a9eceec77666fc124b9695f124 (diff)
Add test coverage to CSS class generation (#2285)
The code that generates CSS is based on a lot of boolean conditions.
The possible combinations of these grows exponentially as we add more
conditions.

Since most of the code is conditional on a single boolean, we tested the
following:

1. All `false`
2. All `true`
3. Each individual flag set to `true`

The methods tested are:

* `StreamEntriesHelper#style_classes`
* `StreamEntriesHelper#microformats_classes`
* `StreamEntriesHelper#microformats_h_class`
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/stream_entries_helper_spec.rb125
1 files changed, 125 insertions, 0 deletions
diff --git a/spec/helpers/stream_entries_helper_spec.rb b/spec/helpers/stream_entries_helper_spec.rb
index 706a872f1..a9e2d9c4b 100644
--- a/spec/helpers/stream_entries_helper_spec.rb
+++ b/spec/helpers/stream_entries_helper_spec.rb
@@ -15,6 +15,131 @@ RSpec.describe StreamEntriesHelper, type: :helper do
     end
   end
 
+  describe '#style_classes' do
+    it do
+      status = double(reblog?: false)
+      classes = helper.style_classes(status, false, false, false)
+
+      expect(classes).to eq 'entry'
+    end
+
+    it do
+      status = double(reblog?: true)
+      classes = helper.style_classes(status, false, false, false)
+
+      expect(classes).to eq 'entry entry-reblog'
+    end
+
+    it do
+      status = double(reblog?: false)
+      classes = helper.style_classes(status, true, false, false)
+
+      expect(classes).to eq 'entry entry-predecessor'
+    end
+
+    it do
+      status = double(reblog?: false)
+      classes = helper.style_classes(status, false, true, false)
+
+      expect(classes).to eq 'entry entry-successor'
+    end
+
+    it do
+      status = double(reblog?: false)
+      classes = helper.style_classes(status, false, false, true)
+
+      expect(classes).to eq 'entry entry-center'
+    end
+
+    it do
+      status = double(reblog?: true)
+      classes = helper.style_classes(status, true, true, true)
+
+      expect(classes).to eq 'entry entry-predecessor entry-reblog entry-successor entry-center'
+    end
+  end
+
+  describe '#microformats_classes' do
+    it do
+      status = double(reblog?: false)
+      classes = helper.microformats_classes(status, false, false)
+
+      expect(classes).to eq ''
+    end
+
+    it do
+      status = double(reblog?: false)
+      classes = helper.microformats_classes(status, true, false)
+
+      expect(classes).to eq 'p-in-reply-to'
+    end
+
+    it do
+      status = double(reblog?: false)
+      classes = helper.microformats_classes(status, false, true)
+
+      expect(classes).to eq 'p-comment'
+    end
+
+    it do
+      status = double(reblog?: true)
+      classes = helper.microformats_classes(status, true, false)
+
+      expect(classes).to eq 'p-in-reply-to p-repost-of'
+    end
+
+    it do
+      status = double(reblog?: true)
+      classes = helper.microformats_classes(status, true, true)
+
+      expect(classes).to eq 'p-in-reply-to p-repost-of p-comment'
+    end
+  end
+
+  describe '#microformats_h_class' do
+    it do
+      status = double(reblog?: false)
+      css_class = helper.microformats_h_class(status, false, false, false)
+
+      expect(css_class).to eq 'h-entry'
+    end
+
+    it do
+      status = double(reblog?: true)
+      css_class = helper.microformats_h_class(status, false, false, false)
+
+      expect(css_class).to eq 'h-cite'
+    end
+
+    it do
+      status = double(reblog?: false)
+      css_class = helper.microformats_h_class(status, true, false, false)
+
+      expect(css_class).to eq 'h-cite'
+    end
+
+    it do
+      status = double(reblog?: false)
+      css_class = helper.microformats_h_class(status, false, true, false)
+
+      expect(css_class).to eq 'h-cite'
+    end
+
+    it do
+      status = double(reblog?: false)
+      css_class = helper.microformats_h_class(status, false, false, true)
+
+      expect(css_class).to eq ''
+    end
+
+    it do
+      status = double(reblog?: true)
+      css_class = helper.microformats_h_class(status, true, true, true)
+
+      expect(css_class).to eq 'h-cite'
+    end
+  end
+  
   describe '#rtl?' do
     it 'is false if text is empty' do
       expect(helper).not_to be_rtl ''