uh-layout 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,194 +0,0 @@
1
- module Uh
2
- class Layout
3
- describe Container do
4
- let(:entries) { %i[foo bar] }
5
- subject(:container) { described_class.new entries }
6
-
7
- describe '#initialize' do
8
- it 'assigns no entries when no arguments are given' do
9
- expect(described_class.new).to be_empty
10
- end
11
- end
12
-
13
- describe '#to_ary' do
14
- it 'supports implicit conversion to array' do
15
- expect([] + container).to eq %i[foo bar]
16
- end
17
- end
18
-
19
- describe '#current' do
20
- context 'when container has multiple entries' do
21
- it 'returns the first entry' do
22
- expect(container.current).to be :foo
23
- end
24
- end
25
-
26
- context 'when container has no entry' do
27
- subject(:container) { described_class.new }
28
-
29
- it 'returns nil' do
30
- expect(container.current).to be nil
31
- end
32
- end
33
- end
34
-
35
- describe '#current=' do
36
- context 'when given argument is an entry' do
37
- before { container.current = :bar }
38
-
39
- it 'assigns given entry as the current one' do
40
- expect(container.current).to be :bar
41
- end
42
- end
43
-
44
- context 'when given argument is not an entry' do
45
- it 'raises ArgumentError' do
46
- expect { container.current = :unknown_entry }
47
- .to raise_error Layout::ArgumentError
48
- end
49
- end
50
- end
51
-
52
- describe '#<<' do
53
- it 'adds given entry' do
54
- container << :baz
55
- expect(container).to include :baz
56
- end
57
- end
58
-
59
- describe '#insert_after_current' do
60
- it 'inserts given entry after current one' do
61
- container.insert_after_current :baz
62
- expect(container.entries).to eq %i[foo baz bar]
63
- end
64
-
65
- context 'when container has no entry' do
66
- let(:entries) { [] }
67
-
68
- it 'raises a RuntimeError' do
69
- expect { container.insert_after_current :foo }
70
- .to raise_error Layout::RuntimeError
71
- end
72
- end
73
- end
74
-
75
- describe '#remove' do
76
- let(:entries) { %i[foo bar baz] }
77
-
78
- before { container.current = :bar }
79
-
80
- it 'removes given argument from entries' do
81
- container.remove :foo
82
- expect(container).not_to include :foo
83
- end
84
-
85
- it 'preserves the current entry' do
86
- container.remove :foo
87
- expect(container.current).to be :bar
88
- end
89
-
90
- it 'returns self' do
91
- expect(container.remove :foo).to be container
92
- end
93
-
94
- it 'raises an ArgumentError when given entry is not included' do
95
- expect { container.remove :unknown_entry }.to raise_error ArgumentError
96
- end
97
-
98
- context 'when the first and current entry is removed' do
99
- before do
100
- container.current = :foo
101
- container.remove :foo
102
- end
103
-
104
- it 'assigns next entry as the current one' do
105
- expect(container.current).to be :bar
106
- end
107
- end
108
-
109
- context 'when given entry is the only one' do
110
- let(:entries) { [:bar] }
111
-
112
- it 'has no more current entry' do
113
- container.remove :bar
114
- expect(container.current).to be nil
115
- end
116
- end
117
- end
118
-
119
- describe '#remove_if' do
120
- it 'removes entries for which given block returns true' do
121
- container.remove_if { |e| e == :foo }
122
- expect(container).not_to include :foo
123
- end
124
- end
125
-
126
- describe '#get' do
127
- it 'returns consecutive entry in given direction' do
128
- expect(container.get :succ).to be :bar
129
- end
130
-
131
- it 'returns nil when no consecutive entry exists' do
132
- expect(container.get :pred).to be nil
133
- end
134
-
135
- context 'with cycle option' do
136
- it 'returns consecutive entry, cycling before first one' do
137
- expect(container.get :pred, cycle: true).to be :bar
138
- end
139
-
140
- it 'returns consecutive entry, cycling after last one' do
141
- container.current = :bar
142
- expect(container.get :succ, cycle: true).to be :foo
143
- end
144
- end
145
- end
146
-
147
- describe '#sel' do
148
- it 'sets consecutive entry in given direction as the current one' do
149
- container.sel :next
150
- expect(container.current).to be :bar
151
- end
152
- end
153
-
154
- describe '#set' do
155
- let(:entries) { %i[foo bar baz] }
156
-
157
- it 'swaps current entry with consecutive one in given direction' do
158
- container.set :next
159
- expect(container.entries).to eq %i[bar foo baz]
160
- end
161
-
162
- it 'does not change current entry' do
163
- expect { container.set :next }.not_to change { container.current }
164
- end
165
-
166
- context 'when direction is out of range' do
167
- it 'rotates the entries' do
168
- container.set :pred
169
- expect(container.entries).to eq %i[bar baz foo]
170
- end
171
-
172
- it 'does not change current entry' do
173
- expect { container.set :pred }.not_to change { container.current }
174
- end
175
- end
176
-
177
- context 'when entries count is less than 2' do
178
- let(:entries) { %i[foo] }
179
-
180
- it 'raises a RuntimeError' do
181
- expect { container.set :pred }.to raise_error Layout::RuntimeError
182
- end
183
- end
184
- end
185
-
186
- describe '#swap' do
187
- it 'swaps entries matched by given indexes' do
188
- container.swap 0, 1
189
- expect(container.entries).to eq %i[bar foo]
190
- end
191
- end
192
- end
193
- end
194
- end
@@ -1,32 +0,0 @@
1
- module Uh
2
- class Layout
3
- describe History do
4
- subject(:history) { described_class.new }
5
-
6
- it 'has an empty tag history' do
7
- expect(history.tags).to be_empty
8
- end
9
-
10
- describe '#record_tag' do
11
- it 'adds current tag' do
12
- history.record_tag :some_tag
13
- expect(history.tags).to include :some_tag
14
- end
15
-
16
- it 'limits stored tags count to configured tags size' do
17
- history.tags_size_max.times { |n| history.record_tag "tag_#{n}" }
18
- expect { history.record_tag :one_more }
19
- .not_to change { history.tags.size }
20
- end
21
- end
22
-
23
- describe '#last_tag' do
24
- it 'returns last recorded tag' do
25
- history.record_tag :tag_1
26
- history.record_tag :tag_2
27
- expect(history.last_tag).to be :tag_2
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,46 +0,0 @@
1
- module Uh
2
- class Layout
3
- describe Registrant do
4
- let(:layout) { Layout.new }
5
- let(:geo) { build_geo }
6
- let(:screen) { double 'screen', id: 0, geo: geo, height: geo.height }
7
- let(:display) { double 'display', screens: [screen] }
8
- let(:bar) { instance_spy Bar, height: 16 }
9
-
10
- before do
11
- allow(Bar).to receive(:new) { bar }
12
- end
13
-
14
- describe '#register' do
15
- it 'registers display screens as layout screens' do
16
- described_class.register layout, display
17
- expect(layout.screens[0])
18
- .to be_a(Screen)
19
- .and have_attributes(id: 0)
20
- end
21
-
22
- it 'builds a new bar widget' do
23
- expect(Bar)
24
- .to receive(:new)
25
- .with display, an_instance_of(Screen), layout.colors
26
- described_class.register layout, display
27
- end
28
-
29
- it 'registers the bar widget' do
30
- described_class.register layout, display
31
- expect(layout.widgets[0]).to be bar
32
- end
33
-
34
- it 'decreases the layout screens height with the bar height' do
35
- described_class.register layout, display
36
- expect(layout.screens[0].height).to eq screen.height - bar.height
37
- end
38
-
39
- it 'updates layout widgets' do
40
- expect(layout).to receive :update_widgets
41
- described_class.register layout, display
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,40 +0,0 @@
1
- module Uh
2
- class Layout
3
- describe Screen do
4
- let(:geo) { build_geo }
5
- let(:other_geo) { build_geo 640, 0, 320, 240 }
6
- let(:client) { build_client }
7
- subject(:screen) { described_class.new 0, geo }
8
-
9
- it 'has one default tag with id 1 assigned' do
10
- expect(screen.tags).to include an_object_having_attributes id: '1'
11
- end
12
-
13
- it 'has one default tag with screen geo copy assigned' do
14
- expect(screen.tags.first.geo).to eq(screen.geo).and not_be screen.geo
15
- end
16
-
17
- describe '#height=' do
18
- it 'changes screen height' do
19
- expect { screen.height = 42 }.to change { screen.height }.to 42
20
- end
21
-
22
- it 'changes tags height' do
23
- expect { screen.height = 42 }
24
- .to change { screen.tags.first.height }.to 42
25
- end
26
- end
27
-
28
- describe '#include?' do
29
- it 'returns false when screen does not include given client' do
30
- expect(screen.include? client).to be false
31
- end
32
-
33
- it 'returns true when screen includes given client' do
34
- screen.current_tag.current_column_or_create << client
35
- expect(screen.include? client).to be true
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,91 +0,0 @@
1
- module Uh
2
- class Layout
3
- describe Tag do
4
- let(:geo) { build_geo }
5
- let(:other_geo) { build_geo 640, 0, 320, 240 }
6
- let(:client) { build_client }
7
- let(:other_client) { build_client }
8
- let(:column) { Column.new(geo) }
9
- subject(:tag) { described_class.new '1', geo }
10
-
11
- describe '.new' do
12
- it 'raises error unless id converts to string' do
13
- expect { described_class.new 1, geo }
14
- .to raise_error(Layout::ArgumentError)
15
- end
16
- end
17
-
18
- describe '#clients' do
19
- it 'returns all clients contained in assigned columns' do
20
- tag.columns << column.tap { |column| column << client << other_client }
21
- expect(tag.clients).to eq [client, other_client]
22
- end
23
- end
24
-
25
- describe '#include?' do
26
- it 'returns false when tag does not include given client' do
27
- expect(tag.include? client).to be false
28
- end
29
-
30
- it 'returns true when tag includes given client' do
31
- tag.columns << column.tap { |column| column << client }
32
- expect(tag.include? client).to be true
33
- end
34
- end
35
-
36
- describe '#current_column_or_create' do
37
- context 'when tag has no column' do
38
- it 'creates a new column' do
39
- expect { tag.current_column_or_create }
40
- .to change { tag.columns.size }.from(0).to(1)
41
- end
42
-
43
- it 'returns the new column' do
44
- expect(tag.current_column_or_create).to be tag.columns.fetch 0
45
- end
46
- end
47
-
48
- context 'when tag has a column' do
49
- before { tag.columns << column }
50
-
51
- it 'does not create any column' do
52
- expect { tag.current_column_or_create }
53
- .not_to change { tag.columns.size }
54
- end
55
-
56
- it 'returns the current column' do
57
- expect(tag.current_column_or_create).to be column
58
- end
59
- end
60
- end
61
-
62
- describe '#arranger' do
63
- it 'returns a fixed width arranger' do
64
- expect(tag.arranger).to be_an Arrangers::FixedWidth
65
- end
66
- end
67
-
68
- describe '#arrange_columns' do
69
- before { tag.columns << column }
70
-
71
- it 'purges empty columns' do
72
- tag.arrange_columns
73
- expect(tag.columns).to be_empty
74
- end
75
-
76
- it 'arranges columns' do
77
- arranger = instance_spy Arrangers::FixedWidth
78
- allow(tag).to receive(:arranger) { arranger }
79
- expect(arranger).to receive :arrange
80
- tag.arrange_columns
81
- end
82
-
83
- it 'arranges columns clients' do
84
- column << client
85
- expect(column).to receive :arrange_clients
86
- tag.arrange_columns
87
- end
88
- end
89
- end
90
- end
91
- end