Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a2454dc3
Commit
a2454dc3
authored
Sep 15, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a few more tests, including error cases
parent
7dfba610
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
spec/lib/gitlab/relative_positioning/item_context_spec.rb
spec/lib/gitlab/relative_positioning/item_context_spec.rb
+32
-3
No files found.
spec/lib/gitlab/relative_positioning/item_context_spec.rb
View file @
a2454dc3
...
...
@@ -10,9 +10,7 @@ RSpec.describe Gitlab::RelativePositioning::ItemContext do
create
(
:issue
,
project:
project
,
relative_position:
pos
)
end
# Increase the range size to convice yourself that this covers ALL arrangements
# We use plain variables here so we can use them in `where` blocks.
range
=
(
101
..
108
)
range
=
(
101
..
107
)
# A deliberately small range, so we can test everything
indices
=
(
0
..
).
take
(
range
.
size
)
let
(
:start
)
{
((
range
.
first
+
range
.
last
)
/
2.0
).
floor
}
...
...
@@ -34,28 +32,39 @@ RSpec.describe Gitlab::RelativePositioning::ItemContext do
with_them
do
subject
{
subjects
[
index
]
}
let
(
:positions
)
{
subject
.
scoped_items
.
map
(
&
:relative_position
)
}
it
'is possible to shift_right, which will consume the gap at the end'
do
subject
.
shift_right
expect
(
subject
.
find_next_gap_after
).
not_to
be_present
expect
(
positions
).
to
all
(
be_between
(
range
.
first
,
range
.
last
))
expect
(
positions
).
to
eq
(
positions
.
uniq
)
end
it
'is possible to create_space_right, which will move the gap to immediately after'
do
subject
.
create_space_right
expect
(
subject
.
find_next_gap_after
).
to
have_attributes
(
start_pos:
subject
.
relative_position
)
expect
(
positions
).
to
all
(
be_between
(
range
.
first
,
range
.
last
))
expect
(
positions
).
to
eq
(
positions
.
uniq
)
end
it
'is possible to shift_left, which will consume the gap at the start'
do
subject
.
shift_left
expect
(
subject
.
find_next_gap_before
).
not_to
be_present
expect
(
positions
).
to
all
(
be_between
(
range
.
first
,
range
.
last
))
expect
(
positions
).
to
eq
(
positions
.
uniq
)
end
it
'is possible to create_space_left, which will move the gap to immediately before'
do
subject
.
create_space_left
expect
(
subject
.
find_next_gap_before
).
to
have_attributes
(
start_pos:
subject
.
relative_position
)
expect
(
positions
).
to
all
(
be_between
(
range
.
first
,
range
.
last
))
expect
(
positions
).
to
eq
(
positions
.
uniq
)
end
end
end
...
...
@@ -63,6 +72,26 @@ RSpec.describe Gitlab::RelativePositioning::ItemContext do
context
'there is a gap of multiple spaces'
do
let_it_be
(
:issues
)
{
[
range
.
first
,
range
.
last
].
map
{
|
pos
|
create_issue
(
pos
)
}
}
it
'is impossible to move the last element to the right'
do
expect
{
subjects
.
last
.
shift_right
}.
to
raise_error
(
Gitlab
::
RelativePositioning
::
NoSpaceLeft
)
end
it
'is impossible to move the first element to the left'
do
expect
{
subjects
.
first
.
shift_left
}.
to
raise_error
(
Gitlab
::
RelativePositioning
::
NoSpaceLeft
)
end
it
'is possible to move the last element to the left'
do
subject
=
subjects
.
last
expect
{
subject
.
shift_left
}.
to
change
{
subject
.
relative_position
}.
by
(
be
<
0
)
end
it
'is possible to move the first element to the right'
do
subject
=
subjects
.
first
expect
{
subject
.
shift_right
}.
to
change
{
subject
.
relative_position
}.
by
(
be
>
0
)
end
it
'is possible to find the gap from the right'
do
gap
=
Gitlab
::
RelativePositioning
::
Gap
.
new
(
range
.
last
,
range
.
first
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment