2019-05-30 14:35:16 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ProtocolImporters::ProtocolDescriptionBuilder do
|
|
|
|
let(:description_only) do
|
2019-05-31 02:26:22 +08:00
|
|
|
JSON.parse(file_fixture('protocol_importers/description_with_body.json').read).to_h.with_indifferent_access
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
let(:description_with_image) do
|
2019-05-31 02:26:22 +08:00
|
|
|
JSON.parse(file_fixture('protocol_importers/description_with_image.json').read).to_h.with_indifferent_access
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
let(:description_with_extra_content) do
|
2019-05-31 02:26:22 +08:00
|
|
|
JSON.parse(file_fixture('protocol_importers/description_with_extra_content.json').read).to_h.with_indifferent_access
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
let(:description_with_html) do
|
2019-05-31 02:26:22 +08:00
|
|
|
JSON.parse(file_fixture('protocol_importers/description_with_body_html.json').read).to_h.with_indifferent_access
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'self.generate' do
|
|
|
|
context 'when description field not exists' do
|
|
|
|
it 'returns empty string' do
|
|
|
|
expect(described_class.generate({})).to be == ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when have only description' do
|
|
|
|
it 'includes paragraph description' do
|
2019-06-03 18:42:15 +08:00
|
|
|
expect(described_class.generate(description_only)).to include('<p> original desc </p>')
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'strips HTML tags' do
|
2019-06-03 18:42:15 +08:00
|
|
|
expect(described_class.generate(description_with_html).scan('script').count).to be == 0
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when includes image' do
|
|
|
|
it 'includes image tag' do
|
|
|
|
expect(described_class.generate(description_with_image)).to include('<img src=')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when have extra content' do
|
|
|
|
it 'add extra fields as paragraphs' do
|
2019-06-17 23:09:31 +08:00
|
|
|
expect(described_class.generate(description_with_extra_content).scan('<br/>').size).to be == 10
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|