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
3008e995
Commit
3008e995
authored
Aug 10, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes broken tests of quick_submit_spec and reduces tech debt
parent
f67ff8e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
99 deletions
+90
-99
quick_submit_spec.js
spec/javascripts/behaviors/quick_submit_spec.js
+90
-99
No files found.
spec/javascripts/behaviors/quick_submit_spec.js
View file @
3008e995
/* eslint-disable space-before-function-paren, no-var, no-return-assign, comma-dangle, jasmine/no-spec-dupes, new-cap, max-len */
import
'~/behaviors/quick_submit'
;
import
'~/behaviors/quick_submit'
;
(
function
()
{
describe
(
'Quick Submit behavior'
,
()
=>
{
describe
(
'Quick Submit behavior'
,
function
()
{
const
keydownEvent
=
(
options
=
{
keyCode
:
13
,
metaKey
:
true
})
=>
$
.
Event
(
'keydown'
,
options
);
var
keydownEvent
;
preloadFixtures
(
'issues/open-issue.html.raw'
);
beforeEach
(
function
()
{
loadFixtures
(
'issues/open-issue.html.raw'
);
$
(
'form'
).
submit
(
function
(
e
)
{
// Prevent a form submit from moving us off the testing page
return
e
.
preventDefault
();
});
this
.
spies
=
{
submit
:
spyOnEvent
(
'form'
,
'submit'
)
};
this
.
textarea
=
$
(
'.js-quick-submit textarea'
).
first
();
preloadFixtures
(
'merge_requests/merge_request_with_task_list.html.raw'
);
});
it
(
'does not respond to other keyCodes'
,
function
()
{
this
.
textarea
.
trigger
(
keydownEvent
({
keyCode
:
32
}));
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
it
(
'does not respond to Enter alone'
,
function
()
{
this
.
textarea
.
trigger
(
keydownEvent
({
ctrlKey
:
false
,
metaKey
:
false
}));
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
it
(
'does not respond to repeated events'
,
function
()
{
this
.
textarea
.
trigger
(
keydownEvent
({
repeat
:
true
}));
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
it
(
'disables input of type submit'
,
function
()
{
const
submitButton
=
$
(
'.js-quick-submit input[type=submit]'
);
this
.
textarea
.
trigger
(
keydownEvent
());
expect
(
submitButton
).
toBeDisabled
();
beforeEach
(()
=>
{
loadFixtures
(
'merge_requests/merge_request_with_task_list.html.raw'
);
$
(
'form'
).
submit
((
e
)
=>
{
// Prevent a form submit from moving us off the testing page
e
.
preventDefault
();
});
});
it
(
'disables button of type submit'
,
function
()
{
this
.
spies
=
{
const
submitButton
=
$
(
'.js-quick-submit input[type=submit]'
);
submit
:
spyOnEvent
(
'form'
,
'submit'
),
this
.
textarea
.
trigger
(
keydownEvent
())
;
}
;
expect
(
submitButton
).
toBeDisabled
();
this
.
textarea
=
$
(
'.js-quick-submit textarea'
).
first
();
});
});
it
(
'only clicks one submit'
,
function
()
{
const
existingSubmit
=
$
(
'.js-quick-submit input[type=submit]'
);
// Add an extra submit button
const
newSubmit
=
$
(
'<button type="submit">Submit it</button>'
);
newSubmit
.
insertAfter
(
this
.
textarea
);
const
oldClick
=
spyOnEvent
(
existingSubmit
,
'click'
);
it
(
'does not respond to other keyCodes'
,
()
=>
{
const
newClick
=
spyOnEvent
(
newSubmit
,
'click'
);
this
.
textarea
.
trigger
(
keydownEvent
({
keyCode
:
32
,
}));
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
this
.
textarea
.
trigger
(
keydownEvent
());
it
(
'does not respond to Enter alone'
,
()
=>
{
this
.
textarea
.
trigger
(
keydownEvent
({
ctrlKey
:
false
,
metaKey
:
false
,
}));
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
expect
(
oldClick
).
not
.
toHaveBeenTriggered
();
it
(
'does not respond to repeated events'
,
()
=>
{
expect
(
newClick
).
toHaveBeenTriggered
();
this
.
textarea
.
trigger
(
keydownEvent
({
});
repeat
:
true
,
// We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
}));
// only run the tests that apply to the current platform
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
if
(
navigator
.
userAgent
.
match
(
/Macintosh/
))
{
});
it
(
'responds to Meta+Enter'
,
function
()
{
this
.
textarea
.
trigger
(
keydownEvent
());
it
(
'disables input of type submit'
,
()
=>
{
return
expect
(
this
.
spies
.
submit
).
toHaveBeenTriggered
();
const
submitButton
=
$
(
'.js-quick-submit input[type=submit]'
);
});
this
.
textarea
.
trigger
(
keydownEvent
());
it
(
'excludes other modifier keys'
,
function
()
{
this
.
textarea
.
trigger
(
keydownEvent
({
expect
(
submitButton
).
toBeDisabled
();
altKey
:
true
});
}));
it
(
'disables button of type submit'
,
()
=>
{
this
.
textarea
.
trigger
(
keydownEvent
({
const
submitButton
=
$
(
'.js-quick-submit input[type=submit]'
);
ctrlKey
:
true
this
.
textarea
.
trigger
(
keydownEvent
());
}));
this
.
textarea
.
trigger
(
keydownEvent
({
expect
(
submitButton
).
toBeDisabled
();
shiftKey
:
true
});
}));
it
(
'only clicks one submit'
,
()
=>
{
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
const
existingSubmit
=
$
(
'.js-quick-submit input[type=submit]'
);
});
// Add an extra submit button
}
else
{
const
newSubmit
=
$
(
'<button type="submit">Submit it</button>'
);
it
(
'responds to Ctrl+Enter'
,
function
()
{
newSubmit
.
insertAfter
(
this
.
textarea
);
const
oldClick
=
spyOnEvent
(
existingSubmit
,
'click'
);
const
newClick
=
spyOnEvent
(
newSubmit
,
'click'
);
this
.
textarea
.
trigger
(
keydownEvent
());
expect
(
oldClick
).
not
.
toHaveBeenTriggered
();
expect
(
newClick
).
toHaveBeenTriggered
();
});
// 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'
,
()
=>
{
this
.
textarea
.
trigger
(
keydownEvent
());
this
.
textarea
.
trigger
(
keydownEvent
());
return
expect
(
this
.
spies
.
submit
).
toHaveBeenTriggered
();
return
expect
(
this
.
spies
.
submit
).
toHaveBeenTriggered
();
});
});
it
(
'excludes other modifier keys'
,
function
()
{
it
(
'excludes other modifier keys'
,
()
=>
{
this
.
textarea
.
trigger
(
keydownEvent
({
this
.
textarea
.
trigger
(
keydownEvent
({
altKey
:
true
altKey
:
true
,
}));
}));
this
.
textarea
.
trigger
(
keydownEvent
({
this
.
textarea
.
trigger
(
keydownEvent
({
metaKey
:
true
ctrlKey
:
true
,
}));
}));
this
.
textarea
.
trigger
(
keydownEvent
({
this
.
textarea
.
trigger
(
keydownEvent
({
shiftKey
:
true
shiftKey
:
true
,
}));
}));
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
});
}
});
return
keydownEvent
=
function
(
options
)
{
}
else
{
var
defaults
;
it
(
'responds to Ctrl+Enter'
,
()
=>
{
if
(
navigator
.
userAgent
.
match
(
/Macintosh/
))
{
this
.
textarea
.
trigger
(
keydownEvent
());
defaults
=
{
return
expect
(
this
.
spies
.
submit
).
toHaveBeenTriggered
();
keyCode
:
13
,
});
metaKey
:
true
};
it
(
'excludes other modifier keys'
,
()
=>
{
}
else
{
this
.
textarea
.
trigger
(
keydownEvent
({
defaults
=
{
altKey
:
true
,
keyCode
:
13
,
}));
ctrlKey
:
true
this
.
textarea
.
trigger
(
keydownEvent
({
};
metaKey
:
true
,
}
}));
return
$
.
Event
(
'keydown'
,
$
.
extend
({},
defaults
,
options
));
this
.
textarea
.
trigger
(
keydownEvent
({
};
shiftKey
:
true
,
});
}));
}).
call
(
window
);
return
expect
(
this
.
spies
.
submit
).
not
.
toHaveBeenTriggered
();
});
}
});
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