Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-28 21:09:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-28 21:09:07 +0300
commit1c8fa70f9d0818e2a82089c8643a6e455bca47fd (patch)
treef339f97de0425270bdd909e2f4d378927b6e0a18 /spec/frontend/behaviors
parent736d36d8597d0d1ec1b47644e6d091c3f4a78f45 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/behaviors')
-rw-r--r--spec/frontend/behaviors/quick_submit_spec.js153
1 files changed, 153 insertions, 0 deletions
diff --git a/spec/frontend/behaviors/quick_submit_spec.js b/spec/frontend/behaviors/quick_submit_spec.js
new file mode 100644
index 00000000000..2dc2bb198e8
--- /dev/null
+++ b/spec/frontend/behaviors/quick_submit_spec.js
@@ -0,0 +1,153 @@
+import $ from 'jquery';
+import '~/behaviors/quick_submit';
+
+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();
+ });
+ testContext.textarea = $('.js-quick-submit textarea').first();
+ });
+
+ it('does not respond to other keyCodes', () => {
+ testContext.textarea.trigger(
+ keydownEvent({
+ keyCode: 32,
+ }),
+ );
+
+ expect(testContext.spies.submit).not.toHaveBeenCalled();
+ });
+
+ it('does not respond to Enter alone', () => {
+ testContext.textarea.trigger(
+ keydownEvent({
+ ctrlKey: false,
+ metaKey: false,
+ }),
+ );
+
+ expect(testContext.spies.submit).not.toHaveBeenCalled();
+ });
+
+ it('does not respond to repeated events', () => {
+ testContext.textarea.trigger(
+ keydownEvent({
+ repeat: true,
+ }),
+ );
+
+ expect(testContext.spies.submit).not.toHaveBeenCalled();
+ });
+
+ it('disables input of type submit', () => {
+ const submitButton = $('.js-quick-submit input[type=submit]');
+ testContext.textarea.trigger(keydownEvent());
+
+ expect(submitButton).toBeDisabled();
+ });
+
+ it('disables button of type submit', () => {
+ const submitButton = $('.js-quick-submit input[type=submit]');
+ testContext.textarea.trigger(keydownEvent());
+
+ expect(submitButton).toBeDisabled();
+ });
+
+ it('only clicks one submit', () => {
+ const existingSubmit = $('.js-quick-submit input[type=submit]');
+ // Add an extra submit button
+ const newSubmit = $('<button type="submit">Submit it</button>');
+ newSubmit.insertAfter(testContext.textarea);
+
+ const spies = {
+ oldClickSpy: jest.fn(),
+ newClickSpy: jest.fn(),
+ };
+ existingSubmit.on('click', () => {
+ spies.oldClickSpy();
+ });
+ newSubmit.on('click', () => {
+ spies.newClickSpy();
+ });
+
+ testContext.textarea.trigger(keydownEvent());
+
+ expect(spies.oldClickSpy).not.toHaveBeenCalled();
+ expect(spies.newClickSpy).toHaveBeenCalled();
+ });
+ // 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', () => {
+ testContext.textarea.trigger(keydownEvent());
+
+ expect(testContext.spies.submit).toHaveBeenCalled();
+ });
+
+ it('excludes other modifier keys', () => {
+ testContext.textarea.trigger(
+ keydownEvent({
+ altKey: true,
+ }),
+ );
+ testContext.textarea.trigger(
+ keydownEvent({
+ ctrlKey: true,
+ }),
+ );
+ testContext.textarea.trigger(
+ keydownEvent({
+ shiftKey: true,
+ }),
+ );
+
+ expect(testContext.spies.submit).not.toHaveBeenCalled();
+ });
+ });
+ } else {
+ it('responds to Ctrl+Enter', () => {
+ testContext.textarea.trigger(keydownEvent());
+
+ expect(testContext.spies.submit).toHaveBeenCalled();
+ });
+
+ it('excludes other modifier keys', () => {
+ testContext.textarea.trigger(
+ keydownEvent({
+ altKey: true,
+ }),
+ );
+ testContext.textarea.trigger(
+ keydownEvent({
+ metaKey: true,
+ }),
+ );
+ testContext.textarea.trigger(
+ keydownEvent({
+ shiftKey: true,
+ }),
+ );
+
+ expect(testContext.spies.submit).not.toHaveBeenCalled();
+ });
+ }
+});