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
015e76ca
Commit
015e76ca
authored
Nov 26, 2019
by
Enrique Alcántara
Committed by
Natalia Tepluhina
Nov 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare markdown-header spec for bv upgrade
parent
cd98a2b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
36 deletions
+50
-36
spec/frontend/vue_shared/components/markdown/header_spec.js
spec/frontend/vue_shared/components/markdown/header_spec.js
+50
-36
No files found.
spec/frontend/vue_shared/components/markdown/header_spec.js
View file @
015e76ca
import
Vue
from
'
vue
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
$
from
'
jquery
'
;
import
headerComponent
from
'
~/vue_shared/components/markdown/header.vue
'
;
import
HeaderComponent
from
'
~/vue_shared/components/markdown/header.vue
'
;
import
ToolbarButton
from
'
~/vue_shared/components/markdown/toolbar_button.vue
'
;
describe
(
'
Markdown field header component
'
,
()
=>
{
let
vm
;
let
wrapper
;
beforeEach
(()
=>
{
const
Component
=
Vue
.
extend
(
headerComponent
);
vm
=
new
Component
({
const
createWrapper
=
props
=>
{
wrapper
=
shallowMount
(
HeaderComponent
,
{
propsData
:
{
previewMarkdown
:
false
,
...
props
,
},
}).
$mount
();
sync
:
false
,
attachToDocument
:
true
,
});
};
const
findToolbarButtons
=
()
=>
wrapper
.
findAll
(
ToolbarButton
);
const
findToolbarButtonByProp
=
(
prop
,
value
)
=>
findToolbarButtons
()
.
filter
(
button
=>
button
.
props
(
prop
)
===
value
)
.
at
(
0
);
beforeEach
(()
=>
{
createWrapper
();
});
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
});
it
(
'
renders markdown header buttons
'
,
()
=>
{
...
...
@@ -29,75 +46,72 @@ describe('Markdown field header component', () => {
'
Add a table
'
,
'
Go full screen
'
,
];
const
elements
=
vm
.
$el
.
querySelectorAll
(
'
.toolbar-btn
'
);
const
elements
=
findToolbarButtons
(
);
elements
.
forEach
((
buttonEl
,
index
)
=>
{
expect
(
buttonEl
.
getAttribute
(
'
data-original-t
itle
'
)).
toBe
(
buttons
[
index
]);
elements
.
wrappers
.
forEach
((
buttonEl
,
index
)
=>
{
expect
(
buttonEl
.
props
(
'
buttonT
itle
'
)).
toBe
(
buttons
[
index
]);
});
});
it
(
'
renders `write` link as active when previewMarkdown is false
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
li:nth-child(1)
'
).
classList
.
contains
(
'
active
'
)).
toBeTruthy
(
);
expect
(
wrapper
.
find
(
'
li:nth-child(1)
'
).
classes
()).
toContain
(
'
active
'
);
});
it
(
'
renders `preview` link as active when previewMarkdown is true
'
,
()
=>
{
vm
.
previewMarkdown
=
true
;
createWrapper
({
previewMarkdown
:
true
})
;
Vue
.
nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
li:nth-child(2)
'
).
classList
.
contains
(
'
active
'
)).
toBeTruthy
();
});
expect
(
wrapper
.
find
(
'
li:nth-child(2)
'
).
classes
()).
toContain
(
'
active
'
);
});
it
(
'
emits toggle markdown event when clicking preview
'
,
()
=>
{
jest
.
spyOn
(
vm
,
'
$emit
'
).
mockImplementation
();
vm
.
$el
.
querySelector
(
'
.js-preview-link
'
).
click
();
wrapper
.
find
(
'
.js-preview-link
'
).
trigger
(
'
click
'
);
expect
(
vm
.
$emit
).
toHaveBeenCalledWith
(
'
preview-markdown
'
);
expect
(
wrapper
.
emitted
(
'
preview-markdown
'
).
length
).
toEqual
(
1
);
vm
.
$el
.
querySelector
(
'
.js-write-link
'
).
click
(
);
wrapper
.
find
(
'
.js-write-link
'
).
trigger
(
'
click
'
);
expect
(
vm
.
$emit
).
toHaveBeenCalledWith
(
'
write-markdown
'
);
expect
(
wrapper
.
emitted
(
'
write-markdown
'
).
length
).
toEqual
(
1
);
});
it
(
'
does not emit toggle markdown event when triggered from another form
'
,
()
=>
{
jest
.
spyOn
(
vm
,
'
$emit
'
).
mockImplementation
();
$
(
document
).
triggerHandler
(
'
markdown-preview:show
'
,
[
$
(
'
<form><div class="js-vue-markdown-field"><textarea class="markdown-area"></textarea></div></form>
'
,
),
]);
expect
(
vm
.
$emit
).
not
.
toHaveBeenCalled
();
expect
(
wrapper
.
emitted
(
'
preview-markdown
'
)).
toBeFalsy
();
expect
(
wrapper
.
emitted
(
'
write-markdown
'
)).
toBeFalsy
();
});
it
(
'
blurs preview link after click
'
,
()
=>
{
const
link
=
vm
.
$el
.
querySelector
(
'
li:nth-child(2) button
'
);
const
link
=
wrapper
.
find
(
'
li:nth-child(2) button
'
);
jest
.
spyOn
(
HTMLElement
.
prototype
,
'
blur
'
).
mockImplementation
();
link
.
click
(
);
link
.
trigger
(
'
click
'
);
expect
(
link
.
blur
).
toHaveBeenCalled
();
expect
(
link
.
element
.
blur
).
toHaveBeenCalled
();
});
it
(
'
renders markdown table template
'
,
()
=>
{
expect
(
vm
.
mdTable
).
toEqual
(
const
tableButton
=
findToolbarButtonByProp
(
'
icon
'
,
'
table
'
);
expect
(
tableButton
.
props
(
'
tag
'
)).
toEqual
(
'
| header | header |
\n
| ------ | ------ |
\n
| cell | cell |
\n
| cell | cell |
'
,
);
});
it
(
'
renders suggestion template
'
,
()
=>
{
vm
.
lineContent
=
'
Some content
'
;
expect
(
vm
.
mdSuggestion
).
toEqual
(
'
```suggestion:-0+0
\n
{text}
\n
```
'
);
expect
(
findToolbarButtonByProp
(
'
buttonTitle
'
,
'
Insert suggestion
'
).
props
(
'
tag
'
)).
toEqual
(
'
```suggestion:-0+0
\n
{text}
\n
```
'
,
);
});
it
(
'
does not render suggestion button if `canSuggest` is set to false
'
,
()
=>
{
vm
.
canSuggest
=
false
;
Vue
.
nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.js-suggestion-btn
'
)).
toBe
(
null
);
createWrapper
({
canSuggest
:
false
,
});
expect
(
wrapper
.
find
(
'
.js-suggestion-btn
'
).
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