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
$
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
'
,
()
=>
{
describe
(
'
Markdown field header component
'
,
()
=>
{
let
vm
;
let
wrapper
;
beforeEach
(()
=>
{
const
createWrapper
=
props
=>
{
const
Component
=
Vue
.
extend
(
headerComponent
);
wrapper
=
shallowMount
(
HeaderComponent
,
{
vm
=
new
Component
({
propsData
:
{
propsData
:
{
previewMarkdown
:
false
,
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
'
,
()
=>
{
it
(
'
renders markdown header buttons
'
,
()
=>
{
...
@@ -29,75 +46,72 @@ describe('Markdown field header component', () => {
...
@@ -29,75 +46,72 @@ describe('Markdown field header component', () => {
'
Add a table
'
,
'
Add a table
'
,
'
Go full screen
'
,
'
Go full screen
'
,
];
];
const
elements
=
vm
.
$el
.
querySelectorAll
(
'
.toolbar-btn
'
);
const
elements
=
findToolbarButtons
(
);
elements
.
forEach
((
buttonEl
,
index
)
=>
{
elements
.
wrappers
.
forEach
((
buttonEl
,
index
)
=>
{
expect
(
buttonEl
.
getAttribute
(
'
data-original-t
itle
'
)).
toBe
(
buttons
[
index
]);
expect
(
buttonEl
.
props
(
'
buttonT
itle
'
)).
toBe
(
buttons
[
index
]);
});
});
});
});
it
(
'
renders `write` link as active when previewMarkdown is false
'
,
()
=>
{
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
'
,
()
=>
{
it
(
'
renders `preview` link as active when previewMarkdown is true
'
,
()
=>
{
vm
.
previewMarkdown
=
true
;
createWrapper
({
previewMarkdown
:
true
})
;
Vue
.
nextTick
(()
=>
{
expect
(
wrapper
.
find
(
'
li:nth-child(2)
'
).
classes
()).
toContain
(
'
active
'
);
expect
(
vm
.
$el
.
querySelector
(
'
li:nth-child(2)
'
).
classList
.
contains
(
'
active
'
)).
toBeTruthy
();
});
});
});
it
(
'
emits toggle markdown event when clicking preview
'
,
()
=>
{
it
(
'
emits toggle markdown event when clicking preview
'
,
()
=>
{
jest
.
spyOn
(
vm
,
'
$emit
'
).
mockImplementation
();
wrapper
.
find
(
'
.js-preview-link
'
).
trigger
(
'
click
'
);
vm
.
$el
.
querySelector
(
'
.js-preview-link
'
).
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
'
,
()
=>
{
it
(
'
does not emit toggle markdown event when triggered from another form
'
,
()
=>
{
jest
.
spyOn
(
vm
,
'
$emit
'
).
mockImplementation
();
$
(
document
).
triggerHandler
(
'
markdown-preview:show
'
,
[
$
(
document
).
triggerHandler
(
'
markdown-preview:show
'
,
[
$
(
$
(
'
<form><div class="js-vue-markdown-field"><textarea class="markdown-area"></textarea></div></form>
'
,
'
<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
'
,
()
=>
{
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
();
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
'
,
()
=>
{
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 |
'
,
'
| header | header |
\n
| ------ | ------ |
\n
| cell | cell |
\n
| cell | cell |
'
,
);
);
});
});
it
(
'
renders suggestion template
'
,
()
=>
{
it
(
'
renders suggestion template
'
,
()
=>
{
vm
.
lineContent
=
'
Some content
'
;
expect
(
findToolbarButtonByProp
(
'
buttonTitle
'
,
'
Insert suggestion
'
).
props
(
'
tag
'
)).
toEqual
(
'
```suggestion:-0+0
\n
{text}
\n
```
'
,
expect
(
vm
.
mdSuggestion
).
toEqual
(
'
```suggestion:-0+0
\n
{text}
\n
```
'
);
);
});
});
it
(
'
does not render suggestion button if `canSuggest` is set to false
'
,
()
=>
{
it
(
'
does not render suggestion button if `canSuggest` is set to false
'
,
()
=>
{
vm
.
canSuggest
=
false
;
createWrapper
({
canSuggest
:
false
,
Vue
.
nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.js-suggestion-btn
'
)).
toBe
(
null
);
});
});
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