From e8a3a0006898f325458cfedb10a110a2a0c5aef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Quenneville?= Date: Sun, 23 Apr 2017 00:04:32 -0400 Subject: [PATCH] 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` --- app/helpers/stream_entries_helper.rb | 10 +- 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 daa4a48e48..a1dfe2ecfd 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 706a872f1a..a9e2d9c4be 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 ''