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
Boxiang Sun
gitlab-ce
Commits
7430149d
Commit
7430149d
authored
Feb 12, 2019
by
Winnie Hellmann
Committed by
Fatih Acet
Feb 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert noteable_note_spec.js to Vue test utils
(cherry picked from commit
861f93e6
)
parent
d663c926
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
38 deletions
+98
-38
spec/javascripts/notes/components/noteable_note_spec.js
spec/javascripts/notes/components/noteable_note_spec.js
+85
-33
spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js
...ue_shared/components/user_avatar/user_avatar_link_spec.js
+13
-5
No files found.
spec/javascripts/notes/components/noteable_note_spec.js
View file @
7430149d
import
$
from
'
jquery
'
;
import
_
from
'
underscore
'
;
import
Vue
from
'
vue
'
;
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
createStore
from
'
~/notes/stores
'
;
import
issueNote
from
'
~/notes/components/noteable_note.vue
'
;
import
NoteHeader
from
'
~/notes/components/note_header.vue
'
;
import
UserAvatarLink
from
'
~/vue_shared/components/user_avatar/user_avatar_link.vue
'
;
import
NoteActions
from
'
~/notes/components/note_actions.vue
'
;
import
NoteBody
from
'
~/notes/components/note_body.vue
'
;
import
{
noteableDataMock
,
notesDataMock
,
note
}
from
'
../mock_data
'
;
describe
(
'
issue_note
'
,
()
=>
{
let
store
;
let
vm
;
let
wrapper
;
beforeEach
(()
=>
{
const
Component
=
Vue
.
extend
(
issueNote
);
store
=
createStore
();
store
.
dispatch
(
'
setNoteableData
'
,
noteableDataMock
);
store
.
dispatch
(
'
setNotesData
'
,
notesDataMock
);
vm
=
new
Component
({
const
localVue
=
createLocalVue
();
wrapper
=
shallowMount
(
issueNote
,
{
store
,
propsData
:
{
note
,
},
}).
$mount
();
sync
:
false
,
localVue
,
});
});
afterEach
(()
=>
{
vm
.
$
destroy
();
wrapper
.
destroy
();
});
it
(
'
should render user information
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.user-avatar-link img
'
).
getAttribute
(
'
src
'
)).
toEqual
(
note
.
author
.
avatar_url
,
);
const
{
author
}
=
note
;
const
avatar
=
wrapper
.
find
(
UserAvatarLink
);
const
avatarProps
=
avatar
.
props
();
expect
(
avatarProps
.
linkHref
).
toBe
(
author
.
path
);
expect
(
avatarProps
.
imgSrc
).
toBe
(
author
.
avatar_url
);
expect
(
avatarProps
.
imgAlt
).
toBe
(
author
.
name
);
expect
(
avatarProps
.
imgSize
).
toBe
(
40
);
});
it
(
'
should render note header content
'
,
()
=>
{
const
el
=
vm
.
$el
.
querySelector
(
'
.note-header .note-header-author-name
'
);
const
noteHeader
=
wrapper
.
find
(
NoteHeader
);
const
noteHeaderProps
=
noteHeader
.
props
();
expect
(
el
.
textContent
.
trim
()).
toEqual
(
note
.
author
.
name
);
expect
(
noteHeaderProps
.
author
).
toEqual
(
note
.
author
);
expect
(
noteHeaderProps
.
createdAt
).
toEqual
(
note
.
created_at
);
expect
(
noteHeaderProps
.
noteId
).
toEqual
(
note
.
id
);
});
it
(
'
should render note actions
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.note-actions
'
)).
toBeDefined
();
const
{
author
}
=
note
;
const
noteActions
=
wrapper
.
find
(
NoteActions
);
const
noteActionsProps
=
noteActions
.
props
();
expect
(
noteActionsProps
.
authorId
).
toBe
(
author
.
id
);
expect
(
noteActionsProps
.
noteId
).
toBe
(
note
.
id
);
expect
(
noteActionsProps
.
noteUrl
).
toBe
(
note
.
noteable_note_url
);
expect
(
noteActionsProps
.
accessLevel
).
toBe
(
note
.
human_access
);
expect
(
noteActionsProps
.
canEdit
).
toBe
(
note
.
current_user
.
can_edit
);
expect
(
noteActionsProps
.
canAwardEmoji
).
toBe
(
note
.
current_user
.
can_award_emoji
);
expect
(
noteActionsProps
.
canDelete
).
toBe
(
note
.
current_user
.
can_edit
);
expect
(
noteActionsProps
.
canReportAsAbuse
).
toBe
(
true
);
expect
(
noteActionsProps
.
canResolve
).
toBe
(
false
);
expect
(
noteActionsProps
.
reportAbusePath
).
toBe
(
note
.
report_abuse_path
);
expect
(
noteActionsProps
.
resolvable
).
toBe
(
false
);
expect
(
noteActionsProps
.
isResolved
).
toBe
(
false
);
expect
(
noteActionsProps
.
isResolving
).
toBe
(
false
);
expect
(
noteActionsProps
.
resolvedBy
).
toEqual
({});
});
it
(
'
should render issue body
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.note-text
'
).
innerHTML
).
toEqual
(
note
.
note_html
);
const
noteBody
=
wrapper
.
find
(
NoteBody
);
const
noteBodyProps
=
noteBody
.
props
();
expect
(
noteBodyProps
.
note
).
toEqual
(
note
);
expect
(
noteBodyProps
.
line
).
toBe
(
null
);
expect
(
noteBodyProps
.
canEdit
).
toBe
(
note
.
current_user
.
can_edit
);
expect
(
noteBodyProps
.
isEditing
).
toBe
(
false
);
expect
(
noteBodyProps
.
helpPagePath
).
toBe
(
''
);
});
it
(
'
prevents note preview xss
'
,
done
=>
{
const
imgSrc
=
'
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
'
;
const
noteBody
=
`<img src="
${
imgSrc
}
" onload="alert(1)" />`
;
const
alertSpy
=
spyOn
(
window
,
'
alert
'
);
vm
.
updateNote
=
()
=>
new
Promise
(
$
.
noop
);
store
.
hotUpdate
({
actions
:
{
updateNote
()
{},
},
});
const
noteBodyComponent
=
wrapper
.
find
(
NoteBody
);
vm
.
formUpdateHandler
(
noteBody
,
null
,
$
.
noop
);
noteBodyComponent
.
vm
.
$emit
(
'
handleFormUpdate
'
,
noteBody
,
null
,
()
=>
{}
);
setTimeout
(()
=>
{
expect
(
alertSpy
).
not
.
toHaveBeenCalled
();
expect
(
vm
.
note
.
note_html
).
toEqual
(
_
.
escape
(
noteBody
));
expect
(
wrapper
.
vm
.
note
.
note_html
).
toEqual
(
_
.
escape
(
noteBody
));
done
();
},
0
);
});
describe
(
'
cancel edit
'
,
()
=>
{
it
(
'
restores content of updated note
'
,
done
=>
{
const
noteBody
=
'
updated note text
'
;
vm
.
updateNote
=
()
=>
Promise
.
resolve
();
vm
.
formUpdateHandler
(
noteBody
,
null
,
$
.
noop
);
setTimeout
(()
=>
{
expect
(
vm
.
note
.
note_html
).
toEqual
(
noteBody
);
vm
.
formCancelHandler
();
setTimeout
(()
=>
{
expect
(
vm
.
note
.
note_html
).
toEqual
(
noteBody
);
done
();
});
const
updatedText
=
'
updated note text
'
;
store
.
hotUpdate
({
actions
:
{
updateNote
()
{},
},
});
const
noteBody
=
wrapper
.
find
(
NoteBody
);
noteBody
.
vm
.
resetAutoSave
=
()
=>
{};
noteBody
.
vm
.
$emit
(
'
handleFormUpdate
'
,
updatedText
,
null
,
()
=>
{});
wrapper
.
vm
.
$nextTick
()
.
then
(()
=>
{
const
noteBodyProps
=
noteBody
.
props
();
expect
(
noteBodyProps
.
note
.
note_html
).
toBe
(
updatedText
);
noteBody
.
vm
.
$emit
(
'
cancelForm
'
);
})
.
then
(()
=>
wrapper
.
vm
.
$nextTick
())
.
then
(()
=>
{
const
noteBodyProps
=
noteBody
.
props
();
expect
(
noteBodyProps
.
note
.
note_html
).
toBe
(
note
.
note_html
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
spec/javascripts/vue_shared/components/user_avatar/user_avatar_link_spec.js
View file @
7430149d
import
_
from
'
underscore
'
;
import
Vue
from
'
vue
'
;
import
UserAvatarLink
from
'
~/vue_shared/components/user_avatar/user_avatar_link.vue
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
describe
(
'
User Avatar Link Component
'
,
function
()
{
beforeEach
(
function
()
{
this
.
propsData
=
{
linkHref
:
'
myavatarurl.com
'
,
linkHref
:
`
${
TEST_HOST
}
/myavatarurl.com`
,
imgSize
:
99
,
imgSrc
:
'
myavatarurl.com
'
,
imgSrc
:
`
${
TEST_HOST
}
/myavatarurl.com`
,
imgAlt
:
'
mydisplayname
'
,
imgCssClasses
:
'
myextraavatarclass
'
,
tooltipText
:
'
tooltip text
'
,
...
...
@@ -37,11 +38,18 @@ describe('User Avatar Link Component', function() {
});
it
(
'
should render <a> as a child element
'
,
function
()
{
expect
(
this
.
userAvatarLink
.
$el
.
tagName
).
toBe
(
'
A
'
);
const
link
=
this
.
userAvatarLink
.
$el
;
expect
(
link
.
tagName
).
toBe
(
'
A
'
);
expect
(
link
.
href
).
toBe
(
this
.
propsData
.
linkHref
);
});
it
(
'
should have <img> as a child element
'
,
function
()
{
expect
(
this
.
userAvatarLink
.
$el
.
querySelector
(
'
img
'
)).
not
.
toBeNull
();
it
(
'
renders imgSrc with imgSize as image
'
,
function
()
{
const
{
imgSrc
,
imgSize
}
=
this
.
propsData
;
const
image
=
this
.
userAvatarLink
.
$el
.
querySelector
(
'
img
'
);
expect
(
image
).
not
.
toBeNull
();
expect
(
image
.
src
).
toBe
(
`
${
imgSrc
}
?width=
${
imgSize
}
`
);
});
it
(
'
should return necessary props as defined
'
,
function
()
{
...
...
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