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`
th-downstream
Joël Quenneville 8 years ago committed by Eugen
parent ac91652eae
commit e8a3a00068

@ -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)

@ -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 ''

Loading…
Cancel
Save