1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::PositionableList do
subject do
Class.new do
include Sidebars::PositionableList
end.new
end
describe '#add_element' do
it 'adds the element to the last position of the list' do
list = [1, 2]
subject.add_element(list, 3)
expect(list).to eq([1, 2, 3])
end
end
describe '#insert_element_before' do
let(:user) { build(:user) }
let(:list) { [1, user] }
it 'adds element before the specific element class' do
subject.insert_element_before(list, User, 2)
expect(list).to eq [1, 2, user]
end
context 'when reference element does not exist' do
it 'adds the element to the top of the list' do
subject.insert_element_before(list, Project, 2)
expect(list).to eq [2, 1, user]
end
end
end
describe '#insert_element_after' do
let(:user) { build(:user) }
let(:list) { [1, user] }
it 'adds element after the specific element class' do
subject.insert_element_after(list, Integer, 2)
expect(list).to eq [1, 2, user]
end
context 'when reference element does not exist' do
it 'adds the element to the end of the list' do
subject.insert_element_after(list, Project, 2)
expect(list).to eq [1, user, 2]
end
end
end
end
|