diff options
author | Joël Quenneville <joel.quen@gmail.com> | 2017-04-23 00:04:32 -0400 |
---|---|---|
committer | Eugen <eugen@zeonfederated.com> | 2017-04-23 06:04:32 +0200 |
commit | 0c2fe22bc19a82899c7577410bc869db7d42955a (patch) | |
tree | 10961704fdb4a80524a00cd180864c3d9a16e578 | |
parent | 6f0b3b069f3ee9a9eceec77666fc124b9695f124 (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`
-rw-r--r-- | app/helpers/stream_entries_helper.rb | 10 | ||||
-rw-r--r-- | spec/helpers/stream_entries_helper_spec.rb | 125 |
2 files changed, 132 insertions, 3 deletions
diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index daa4a48e4..a1dfe2ecf 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -31,9 +31,13 @@ module StreamEntriesHelper end def microformats_h_class(status, is_predecessor, is_successor, include_threads) - return 'h-cite' if is_predecessor || status.reblog || is_successor - return 'h-entry' unless include_threads - '' + if is_predecessor || status.reblog? || is_successor + 'h-cite' + elsif include_threads + '' + else + 'h-entry' + end end def rtl?(text) 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 '' |