All files / app/assets/javascripts/projects project_import_gitlab_project.js

84.21% Statements 16/19
100% Branches 8/8
50% Functions 2/4
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45        1x 6x 6x     6x 1x       5x 1x     4x       6x 6x 6x 6x     6x     6x     6x           6x        
import { convertToTitleCase, humanize, slugify } from '../lib/utils/text_utility';
import { getParameterValues } from '../lib/utils/url_utility';
import projectNew from './project_new';
 
const prepareParameters = () => {
  const name = getParameterValues('name')[0];
  const path = getParameterValues('path')[0];
 
  // If the name param exists but the path doesn't then generate it from the name
  if (name && !path) {
    return { name, path: slugify(name) };
  }
 
  // If the path param exists but the name doesn't then generate it from the path
  if (path && !name) {
    return { name: convertToTitleCase(humanize(path, '-')), path };
  }
 
  return { name, path };
};
 
export default () => {
  let hasUserDefinedProjectName = false;
  const $projectName = document.querySelector('.js-project-name');
  const $projectPath = document.querySelector('.js-path-name');
  const { name, path } = prepareParameters();
 
  // get the project name from the URL and set it as input value
  $projectName.value = name;
 
  // get the path url and append it in the input
  $projectPath.value = path;
 
  // generate slug when project name changes
  $projectName.addEventListener('keyup', () => {
    projectNew.onProjectNameChange($projectName, $projectPath);
    hasUserDefinedProjectName = $projectName.value.trim().length > 0;
  });
 
  // generate project name from the slug if one isn't set
  $projectPath.addEventListener('keyup', () =>
    projectNew.onProjectPathChange($projectName, $projectPath, hasUserDefinedProjectName),
  );
};