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
6b002e6e
Commit
6b002e6e
authored
Apr 15, 2021
by
Denys Mishunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not render Source Editor by default
parent
c821e3a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
...ipts/vue_shared/components/blob_viewers/simple_viewer.vue
+8
-4
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
.../vue_shared/components/blob_viewers/simple_viewer_spec.js
+33
-11
No files found.
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
View file @
6b002e6e
<
script
>
/* eslint-disable vue/no-v-html */
import
{
GlIcon
}
from
'
@gitlab/ui
'
;
import
EditorLite
from
'
~/vue_shared/components/editor_lite.vue
'
;
import
glFeatureFlagsMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
./constants
'
;
import
ViewerMixin
from
'
./mixins
'
;
export
default
{
components
:
{
GlIcon
,
EditorLite
,
EditorLite
:
()
=>
import
(
/* webpackChunkName: 'EditorLite' */
'
~/vue_shared/components/editor_lite.vue
'
),
},
mixins
:
[
ViewerMixin
],
mixins
:
[
ViewerMixin
,
glFeatureFlagsMixin
()
],
inject
:
[
'
blobHash
'
],
data
()
{
return
{
...
...
@@ -21,6 +22,9 @@ export default {
lineNumbers
()
{
return
this
.
content
.
split
(
'
\n
'
).
length
;
},
refactorBlobViewerEnabled
()
{
return
this
.
glFeatures
.
refactorBlobViewer
;
},
},
mounted
()
{
const
{
hash
}
=
window
.
location
;
...
...
@@ -49,7 +53,7 @@ export default {
<
template
>
<div>
<editor-lite
v-if=
"isRawContent"
v-if=
"isRawContent
&& refactorBlobViewerEnabled
"
:value=
"content"
:file-name=
"fileName"
:editor-options=
"
{ readOnly: true }"
...
...
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
View file @
6b002e6e
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
~/vue_shared/components/blob_viewers/constants
'
;
import
SimpleViewer
from
'
~/vue_shared/components/blob_viewers/simple_viewer.vue
'
;
import
EditorLite
from
'
~/vue_shared/components/editor_lite.vue
'
;
...
...
@@ -8,10 +9,17 @@ describe('Blob Simple Viewer component', () => {
const
contentMock
=
`<span id="LC1">First</span>\n<span id="LC2">Second</span>\n<span id="LC3">Third</span>`
;
const
blobHash
=
'
foo-bar
'
;
function
createComponent
(
content
=
contentMock
,
isRawContent
=
false
)
{
function
createComponent
(
content
=
contentMock
,
isRawContent
=
false
,
isRefactorFlagEnabled
=
false
,
)
{
wrapper
=
shallowMount
(
SimpleViewer
,
{
provide
:
{
blobHash
,
glFeatures
:
{
refactorBlobViewer
:
isRefactorFlagEnabled
,
},
},
propsData
:
{
content
,
...
...
@@ -87,17 +95,31 @@ describe('Blob Simple Viewer component', () => {
});
});
describe
(
'
raw content
'
,
()
=>
{
describe
(
'
Vue refactoring to use Source Editor
'
,
()
=>
{
const
findEditorLite
=
()
=>
wrapper
.
find
(
EditorLite
);
const
isRawContent
=
true
;
it
(
'
uses the Editor Lite component in readonly mode when viewing raw content
'
,
()
=>
{
createComponent
(
'
raw content
'
,
isRawContent
);
expect
(
findEditorLite
().
exists
()).
toBe
(
true
);
expect
(
findEditorLite
().
props
(
'
value
'
)).
toBe
(
'
raw content
'
);
expect
(
findEditorLite
().
props
(
'
fileName
'
)).
toBe
(
'
test.js
'
);
expect
(
findEditorLite
().
props
(
'
editorOptions
'
)).
toEqual
({
readOnly
:
true
});
});
it
.
each
`
doesRender | condition | isRawContent | isRefactorFlagEnabled
${
'
Does not
'
}
|
${
'
rawContent is not specified
'
}
|
${
false
}
|
${
true
}
${
'
Does not
'
}
|
${
'
feature flag is disabled is not specified
'
}
|
${
true
}
|
${
false
}
${
'
Does not
'
}
|
${
'
both, the FF and rawContent are not specified
'
}
|
${
false
}
|
${
false
}
${
'
Does
'
}
|
${
'
both, the FF and rawContent are specified
'
}
|
${
true
}
|
${
true
}
`
(
'
$doesRender render Editor Lite component in readonly mode when $condition
'
,
async
({
isRawContent
,
isRefactorFlagEnabled
}
=
{})
=>
{
createComponent
(
'
raw content
'
,
isRawContent
,
isRefactorFlagEnabled
);
await
waitForPromises
();
if
(
isRawContent
&&
isRefactorFlagEnabled
)
{
expect
(
findEditorLite
().
exists
()).
toBe
(
true
);
expect
(
findEditorLite
().
props
(
'
value
'
)).
toBe
(
'
raw content
'
);
expect
(
findEditorLite
().
props
(
'
fileName
'
)).
toBe
(
'
test.js
'
);
expect
(
findEditorLite
().
props
(
'
editorOptions
'
)).
toEqual
({
readOnly
:
true
});
}
else
{
expect
(
findEditorLite
().
exists
()).
toBe
(
false
);
}
},
);
});
});
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