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
572ffacd
Commit
572ffacd
authored
Feb 28, 2020
by
Roman Kuba
Committed by
Paul Slaughter
Feb 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ported existing spec from karma to jest
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25934
parent
80f584a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
37 deletions
+47
-37
spec/frontend/behaviors/quick_submit_spec.js
spec/frontend/behaviors/quick_submit_spec.js
+47
-37
No files found.
spec/
javascripts
/behaviors/quick_submit_spec.js
→
spec/
frontend
/behaviors/quick_submit_spec.js
View file @
572ffacd
import
$
from
'
jquery
'
;
import
'
~/behaviors/quick_submit
'
;
describe
(
'
Quick Submit behavior
'
,
function
()
{
describe
(
'
Quick Submit behavior
'
,
()
=>
{
let
testContext
;
const
keydownEvent
=
(
options
=
{
keyCode
:
13
,
metaKey
:
true
})
=>
$
.
Event
(
'
keydown
'
,
options
);
preloadFixtures
(
'
snippets/show.html
'
);
beforeEach
(()
=>
{
loadFixtures
(
'
snippets/show.html
'
);
testContext
=
{};
testContext
.
spies
=
{
submit
:
jest
.
fn
(),
};
$
(
'
form
'
).
submit
(
e
=>
{
// Prevent a form submit from moving us off the testing page
e
.
preventDefault
();
// Explicitly call the spie to know this function get's not called
testContext
.
spies
.
submit
();
});
this
.
spies
=
{
submit
:
spyOnEvent
(
'
form
'
,
'
submit
'
),
};
this
.
textarea
=
$
(
'
.js-quick-submit textarea
'
).
first
();
});
afterEach
(()
=>
{
// Undo what we did to the shared <body>
$
(
'
body
'
).
removeAttr
(
'
data-page
'
);
testContext
.
textarea
=
$
(
'
.js-quick-submit textarea
'
).
first
();
});
it
(
'
does not respond to other keyCodes
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
keyCode
:
32
,
}),
);
expect
(
t
his
.
spies
.
submit
).
not
.
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
not
.
toHaveBeenCall
ed
();
});
it
(
'
does not respond to Enter alone
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
ctrlKey
:
false
,
metaKey
:
false
,
}),
);
expect
(
t
his
.
spies
.
submit
).
not
.
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
not
.
toHaveBeenCall
ed
();
});
it
(
'
does not respond to repeated events
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
repeat
:
true
,
}),
);
expect
(
t
his
.
spies
.
submit
).
not
.
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
not
.
toHaveBeenCall
ed
();
});
it
(
'
disables input of type submit
'
,
()
=>
{
const
submitButton
=
$
(
'
.js-quick-submit input[type=submit]
'
);
t
his
.
textarea
.
trigger
(
keydownEvent
());
t
estContext
.
textarea
.
trigger
(
keydownEvent
());
expect
(
submitButton
).
toBeDisabled
();
});
it
(
'
disables button of type submit
'
,
()
=>
{
const
submitButton
=
$
(
'
.js-quick-submit input[type=submit]
'
);
t
his
.
textarea
.
trigger
(
keydownEvent
());
t
estContext
.
textarea
.
trigger
(
keydownEvent
());
expect
(
submitButton
).
toBeDisabled
();
});
...
...
@@ -73,71 +75,79 @@ describe('Quick Submit behavior', function() {
const
existingSubmit
=
$
(
'
.js-quick-submit input[type=submit]
'
);
// Add an extra submit button
const
newSubmit
=
$
(
'
<button type="submit">Submit it</button>
'
);
newSubmit
.
insertAfter
(
t
his
.
textarea
);
newSubmit
.
insertAfter
(
t
estContext
.
textarea
);
const
oldClick
=
spyOnEvent
(
existingSubmit
,
'
click
'
);
const
newClick
=
spyOnEvent
(
newSubmit
,
'
click
'
);
const
spies
=
{
oldClickSpy
:
jest
.
fn
(),
newClickSpy
:
jest
.
fn
(),
};
existingSubmit
.
on
(
'
click
'
,
()
=>
{
spies
.
oldClickSpy
();
});
newSubmit
.
on
(
'
click
'
,
()
=>
{
spies
.
newClickSpy
();
});
t
his
.
textarea
.
trigger
(
keydownEvent
());
t
estContext
.
textarea
.
trigger
(
keydownEvent
());
expect
(
oldClick
).
not
.
toHaveBeenTrigger
ed
();
expect
(
newClick
).
toHaveBeenTrigger
ed
();
expect
(
spies
.
oldClickSpy
).
not
.
toHaveBeenCall
ed
();
expect
(
spies
.
newClickSpy
).
toHaveBeenCall
ed
();
});
// We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
// only run the tests that apply to the current platform
if
(
navigator
.
userAgent
.
match
(
/Macintosh/
))
{
describe
(
'
In Macintosh
'
,
()
=>
{
it
(
'
responds to Meta+Enter
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
keydownEvent
());
t
estContext
.
textarea
.
trigger
(
keydownEvent
());
expect
(
t
his
.
spies
.
submit
).
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
toHaveBeenCall
ed
();
});
it
(
'
excludes other modifier keys
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
altKey
:
true
,
}),
);
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
ctrlKey
:
true
,
}),
);
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
shiftKey
:
true
,
}),
);
expect
(
t
his
.
spies
.
submit
).
not
.
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
not
.
toHaveBeenCall
ed
();
});
});
}
else
{
it
(
'
responds to Ctrl+Enter
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
keydownEvent
());
t
estContext
.
textarea
.
trigger
(
keydownEvent
());
expect
(
t
his
.
spies
.
submit
).
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
toHaveBeenCall
ed
();
});
it
(
'
excludes other modifier keys
'
,
()
=>
{
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
altKey
:
true
,
}),
);
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
metaKey
:
true
,
}),
);
t
his
.
textarea
.
trigger
(
t
estContext
.
textarea
.
trigger
(
keydownEvent
({
shiftKey
:
true
,
}),
);
expect
(
t
his
.
spies
.
submit
).
not
.
toHaveBeenTrigger
ed
();
expect
(
t
estContext
.
spies
.
submit
).
not
.
toHaveBeenCall
ed
();
});
}
});
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