2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2021-01-15 00:10:45 +00:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2020-08-17 21:09:56 +00:00
|
|
|
import projectNew from '~/projects/project_new';
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
describe('New Project', () => {
|
|
|
|
let $projectImportUrl;
|
|
|
|
let $projectPath;
|
2018-09-08 06:03:00 +00:00
|
|
|
let $projectName;
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
2017-12-22 18:25:24 +00:00
|
|
|
<div class='toggle-import-form'>
|
|
|
|
<div class='import-url-data'>
|
2019-04-13 16:00:10 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<input id="project_import_url" />
|
|
|
|
</div>
|
|
|
|
<div id="import-url-auth-method">
|
|
|
|
<div class="form-group">
|
|
|
|
<input id="project-import-url-user" />
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<input id="project_import_url_password" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-09-08 06:03:00 +00:00
|
|
|
<input id="project_name" />
|
2017-12-22 18:25:24 +00:00
|
|
|
<input id="project_path" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-01 18:06:06 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
$projectImportUrl = $('#project_import_url');
|
|
|
|
$projectPath = $('#project_path');
|
2018-09-08 06:03:00 +00:00
|
|
|
$projectName = $('#project_name');
|
2017-08-01 18:06:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('deriveProjectPathFromUrl', () => {
|
2020-07-16 03:09:12 +00:00
|
|
|
const dummyImportUrl = `${TEST_HOST}/dummy/import/url.git`;
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
projectNew.bindEvents();
|
2020-12-23 12:10:26 +00:00
|
|
|
$projectPath.val('').keyup().val(dummyImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change project path for disabled $projectImportUrl', () => {
|
2018-02-20 22:20:48 +00:00
|
|
|
$projectImportUrl.prop('disabled', true);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual(dummyImportUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for enabled $projectImportUrl', () => {
|
|
|
|
beforeEach(() => {
|
2018-02-20 22:20:48 +00:00
|
|
|
$projectImportUrl.prop('disabled', false);
|
2017-08-01 18:06:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change project path if it is set by user', () => {
|
|
|
|
$projectPath.keyup();
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual(dummyImportUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change project path for empty $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual(dummyImportUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change project path for whitespace $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val(' ');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual(dummyImportUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change project path for $projectImportUrl without slashes', () => {
|
|
|
|
$projectImportUrl.val('has-no-slash');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual(dummyImportUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('changes project path to last $projectImportUrl component', () => {
|
|
|
|
$projectImportUrl.val('/this/is/last');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('last');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores trailing slashes in $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('/has/trailing/slash/');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('slash');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores fragment identifier in $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('/this/has/a#fragment-identifier/');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('a');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores query string in $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('/url/with?query=string');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('with');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ignores trailing .git in $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('/repository.git');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('repository');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('changes project path for HTTPS URL in $projectImportUrl', () => {
|
2019-04-13 16:00:10 +00:00
|
|
|
$projectImportUrl.val('https://gitlab.company.com/group/project.git');
|
2017-08-01 18:06:06 +00:00
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('project');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('changes project path for SSH URL in $projectImportUrl', () => {
|
|
|
|
$projectImportUrl.val('git@gitlab.com:gitlab-org/gitlab-ce.git');
|
|
|
|
|
2017-12-22 18:25:24 +00:00
|
|
|
projectNew.deriveProjectPathFromUrl($projectImportUrl);
|
2017-08-01 18:06:06 +00:00
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('gitlab-ce');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-08 06:03:00 +00:00
|
|
|
|
|
|
|
describe('deriveSlugFromProjectName', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
projectNew.bindEvents();
|
|
|
|
$projectName.val('').keyup();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts project name to lower case and dash-limited slug', () => {
|
|
|
|
const dummyProjectName = 'My Awesome Project';
|
|
|
|
|
|
|
|
$projectName.val(dummyProjectName);
|
|
|
|
|
|
|
|
projectNew.onProjectNameChange($projectName, $projectPath);
|
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('my-awesome-project');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add additional dashes in the slug if the project name already contains dashes', () => {
|
|
|
|
const dummyProjectName = 'My-Dash-Delimited Awesome Project';
|
|
|
|
|
|
|
|
$projectName.val(dummyProjectName);
|
|
|
|
|
|
|
|
projectNew.onProjectNameChange($projectName, $projectPath);
|
|
|
|
|
|
|
|
expect($projectPath.val()).toEqual('my-dash-delimited-awesome-project');
|
|
|
|
});
|
|
|
|
});
|
2020-01-17 21:08:29 +00:00
|
|
|
|
|
|
|
describe('derivesProjectNameFromSlug', () => {
|
|
|
|
const dummyProjectPath = 'my-awesome-project';
|
|
|
|
const dummyProjectName = 'Original Awesome Project';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
projectNew.bindEvents();
|
|
|
|
$projectPath.val('').change();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts slug to humanized project name', () => {
|
|
|
|
$projectPath.val(dummyProjectPath);
|
|
|
|
|
|
|
|
projectNew.onProjectPathChange($projectName, $projectPath);
|
|
|
|
|
|
|
|
expect($projectName.val()).toEqual('My Awesome Project');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not convert slug to humanized project name if a project name already exists', () => {
|
|
|
|
$projectName.val(dummyProjectName);
|
|
|
|
$projectPath.val(dummyProjectPath);
|
|
|
|
projectNew.onProjectPathChange(
|
|
|
|
$projectName,
|
|
|
|
$projectPath,
|
|
|
|
$projectName.val().trim().length > 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect($projectName.val()).toEqual(dummyProjectName);
|
|
|
|
});
|
|
|
|
});
|
2017-08-01 18:06:06 +00:00
|
|
|
});
|