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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
7cc4546b
Commit
7cc4546b
authored
Apr 13, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs
parent
796acbe1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
191 additions
and
13 deletions
+191
-13
spec/features/projects/blobs/blob_show_spec.rb
spec/features/projects/blobs/blob_show_spec.rb
+42
-13
spec/javascripts/blob/viewer/index_spec.js
spec/javascripts/blob/viewer/index_spec.js
+120
-0
spec/javascripts/fixtures/blob.rb
spec/javascripts/fixtures/blob.rb
+29
-0
No files found.
spec/features/projects/blobs/blob_show_spec.rb
View file @
7cc4546b
...
@@ -4,19 +4,48 @@ feature 'File blob', feature: true do
...
@@ -4,19 +4,48 @@ feature 'File blob', feature: true do
include
TreeHelper
include
TreeHelper
let
(
:project
)
{
create
(
:project
,
:public
,
:test_repo
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:test_repo
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'feature'
,
target_branch:
'master'
)
}
let
(
:branch
)
{
'master'
}
def
visit_blob
(
path
,
fragment
=
nil
)
let
(
:file_path
)
{
project
.
repository
.
ls_files
(
project
.
repository
.
root_ref
)[
1
]
}
visit
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
'master'
,
path
),
anchor:
fragment
)
end
context
'anonymous'
do
context
'from blob file path'
do
context
'text files'
do
before
do
it
'shows rendered output for SVG'
do
visit
namespace_project_blob_path
(
project
.
namespace
,
project
,
tree_join
(
branch
,
file_path
))
visit_blob
(
'files/images/wm.svg'
)
end
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
)
it
'updates content'
do
end
expect
(
page
).
to
have_link
'Edit'
end
it
'switches to code view'
do
visit_blob
(
'files/images/wm.svg'
)
first
(
'.js-blob-viewer-switcher'
).
click
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="rich"]'
,
visible:
false
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
end
it
'opens raw mode when linking to a line in SVG file'
do
visit_blob
(
'files/images/wm.svg'
,
'L1'
)
expect
(
page
).
to
have_selector
(
'#LC1.hll'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
end
it
'opens raw mode when linking to a line in MD file'
do
visit_blob
(
'README.md'
,
'L1'
)
expect
(
page
).
to
have_selector
(
'#LC1.hll'
)
expect
(
page
).
to
have_selector
(
'.blob-viewer[data-type="simple"]'
)
end
end
context
'binary files'
do
it
'does not show view toggle buttons in toolbar'
do
visit_blob
(
'Gemfile.zip'
)
expect
(
first
(
'.file-actions .btn-group'
)).
to
have_selector
(
'.btn'
,
count:
1
)
expect
(
first
(
'.file-actions .btn-group .btn'
)[
:title
]).
to
eq
(
'Download blob'
)
end
end
end
end
end
end
spec/javascripts/blob/viewer/index_spec.js
0 → 100644
View file @
7cc4546b
/* eslint-disable no-new */
import
BlobViewer
from
'
~/blob/viewer/index
'
;
describe
(
'
Blob viewer
'
,
()
=>
{
preloadFixtures
(
'
blob/show.html.raw
'
);
beforeEach
(()
=>
{
loadFixtures
(
'
blob/show.html.raw
'
);
$
(
'
#modal-upload-blob
'
).
remove
();
new
BlobViewer
();
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(()
=>
{
const
d
=
$
.
Deferred
();
d
.
resolve
({
html
:
'
<div>testing</div>
'
,
});
return
d
.
promise
();
});
});
afterEach
(()
=>
{
location
.
hash
=
''
;
});
it
(
'
loads source file after switching views
'
,
(
done
)
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
)
.
classList
.
contains
(
'
hidden
'
),
).
toBeFalsy
();
done
();
});
});
it
(
'
loads source file when line number is in hash
'
,
(
done
)
=>
{
location
.
hash
=
'
#L1
'
;
new
BlobViewer
();
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
)
.
classList
.
contains
(
'
hidden
'
),
).
toBeFalsy
();
done
();
});
});
it
(
'
doesnt reload file if already loaded
'
,
(
done
)
=>
{
const
asyncClick
=
()
=>
new
Promise
((
resolve
)
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
).
click
();
setTimeout
(
resolve
);
});
asyncClick
()
.
then
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
return
asyncClick
();
})
.
then
(()
=>
{
expect
(
$
.
ajax
.
calls
.
count
()).
toBe
(
1
);
expect
(
document
.
querySelector
(
'
.blob-viewer[data-type="simple"]
'
).
getAttribute
(
'
data-loaded
'
),
).
toBe
(
'
true
'
);
done
();
});
});
describe
(
'
copy blob button
'
,
()
=>
{
it
(
'
disabled on load
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.js-copy-blob-source-btn
'
).
classList
.
contains
(
'
disabled
'
),
).
toBeTruthy
();
});
it
(
'
has tooltip when disabled
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.js-copy-blob-source-btn
'
).
getAttribute
(
'
data-original-title
'
),
).
toBe
(
'
Switch to the source view to copy the source to the clipboard
'
);
});
it
(
'
enables after switching to simple view
'
,
(
done
)
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
document
.
querySelector
(
'
.js-copy-blob-source-btn
'
).
classList
.
contains
(
'
disabled
'
),
).
toBeFalsy
();
done
();
});
});
it
(
'
updates tooltip after switching to simple view
'
,
(
done
)
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switcher[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
document
.
querySelector
(
'
.js-copy-blob-source-btn
'
).
getAttribute
(
'
data-original-title
'
),
).
toBe
(
'
Copy to clipboard
'
);
done
();
});
});
});
});
spec/javascripts/fixtures/blob.rb
0 → 100644
View file @
7cc4546b
require
'spec_helper'
describe
Projects
::
BlobController
,
'(JavaScript fixtures)'
,
type: :controller
do
include
JavaScriptFixturesHelpers
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
namespace
,
path:
'branches-project'
)
}
render_views
before
(
:all
)
do
clean_frontend_fixtures
(
'blob/'
)
end
before
(
:each
)
do
sign_in
(
admin
)
end
it
'blob/show.html.raw'
do
|
example
|
get
(
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
'add-ipython-files/files/ipython/basic.ipynb'
)
expect
(
response
).
to
be_success
store_frontend_fixture
(
response
,
example
.
description
)
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