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`
This commit is contained in:
Joël Quenneville 2017-04-23 00:04:32 -04:00 committed by Eugen
parent 6f0b3b069f
commit 0c2fe22bc1
2 changed files with 132 additions and 3 deletions

View file

@ -31,9 +31,13 @@ module StreamEntriesHelper
end end
def microformats_h_class(status, is_predecessor, is_successor, include_threads) def microformats_h_class(status, is_predecessor, is_successor, include_threads)
return 'h-cite' if is_predecessor || status.reblog || is_successor if is_predecessor || status.reblog? || is_successor
return 'h-entry' unless include_threads 'h-cite'
'' elsif include_threads
''
else
'h-entry'
end
end end
def rtl?(text) def rtl?(text)

View file

@ -15,6 +15,131 @@ RSpec.describe StreamEntriesHelper, type: :helper do
end end
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 describe '#rtl?' do
it 'is false if text is empty' do it 'is false if text is empty' do
expect(helper).not_to be_rtl '' expect(helper).not_to be_rtl ''