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
87d87413
Commit
87d87413
authored
Nov 20, 2020
by
jerasmus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add apply suggestion component
Added an apply suggestion component
parent
46fa8712
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
0 deletions
+137
-0
app/assets/javascripts/vue_shared/components/markdown/apply_suggestion.vue
...ripts/vue_shared/components/markdown/apply_suggestion.vue
+59
-0
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/frontend/vue_shared/components/markdown/apply_suggestion_spec.js
...d/vue_shared/components/markdown/apply_suggestion_spec.js
+72
-0
No files found.
app/assets/javascripts/vue_shared/components/markdown/apply_suggestion.vue
0 → 100644
View file @
87d87413
<
script
>
import
{
GlDropdown
,
GlDropdownForm
,
GlFormTextarea
,
GlButton
}
from
'
@gitlab/ui
'
;
import
{
__
,
sprintf
}
from
'
~/locale
'
;
export
default
{
components
:
{
GlDropdown
,
GlDropdownForm
,
GlFormTextarea
,
GlButton
},
props
:
{
disabled
:
{
type
:
Boolean
,
required
:
false
,
default
:
false
,
},
fileName
:
{
type
:
String
,
required
:
true
,
},
},
data
()
{
return
{
message
:
null
,
buttonText
:
__
(
'
Apply suggestion
'
),
headerText
:
__
(
'
Apply suggestion commit message
'
),
};
},
computed
:
{
placeholderText
()
{
return
sprintf
(
__
(
'
Apply suggestion on %{fileName}
'
),
{
fileName
:
this
.
fileName
});
},
},
methods
:
{
onApply
()
{
this
.
$emit
(
'
apply
'
,
this
.
message
||
this
.
placeholderText
);
},
},
};
</
script
>
<
template
>
<gl-dropdown
:text=
"buttonText"
:header-text=
"headerText"
:disabled=
"disabled"
boundary=
"window"
right=
"true"
menu-class=
"gl-w-full! gl-pb-0!"
>
<gl-dropdown-form
class=
"gl-m-3!"
>
<gl-form-textarea
v-model=
"message"
:placeholder=
"placeholderText"
/>
<gl-button
class=
"gl-w-quarter! gl-mt-3 gl-text-center! float-right"
category=
"secondary"
variant=
"success"
@
click=
"onApply"
>
{{
__
(
'
Apply
'
)
}}
</gl-button>
</gl-dropdown-form>
</gl-dropdown>
</
template
>
locale/gitlab.pot
View file @
87d87413
...
...
@@ -3453,6 +3453,12 @@ msgstr ""
msgid "Apply suggestion"
msgstr ""
msgid "Apply suggestion commit message"
msgstr ""
msgid "Apply suggestion on %{fileName}"
msgstr ""
msgid "Apply suggestions"
msgstr ""
...
...
spec/frontend/vue_shared/components/markdown/apply_suggestion_spec.js
0 → 100644
View file @
87d87413
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlDropdown
,
GlFormTextarea
,
GlButton
}
from
'
@gitlab/ui
'
;
import
ApplySuggestionComponent
from
'
~/vue_shared/components/markdown/apply_suggestion.vue
'
;
describe
(
'
Apply Suggestion component
'
,
()
=>
{
const
propsData
=
{
fileName
:
'
test.js
'
,
disabled
:
false
};
let
wrapper
;
const
createWrapper
=
props
=>
{
wrapper
=
shallowMount
(
ApplySuggestionComponent
,
{
propsData
:
{
...
propsData
,
...
props
}
});
};
const
findDropdown
=
()
=>
wrapper
.
find
(
GlDropdown
);
const
findTextArea
=
()
=>
wrapper
.
find
(
GlFormTextarea
);
const
findApplyButton
=
()
=>
wrapper
.
find
(
GlButton
);
beforeEach
(()
=>
createWrapper
());
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
});
describe
(
'
initial template
'
,
()
=>
{
it
(
'
renders a dropdown with the correct props
'
,
()
=>
{
const
dropdown
=
findDropdown
();
expect
(
dropdown
.
exists
()).
toBe
(
true
);
expect
(
dropdown
.
props
(
'
text
'
)).
toBe
(
'
Apply suggestion
'
);
expect
(
dropdown
.
props
(
'
headerText
'
)).
toBe
(
'
Apply suggestion commit message
'
);
expect
(
dropdown
.
props
(
'
disabled
'
)).
toBe
(
false
);
});
it
(
'
renders a textarea with the correct props
'
,
()
=>
{
const
textArea
=
findTextArea
();
expect
(
textArea
.
exists
()).
toBe
(
true
);
expect
(
textArea
.
attributes
(
'
placeholder
'
)).
toBe
(
'
Apply suggestion on test.js
'
);
});
it
(
'
renders an apply button
'
,
()
=>
{
const
applyButton
=
findApplyButton
();
expect
(
applyButton
.
exists
()).
toBe
(
true
);
expect
(
applyButton
.
text
()).
toBe
(
'
Apply
'
);
});
});
describe
(
'
disabled
'
,
()
=>
{
it
(
'
disables the dropdown
'
,
()
=>
{
createWrapper
({
disabled
:
true
});
expect
(
findDropdown
().
props
(
'
disabled
'
)).
toBe
(
true
);
});
});
describe
(
'
apply suggestion
'
,
()
=>
{
it
(
'
emits an apply event with a default message if no message was added
'
,
()
=>
{
findTextArea
().
vm
.
$emit
(
'
input
'
,
null
);
findApplyButton
().
vm
.
$emit
(
'
click
'
);
expect
(
wrapper
.
emitted
(
'
apply
'
)).
toEqual
([[
'
Apply suggestion on test.js
'
]]);
});
it
(
'
emits an apply event with a user-defined message
'
,
()
=>
{
findTextArea
().
vm
.
$emit
(
'
input
'
,
'
some text
'
);
findApplyButton
().
vm
.
$emit
(
'
click
'
);
expect
(
wrapper
.
emitted
(
'
apply
'
)).
toEqual
([[
'
some text
'
]]);
});
});
});
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