BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
988747df
Unverified
Commit
988747df
authored
Feb 01, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed notes_spec.js
parent
0f895147
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
34 deletions
+100
-34
notes_spec.js
spec/javascripts/notes_spec.js
+100
-34
No files found.
spec/javascripts/notes_spec.js
View file @
988747df
/* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, max-len */
import
_
from
'underscore'
;
import
MockAdapter
from
'axios-mock-adapter'
;
import
axios
from
'~/lib/utils/axios_utils'
;
import
*
as
urlUtils
from
'~/lib/utils/url_utility'
;
import
'autosize'
;
import
'~/gl_form'
;
import
'~/lib/utils/text_utility'
;
import
'~/render_gfm'
;
import
Notes
from
'~/notes'
;
import
timeoutPromise
from
'./helpers/set_timeout_promise_helper'
;
(
function
()
{
window
.
gon
||
(
window
.
gon
=
{});
...
...
@@ -119,6 +122,7 @@ import Notes from '~/notes';
let
noteEntity
;
let
$form
;
let
$notesContainer
;
let
mock
;
beforeEach
(()
=>
{
this
.
notes
=
new
Notes
(
''
,
[]);
...
...
@@ -136,17 +140,18 @@ import Notes from '~/notes';
$form
=
$
(
'form.js-main-target-form'
);
$notesContainer
=
$
(
'ul.main-notes-list'
);
$form
.
find
(
'textarea.js-note-text'
).
val
(
sampleComment
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onPost
(
/
(
.*
)\/
notes$/
).
reply
(
200
,
noteEntity
);
});
it
(
'updates note and resets edit form'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'updates note and resets edit form'
,
(
done
)
=>
{
spyOn
(
this
.
notes
,
'revertNoteEditForm'
);
spyOn
(
this
.
notes
,
'setupNewNote'
);
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
noteEntity
);
setTimeout
(()
=>
{
const
$targetNote
=
$notesContainer
.
find
(
`#note_
${
noteEntity
.
id
}
`
);
const
updatedNote
=
Object
.
assign
({},
noteEntity
);
updatedNote
.
note
=
'bar'
;
...
...
@@ -154,6 +159,9 @@ import Notes from '~/notes';
expect
(
this
.
notes
.
revertNoteEditForm
).
toHaveBeenCalledWith
(
$targetNote
);
expect
(
this
.
notes
.
setupNewNote
).
toHaveBeenCalled
();
done
();
});
});
});
...
...
@@ -479,8 +487,19 @@ import Notes from '~/notes';
};
let
$form
;
let
$notesContainer
;
let
mock
;
function
mockNotesPost
()
{
mock
.
onPost
(
/
(
.*
)\/
notes$/
).
reply
(
200
,
note
);
}
function
mockNotesPostError
()
{
mock
.
onPost
(
/
(
.*
)\/
notes$/
).
networkError
();
}
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
this
.
notes
=
new
Notes
(
''
,
[]);
window
.
gon
.
current_username
=
'root'
;
window
.
gon
.
current_user_fullname
=
'Administrator'
;
...
...
@@ -489,63 +508,92 @@ import Notes from '~/notes';
$form
.
find
(
'textarea.js-note-text'
).
val
(
sampleComment
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'should show placeholder note while new comment is being posted'
,
()
=>
{
mockNotesPost
();
$
(
'.js-comment-button'
).
click
();
expect
(
$notesContainer
.
find
(
'.note.being-posted'
).
length
>
0
).
toEqual
(
true
);
});
it
(
'should remove placeholder note when new comment is done posting'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should remove placeholder note when new comment is done posting'
,
(
done
)
=>
{
mockNotesPost
();
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
note
);
setTimeout
(()
=>
{
expect
(
$notesContainer
.
find
(
'.note.being-posted'
).
length
).
toEqual
(
0
);
done
();
});
});
it
(
'should show actual note element when new comment is done posting'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should show actual note element when new comment is done posting'
,
(
done
)
=>
{
mockNotesPost
();
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
note
);
setTimeout
(()
=>
{
expect
(
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
).
length
>
0
).
toEqual
(
true
);
done
();
});
});
it
(
'should reset Form when new comment is done posting'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should reset Form when new comment is done posting'
,
(
done
)
=>
{
mockNotesPost
();
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
note
);
setTimeout
(()
=>
{
expect
(
$form
.
find
(
'textarea.js-note-text'
).
val
()).
toEqual
(
''
);
done
();
});
});
it
(
'should show flash error message when new comment failed to be posted'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should show flash error message when new comment failed to be posted'
,
(
done
)
=>
{
mockNotesPostError
();
$
(
'.js-comment-button'
).
click
();
deferred
.
reject
();
setTimeout
(()
=>
{
expect
(
$notesContainer
.
parent
().
find
(
'.flash-container .flash-text'
).
is
(
':visible'
)).
toEqual
(
true
);
done
();
});
});
it
(
'should show flash error message when comment failed to be updated'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
it
(
'should show flash error message when comment failed to be updated'
,
(
done
)
=>
{
mockNotesPost
();
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
note
);
timeoutPromise
()
.
then
(()
=>
{
const
$noteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
);
$noteEl
.
find
(
'.js-note-edit'
).
click
();
$noteEl
.
find
(
'textarea.js-note-text'
).
val
(
updatedComment
);
$noteEl
.
find
(
'.js-comment-save-button'
).
click
();
deferred
.
reject
();
mock
.
restore
();
mockNotesPostError
();
$noteEl
.
find
(
'.js-comment-save-button'
).
click
();
})
.
then
(
timeoutPromise
)
.
then
(()
=>
{
const
$updatedNoteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
);
expect
(
$updatedNoteEl
.
hasClass
(
'.being-posted'
)).
toEqual
(
false
);
// Remove being-posted visuals
expect
(
$updatedNoteEl
.
find
(
'.note-text'
).
text
().
trim
()).
toEqual
(
sampleComment
);
// See if comment reverted back to original
expect
(
$
(
'.flash-container'
).
is
(
':visible'
)).
toEqual
(
true
);
// Flash error message shown
done
();
})
.
catch
(
done
.
fail
);
});
});
...
...
@@ -563,8 +611,12 @@ import Notes from '~/notes';
};
let
$form
;
let
$notesContainer
;
let
mock
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
.
onPost
(
/
(
.*
)\/
notes$/
).
reply
(
200
,
note
);
this
.
notes
=
new
Notes
(
''
,
[]);
window
.
gon
.
current_username
=
'root'
;
window
.
gon
.
current_user_fullname
=
'Administrator'
;
...
...
@@ -582,15 +634,20 @@ import Notes from '~/notes';
$form
.
find
(
'textarea.js-note-text'
).
val
(
sampleComment
);
});
it
(
'should remove slash command placeholder when comment with slash commands is done posting'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'should remove slash command placeholder when comment with slash commands is done posting'
,
(
done
)
=>
{
spyOn
(
gl
.
awardsHandler
,
'addAwardToEmojiBar'
).
and
.
callThrough
();
$
(
'.js-comment-button'
).
click
();
expect
(
$notesContainer
.
find
(
'.system-note.being-posted'
).
length
).
toEqual
(
1
);
// Placeholder shown
deferred
.
resolve
(
note
);
setTimeout
(()
=>
{
expect
(
$notesContainer
.
find
(
'.system-note.being-posted'
).
length
).
toEqual
(
0
);
// Placeholder removed
done
();
});
});
});
...
...
@@ -607,8 +664,12 @@ import Notes from '~/notes';
};
let
$form
;
let
$notesContainer
;
let
mock
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
.
onPost
(
/
(
.*
)\/
notes$/
).
reply
(
200
,
note
);
this
.
notes
=
new
Notes
(
''
,
[]);
window
.
gon
.
current_username
=
'root'
;
window
.
gon
.
current_user_fullname
=
'Administrator'
;
...
...
@@ -617,12 +678,14 @@ import Notes from '~/notes';
$form
.
find
(
'textarea.js-note-text'
).
html
(
sampleComment
);
});
it
(
'should not render a script tag'
,
()
=>
{
const
deferred
=
$
.
Deferred
();
spyOn
(
$
,
'ajax'
).
and
.
returnValue
(
deferred
.
promise
());
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'should not render a script tag'
,
(
done
)
=>
{
$
(
'.js-comment-button'
).
click
();
deferred
.
resolve
(
note
);
setTimeout
(()
=>
{
const
$noteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
);
$noteEl
.
find
(
'.js-note-edit'
).
click
();
$noteEl
.
find
(
'textarea.js-note-text'
).
html
(
updatedComment
);
...
...
@@ -630,6 +693,9 @@ import Notes from '~/notes';
const
$updatedNoteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
).
find
(
'.js-task-list-container'
);
expect
(
$updatedNoteEl
.
find
(
'.note-text'
).
text
().
trim
()).
toEqual
(
''
);
done
();
});
});
});
...
...
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