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
Léo-Paul Géneau
gitlab-ce
Commits
f5ce678d
Commit
f5ce678d
authored
Feb 26, 2019
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use autosave utilities in NoteForm component
parent
c75da766
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
9 deletions
+106
-9
app/assets/javascripts/notes/components/note_form.vue
app/assets/javascripts/notes/components/note_form.vue
+20
-1
spec/javascripts/notes/components/note_form_spec.js
spec/javascripts/notes/components/note_form_spec.js
+86
-8
No files found.
app/assets/javascripts/notes/components/note_form.vue
View file @
f5ce678d
...
@@ -7,6 +7,7 @@ import markdownField from '../../vue_shared/components/markdown/field.vue';
...
@@ -7,6 +7,7 @@ import markdownField from '../../vue_shared/components/markdown/field.vue';
import
issuableStateMixin
from
'
../mixins/issuable_state
'
;
import
issuableStateMixin
from
'
../mixins/issuable_state
'
;
import
resolvable
from
'
../mixins/resolvable
'
;
import
resolvable
from
'
../mixins/resolvable
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
getDraft
,
updateDraft
}
from
'
~/lib/utils/autosave
'
;
export
default
{
export
default
{
name
:
'
NoteForm
'
,
name
:
'
NoteForm
'
,
...
@@ -65,10 +66,21 @@ export default {
...
@@ -65,10 +66,21 @@ export default {
required
:
false
,
required
:
false
,
default
:
''
,
default
:
''
,
},
},
autosaveKey
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
},
},
data
()
{
data
()
{
let
updatedNoteBody
=
this
.
noteBody
;
if
(
!
updatedNoteBody
&&
this
.
autosaveKey
)
{
updatedNoteBody
=
getDraft
(
this
.
autosaveKey
)
||
''
;
}
return
{
return
{
updatedNoteBody
:
this
.
noteBody
,
updatedNoteBody
,
conflictWhileEditing
:
false
,
conflictWhileEditing
:
false
,
isSubmitting
:
false
,
isSubmitting
:
false
,
isResolving
:
this
.
resolveDiscussion
,
isResolving
:
this
.
resolveDiscussion
,
...
@@ -175,6 +187,12 @@ export default {
...
@@ -175,6 +187,12 @@ export default {
// Sends information about confirm message and if the textarea has changed
// Sends information about confirm message and if the textarea has changed
this
.
$emit
(
'
cancelForm
'
,
shouldConfirm
,
this
.
noteBody
!==
this
.
updatedNoteBody
);
this
.
$emit
(
'
cancelForm
'
,
shouldConfirm
,
this
.
noteBody
!==
this
.
updatedNoteBody
);
},
},
onInput
()
{
if
(
this
.
autosaveKey
)
{
const
{
autosaveKey
,
updatedNoteBody
:
text
}
=
this
;
updateDraft
(
autosaveKey
,
text
);
}
},
},
},
};
};
</
script
>
</
script
>
...
@@ -218,6 +236,7 @@ export default {
...
@@ -218,6 +236,7 @@ export default {
@
keydown.ctrl.enter=
"handleKeySubmit()"
@
keydown.ctrl.enter=
"handleKeySubmit()"
@
keydown.up=
"editMyLastNote()"
@
keydown.up=
"editMyLastNote()"
@
keydown.esc=
"cancelHandler(true)"
@
keydown.esc=
"cancelHandler(true)"
@
input=
"onInput"
></textarea>
></textarea>
</markdown-field>
</markdown-field>
<div
class=
"note-form-actions clearfix"
>
<div
class=
"note-form-actions clearfix"
>
...
...
spec/javascripts/notes/components/note_form_spec.js
View file @
f5ce678d
...
@@ -5,11 +5,33 @@ import MarkdownField from '~/vue_shared/components/markdown/field.vue';
...
@@ -5,11 +5,33 @@ import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import
{
noteableDataMock
,
notesDataMock
}
from
'
../mock_data
'
;
import
{
noteableDataMock
,
notesDataMock
}
from
'
../mock_data
'
;
describe
(
'
issue_note_form component
'
,
()
=>
{
describe
(
'
issue_note_form component
'
,
()
=>
{
const
dummyAutosaveKey
=
'
some-autosave-key
'
;
const
dummyDraft
=
'
dummy draft content
'
;
let
store
;
let
store
;
let
wrapper
;
let
wrapper
;
let
props
;
let
props
;
const
createComponentWrapper
=
()
=>
{
const
localVue
=
createLocalVue
();
return
shallowMount
(
NoteForm
,
{
store
,
propsData
:
props
,
// see https://gitlab.com/gitlab-org/gitlab-ce/issues/56317 for the following
localVue
,
sync
:
false
,
});
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
spyOnDependency
(
NoteForm
,
'
getDraft
'
).
and
.
callFake
(
key
=>
{
if
(
key
===
dummyAutosaveKey
)
{
return
dummyDraft
;
}
return
null
;
});
store
=
createStore
();
store
=
createStore
();
store
.
dispatch
(
'
setNoteableData
'
,
noteableDataMock
);
store
.
dispatch
(
'
setNoteableData
'
,
noteableDataMock
);
store
.
dispatch
(
'
setNotesData
'
,
notesDataMock
);
store
.
dispatch
(
'
setNotesData
'
,
notesDataMock
);
...
@@ -20,14 +42,7 @@ describe('issue_note_form component', () => {
...
@@ -20,14 +42,7 @@ describe('issue_note_form component', () => {
noteId
:
'
545
'
,
noteId
:
'
545
'
,
};
};
const
localVue
=
createLocalVue
();
wrapper
=
createComponentWrapper
();
wrapper
=
shallowMount
(
NoteForm
,
{
store
,
propsData
:
props
,
// see https://gitlab.com/gitlab-org/gitlab-ce/issues/56317 for the following
localVue
,
sync
:
false
,
});
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -181,4 +196,67 @@ describe('issue_note_form component', () => {
...
@@ -181,4 +196,67 @@ describe('issue_note_form component', () => {
});
});
});
});
});
});
describe
(
'
with autosaveKey
'
,
()
=>
{
beforeEach
(()
=>
{
wrapper
.
destroy
();
});
describe
(
'
with draft
'
,
()
=>
{
beforeEach
(
done
=>
{
Object
.
assign
(
props
,
{
noteBody
:
''
,
autosaveKey
:
dummyAutosaveKey
,
});
wrapper
=
createComponentWrapper
();
wrapper
.
vm
.
$nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
displays the draft in textarea
'
,
()
=>
{
const
textarea
=
wrapper
.
find
(
'
textarea
'
);
expect
(
textarea
.
element
.
value
).
toBe
(
dummyDraft
);
});
});
describe
(
'
without draft
'
,
()
=>
{
beforeEach
(
done
=>
{
Object
.
assign
(
props
,
{
noteBody
:
''
,
autosaveKey
:
'
some key without draft
'
,
});
wrapper
=
createComponentWrapper
();
wrapper
.
vm
.
$nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
leaves the textarea empty
'
,
()
=>
{
const
textarea
=
wrapper
.
find
(
'
textarea
'
);
expect
(
textarea
.
element
.
value
).
toBe
(
''
);
});
});
it
(
'
updates the draft if textarea content changes
'
,
()
=>
{
const
updateDraftSpy
=
spyOnDependency
(
NoteForm
,
'
updateDraft
'
).
and
.
stub
();
Object
.
assign
(
props
,
{
noteBody
:
''
,
autosaveKey
:
dummyAutosaveKey
,
});
wrapper
=
createComponentWrapper
();
const
textarea
=
wrapper
.
find
(
'
textarea
'
);
const
dummyContent
=
'
some new content
'
;
textarea
.
setValue
(
dummyContent
);
expect
(
updateDraftSpy
).
toHaveBeenCalledWith
(
dummyAutosaveKey
,
dummyContent
);
});
});
});
});
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