Skip to content

Commit

Permalink
Adding shared_examples for rich_text_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
GetOutOfMyBakery committed Apr 6, 2024
1 parent 8661b0c commit 443b213
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.shared_examples 'rich text element: channel' do |klass|
describe '#channel' do
it 'correctly serializes' do
expected_json = [{ type: 'channel', channel_id: 'AAAAAAAAA' }]
elements = klass.channel(channel_id: 'AAAAAAAAA').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end

RSpec.shared_examples 'rich text element: emoji' do |klass|
describe '#emoji' do
it 'correctly serializes' do
expected_json = [{ type: 'emoji', name: 'wave' }]
elements = klass.emoji(name: 'wave').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end

RSpec.shared_examples 'rich text element: link' do |klass|
describe '#link' do
it 'correctly serializes' do
expected_json = [{ type: 'link', url: 'https://github.com' }]
elements = klass.link(url: 'https://github.com').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end

RSpec.shared_examples 'rich text element: text' do |klass|
describe '#text' do
it 'correctly serializes' do
expected_json = [{ type: 'text', text: 'Some text' }]
elements = klass.text(text: 'Some text').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end

RSpec.shared_examples 'rich text element: user' do |klass|
describe '#user' do
it 'correctly serializes' do
expected_json = [{ type: 'user', user_id: 'AAAAAAAAA' }]
elements = klass.user(user_id: 'AAAAAAAAA').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end

RSpec.shared_examples 'rich text element: usergroup' do |klass|
describe '#usergroup' do
it 'correctly serializes' do
expected_json = [{ type: 'usergroup', usergroup_id: 'AAAAAAAAA' }]
elements = klass.usergroup(usergroup_id: 'AAAAAAAAA').as_json[:elements]

expect(elements).to match(expected_json)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
expect(instance.elements).to eq([1, 2])
end
end

it_behaves_like 'rich text element: channel', described_class.new
it_behaves_like 'rich text element: emoji', described_class.new
it_behaves_like 'rich text element: link', described_class.new
it_behaves_like 'rich text element: text', described_class.new
it_behaves_like 'rich text element: user', described_class.new
it_behaves_like 'rich text element: usergroup', described_class.new
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@
expect(instance.elements).to eq([1, 2])
end
end

it_behaves_like 'rich text element: channel', described_class.new
it_behaves_like 'rich text element: emoji', described_class.new
it_behaves_like 'rich text element: link', described_class.new
it_behaves_like 'rich text element: text', described_class.new
it_behaves_like 'rich text element: user', described_class.new
it_behaves_like 'rich text element: usergroup', described_class.new
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
expect(instance.elements).to eq([1, 2])
end
end

it_behaves_like 'rich text element: channel', described_class.new
it_behaves_like 'rich text element: emoji', described_class.new
it_behaves_like 'rich text element: link', described_class.new
it_behaves_like 'rich text element: text', described_class.new
it_behaves_like 'rich text element: user', described_class.new
it_behaves_like 'rich text element: usergroup', described_class.new
end

0 comments on commit 443b213

Please sign in to comment.