diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-04-16 18:01:09 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2018-04-16 18:01:09 +0000 |
commit | 1cc633c8eca52fe794c9db0b1373023eb67666d7 (patch) | |
tree | 356936f8e70b50dfc0c33cb773a40a34f385fb6f | |
parent | d103a567d6a8802f6c78ff55de674a73c7a7ad0f (diff) | |
download | gitlab-ce-1cc633c8eca52fe794c9db0b1373023eb67666d7.tar.gz |
Adds helpers to remove withespace and linebreaks
5 files changed, 23 insertions, 7 deletions
diff --git a/spec/javascripts/helpers/vue_component_helper.js b/spec/javascripts/helpers/vue_component_helper.js index 257c9f5526a..e0fe18e5560 100644 --- a/spec/javascripts/helpers/vue_component_helper.js +++ b/spec/javascripts/helpers/vue_component_helper.js @@ -1,3 +1,18 @@ -export default function removeBreakLine (data) { - return data.replace(/\r?\n|\r/g, ' '); -} +/** + * Replaces line break with an empty space + * @param {*} data + */ +export const removeBreakLine = data => data.replace(/\r?\n|\r/g, ' '); + +/** + * Removes line breaks, spaces and trims the given text + * @param {String} str + * @returns {String} + */ +export const trimText = str => + str + .replace(/\r?\n|\r/g, '') + .replace(/\s\s+/g, ' ') + .trim(); + +export const removeWhitespace = str => str.replace(/\s\s+/g, ' '); diff --git a/spec/javascripts/ide/components/commit_sidebar/list_collapsed_spec.js b/spec/javascripts/ide/components/commit_sidebar/list_collapsed_spec.js index 5b402886b55..32dbc3bf72e 100644 --- a/spec/javascripts/ide/components/commit_sidebar/list_collapsed_spec.js +++ b/spec/javascripts/ide/components/commit_sidebar/list_collapsed_spec.js @@ -3,6 +3,7 @@ import store from '~/ide/stores'; import listCollapsed from '~/ide/components/commit_sidebar/list_collapsed.vue'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { file } from '../../helpers'; +import { removeWhitespace } from '../../../helpers/vue_component_helper'; describe('Multi-file editor commit sidebar list collapsed', () => { let vm; @@ -23,6 +24,6 @@ describe('Multi-file editor commit sidebar list collapsed', () => { }); it('renders added & modified files count', () => { - expect(vm.$el.textContent.replace(/\s+/g, ' ').trim()).toBe('1 1'); + expect(removeWhitespace(vm.$el.textContent).trim()).toBe('1 1'); }); }); diff --git a/spec/javascripts/vue_mr_widget/components/states/mr_widget_conflicts_spec.js b/spec/javascripts/vue_mr_widget/components/states/mr_widget_conflicts_spec.js index fcbd8169bc7..3d05dbfa305 100644 --- a/spec/javascripts/vue_mr_widget/components/states/mr_widget_conflicts_spec.js +++ b/spec/javascripts/vue_mr_widget/components/states/mr_widget_conflicts_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import conflictsComponent from '~/vue_merge_request_widget/components/states/mr_widget_conflicts.vue'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import removeBreakLine from 'spec/helpers/vue_component_helper'; +import { removeBreakLine } from 'spec/helpers/vue_component_helper'; describe('MRWidgetConflicts', () => { let Component; diff --git a/spec/javascripts/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js b/spec/javascripts/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js index 894dbe3382f..ab096a56918 100644 --- a/spec/javascripts/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js +++ b/spec/javascripts/vue_mr_widget/components/states/mr_widget_pipeline_blocked_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import pipelineBlockedComponent from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_blocked.vue'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import removeBreakLine from 'spec/helpers/vue_component_helper'; +import { removeBreakLine } from 'spec/helpers/vue_component_helper'; describe('MRWidgetPipelineBlocked', () => { let vm; diff --git a/spec/javascripts/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js b/spec/javascripts/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js index b02af94d03a..abf642c166a 100644 --- a/spec/javascripts/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js +++ b/spec/javascripts/vue_mr_widget/components/states/mr_widget_sha_mismatch_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import ShaMismatch from '~/vue_merge_request_widget/components/states/sha_mismatch.vue'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import removeBreakLine from 'spec/helpers/vue_component_helper'; +import { removeBreakLine } from 'spec/helpers/vue_component_helper'; describe('ShaMismatch', () => { let vm; |