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
daac198b
Commit
daac198b
authored
Jul 30, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve project and personal snippet feature show spec
In this commit we improve some snippet feature specs.
parent
1bf84774
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
293 deletions
+172
-293
spec/features/projects/snippets/show_spec.rb
spec/features/projects/snippets/show_spec.rb
+20
-136
spec/features/snippets/show_spec.rb
spec/features/snippets/show_spec.rb
+10
-157
spec/support/shared_examples/features/snippets_shared_examples.rb
...port/shared_examples/features/snippets_shared_examples.rb
+142
-0
No files found.
spec/features/projects/snippets/show_spec.rb
View file @
daac198b
...
...
@@ -3,157 +3,41 @@
require
'spec_helper'
RSpec
.
describe
'Projects > Snippets > Project snippet'
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
,
file_name:
file_name
,
content:
content
)
}
before
do
stub_feature_flags
(
snippets_vue:
false
)
project
.
add_maintainer
(
user
)
sign_in
(
user
)
end
context
'Ruby file'
do
let
(
:file_name
)
{
'popen.rb'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/ruby/popen.rb'
).
data
}
before
do
visit
project_snippet_path
(
project
,
snippet
)
wait_for_requests
end
it
'displays the blob'
do
aggregate_failures
do
# shows highlighted Ruby code
expect
(
page
).
to
have_content
(
"require 'fileutils'"
)
# does not show a viewer switcher
expect
(
page
).
not_to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
do
create
(
:project
,
creator:
user
).
tap
do
|
p
|
p
.
add_maintainer
(
user
)
end
end
end
context
'Markdown file'
do
let
(
:file_name
)
{
'ruby-style-guide.md'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/markdown/ruby-style-guide.md'
).
data
}
context
'visiting directly'
do
before
do
visit
project_snippet_path
(
project
,
snippet
)
wait_for_requests
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
# shows rendered Markdown
expect
(
page
).
to
have_link
(
"PEP-8"
)
let_it_be
(
:snippet
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
)
}
# shows a viewer switcher
expect
(
page
).
to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows a disabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn.disabled'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
end
end
context
'switching to the simple viewer'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=simple]'
).
click
wait_for_requests
end
it
'displays the blob using the simple viewer'
do
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
context
'switching to the rich viewer again'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=rich]'
).
click
stub_feature_flags
(
snippets_vue:
false
)
wait_for_requests
sign_in
(
user
)
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
it_behaves_like
'show and render proper snippet blob'
do
let
(
:anchor
)
{
nil
}
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
end
context
'visiting with a line number anchor'
do
before
do
visit
project_snippet_path
(
project
,
snippet
,
anchor:
'L1'
)
subject
do
visit
project_snippet_path
(
project
,
snippet
,
anchor:
anchor
)
wait_for_requests
end
it
'displays the blob using the simple viewer'
do
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# highlights the line in question
expect
(
page
).
to
have_selector
(
'#LC1.hll'
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
it_behaves_like
'showing user status'
do
let
(
:file_name
)
{
'ruby-style-guide.md'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/markdown/ruby-style-guide.md'
).
data
}
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
let
(
:user_with_status
)
{
snippet
.
author
}
subject
do
visit
project_snippet_path
(
project
,
snippet
)
wait_for_requests
subject
{
visit
project_snippet_path
(
project
,
snippet
)
}
end
it_behaves_like
'does not show New Snippet button'
do
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
subject
{
visit
project_snippet_path
(
project
,
snippet
)
}
end
end
spec/features/snippets/show_spec.rb
View file @
daac198b
...
...
@@ -3,180 +3,33 @@
require
'spec_helper'
RSpec
.
describe
'Snippet'
,
:js
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
:repository
,
author:
user
)
}
before
do
stub_feature_flags
(
snippets_vue:
false
)
end
context
'Ruby file'
do
let
(
:file_name
)
{
'popen.rb'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/ruby/popen.rb'
).
data
}
it_behaves_like
'show and render proper snippet blob'
do
let
(
:anchor
)
{
nil
}
before
do
visit
snippet_path
(
snippet
)
wait_for_requests
end
it
'displays the blob'
do
aggregate_failures
do
# shows highlighted Ruby code
expect
(
page
).
to
have_content
(
"require 'fileutils'"
)
# does not show a viewer switcher
expect
(
page
).
not_to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
end
end
end
context
'Markdown file'
do
let
(
:file_name
)
{
'ruby-style-guide.md'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/markdown/ruby-style-guide.md'
).
data
}
context
'visiting directly'
do
before
do
visit
snippet_path
(
snippet
)
wait_for_requests
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
# shows rendered Markdown
expect
(
page
).
to
have_link
(
"PEP-8"
)
# shows a viewer switcher
expect
(
page
).
to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows a disabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn.disabled'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
end
end
context
'Markdown rendering'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
,
file_name:
file_name
,
content:
content
)
}
let
(
:file_name
)
{
'test.md'
}
let
(
:content
)
{
"1. one
\n
- sublist
\n
"
}
context
'when rendering default markdown'
do
it
'renders using CommonMark'
do
expect
(
page
).
to
have_content
(
"sublist"
)
expect
(
page
).
not_to
have_xpath
(
"//ol//li//ul"
)
end
end
end
context
'switching to the simple viewer'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=simple]'
).
click
wait_for_requests
end
it
'displays the blob using the simple viewer'
do
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
context
'switching to the rich viewer again'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=rich]'
).
click
subject
do
visit
snippet_path
(
snippet
,
anchor:
anchor
)
wait_for_requests
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
end
context
'visiting with a line number anchor'
do
before
do
visit
snippet_path
(
snippet
,
anchor:
'L1'
)
wait_for_requests
end
it
'displays the blob using the simple viewer'
do
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# highlights the line in question
expect
(
page
).
to
have_selector
(
'#LC1.hll'
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
it_behaves_like
'showing user status'
do
let
(
:file_name
)
{
'popen.rb'
}
let
(
:content
)
{
project
.
repository
.
blob_at
(
'master'
,
'files/ruby/popen.rb'
).
data
}
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
let
(
:user_with_status
)
{
snippet
.
author
}
subject
{
visit
snippet_path
(
snippet
)
}
end
context
'when user cannot create snippets'
do
let
(
:user
)
{
create
(
:user
,
:external
)
}
let
(
:snippet
)
{
create
(
:personal_snippet
,
:public
)
}
it_behaves_like
'does not show New Snippet button'
do
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
before
do
sign_in
(
user
)
visit
snippet_path
(
snippet
)
wait_for_requests
end
it
'does not show the "New Snippet" button'
do
expect
(
page
).
not_to
have_link
(
'New snippet'
)
end
subject
{
visit
snippet_path
(
snippet
)
}
end
end
spec/support/shared_examples/features/snippets_shared_examples.rb
View file @
daac198b
...
...
@@ -50,3 +50,145 @@ RSpec.shared_examples 'tabs with counts' do
expect
(
tab
.
find
(
'.badge'
).
text
).
to
eq
(
counts
[
:public
])
end
end
RSpec
.
shared_examples
'does not show New Snippet button'
do
let
(
:user
)
{
create
(
:user
,
:external
)
}
specify
do
sign_in
(
user
)
subject
wait_for_requests
expect
(
page
).
not_to
have_link
(
'New snippet'
)
end
end
RSpec
.
shared_examples
'show and render proper snippet blob'
do
before
do
allow_any_instance_of
(
Snippet
).
to
receive
(
:blobs
).
and_return
([
snippet
.
repository
.
blob_at
(
'master'
,
file_path
)])
end
context
'Ruby file'
do
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
it
'displays the blob'
do
subject
aggregate_failures
do
# shows highlighted Ruby code
expect
(
page
).
to
have_content
(
"require 'fileutils'"
)
# does not show a viewer switcher
expect
(
page
).
not_to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
end
end
end
context
'Markdown file'
do
let
(
:file_path
)
{
'files/markdown/ruby-style-guide.md'
}
context
'visiting directly'
do
before
do
subject
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
# shows rendered Markdown
expect
(
page
).
to
have_link
(
"PEP-8"
)
# shows a viewer switcher
expect
(
page
).
to
have_selector
(
'.js-blob-viewer-switcher'
)
# shows a disabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn.disabled'
)
# shows a raw button
expect
(
page
).
to
have_link
(
'Open raw'
)
# shows a download button
expect
(
page
).
to
have_link
(
'Download'
)
end
end
context
'switching to the simple viewer'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=simple]'
).
click
wait_for_requests
end
it
'displays the blob using the simple viewer'
do
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
context
'switching to the rich viewer again'
do
before
do
find
(
'.js-blob-viewer-switch-btn[data-viewer=rich]'
).
click
wait_for_requests
end
it
'displays the blob using the rich viewer'
do
aggregate_failures
do
# hides the simple viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
end
context
'visiting with a line number anchor'
do
let
(
:anchor
)
{
'L1'
}
it
'displays the blob using the simple viewer'
do
subject
aggregate_failures
do
# hides the rich viewer
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
# highlights the line in question
expect
(
page
).
to
have_selector
(
'#LC1.hll'
)
# shows highlighted Markdown code
expect
(
page
).
to
have_content
(
"[PEP-8](http://www.python.org/dev/peps/pep-0008/)"
)
# shows an enabled copy button
expect
(
page
).
to
have_selector
(
'.js-copy-blob-source-btn:not(.disabled)'
)
end
end
end
end
end
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