debian-mirror-gitlab/spec/javascripts/projects/project_new_spec.js

176 lines
5.2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-09-10 17:25:29 +05:30
import projectNew from '~/projects/project_new';
describe('New Project', () => {
let $projectImportUrl;
let $projectPath;
2018-11-20 20:47:30 +05:30
let $projectName;
2017-09-10 17:25:29 +05:30
beforeEach(() => {
setFixtures(`
2018-03-17 18:26:18 +05:30
<div class='toggle-import-form'>
<div class='import-url-data'>
2019-07-31 22:56:46 +05:30
<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-11-20 20:47:30 +05:30
<input id="project_name" />
2018-03-17 18:26:18 +05:30
<input id="project_path" />
</div>
</div>
2017-09-10 17:25:29 +05:30
`);
$projectImportUrl = $('#project_import_url');
$projectPath = $('#project_path');
2018-11-20 20:47:30 +05:30
$projectName = $('#project_name');
2017-09-10 17:25:29 +05:30
});
describe('deriveProjectPathFromUrl', () => {
const dummyImportUrl = `${gl.TEST_HOST}/dummy/import/url.git`;
beforeEach(() => {
projectNew.bindEvents();
2018-12-13 13:39:08 +05:30
$projectPath
.val('')
.keyup()
.val(dummyImportUrl);
2017-09-10 17:25:29 +05:30
});
it('does not change project path for disabled $projectImportUrl', () => {
2018-03-27 19:54:05 +05:30
$projectImportUrl.prop('disabled', true);
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual(dummyImportUrl);
});
describe('for enabled $projectImportUrl', () => {
beforeEach(() => {
2018-03-27 19:54:05 +05:30
$projectImportUrl.prop('disabled', false);
2017-09-10 17:25:29 +05:30
});
it('does not change project path if it is set by user', () => {
$projectPath.keyup();
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual(dummyImportUrl);
});
it('does not change project path for empty $projectImportUrl', () => {
$projectImportUrl.val('');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual(dummyImportUrl);
});
it('does not change project path for whitespace $projectImportUrl', () => {
$projectImportUrl.val(' ');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual(dummyImportUrl);
});
it('does not change project path for $projectImportUrl without slashes', () => {
$projectImportUrl.val('has-no-slash');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual(dummyImportUrl);
});
it('changes project path to last $projectImportUrl component', () => {
$projectImportUrl.val('/this/is/last');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('last');
});
it('ignores trailing slashes in $projectImportUrl', () => {
$projectImportUrl.val('/has/trailing/slash/');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('slash');
});
it('ignores fragment identifier in $projectImportUrl', () => {
$projectImportUrl.val('/this/has/a#fragment-identifier/');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('a');
});
it('ignores query string in $projectImportUrl', () => {
$projectImportUrl.val('/url/with?query=string');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('with');
});
it('ignores trailing .git in $projectImportUrl', () => {
$projectImportUrl.val('/repository.git');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('repository');
});
it('changes project path for HTTPS URL in $projectImportUrl', () => {
2019-07-31 22:56:46 +05:30
$projectImportUrl.val('https://gitlab.company.com/group/project.git');
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('project');
});
it('changes project path for SSH URL in $projectImportUrl', () => {
$projectImportUrl.val('git@gitlab.com:gitlab-org/gitlab-ce.git');
2018-03-17 18:26:18 +05:30
projectNew.deriveProjectPathFromUrl($projectImportUrl);
2017-09-10 17:25:29 +05:30
expect($projectPath.val()).toEqual('gitlab-ce');
});
});
});
2018-11-20 20:47:30 +05:30
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');
});
});
2017-09-10 17:25:29 +05:30
});