diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 21:09:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 21:09:28 +0300 |
commit | ce8a0b90849ac5d1895e741c023432930f24d724 (patch) | |
tree | dbdc97de542cdbe18a2fc8b1a6b64ac0673ed3d3 /spec/frontend | |
parent | dc889678d1de8c09310b2f8f9742bb6c78a6f1a4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/projects/project_import_gitlab_project_spec.js | 59 | ||||
-rw-r--r-- | spec/frontend/projects/project_new_spec.js | 205 |
2 files changed, 264 insertions, 0 deletions
diff --git a/spec/frontend/projects/project_import_gitlab_project_spec.js b/spec/frontend/projects/project_import_gitlab_project_spec.js new file mode 100644 index 00000000000..3c94934699d --- /dev/null +++ b/spec/frontend/projects/project_import_gitlab_project_spec.js @@ -0,0 +1,59 @@ +import projectImportGitlab from '~/projects/project_import_gitlab_project'; + +describe('Import Gitlab project', () => { + const pathName = 'my-project'; + const projectName = 'My Project'; + + const setTestFixtures = url => { + window.history.pushState({}, null, url); + + setFixtures(` + <input class="js-path-name" /> + <input class="js-project-name" /> + `); + + projectImportGitlab(); + }; + + beforeEach(() => { + setTestFixtures(`?name=${projectName}&path=${pathName}`); + }); + + afterEach(() => { + window.history.pushState({}, null, ''); + }); + + describe('project name', () => { + it('should fill in the project name derived from the previously filled project name', () => { + expect(document.querySelector('.js-project-name').value).toEqual(projectName); + }); + + describe('empty path name', () => { + it('derives the path name from the previously filled project name', () => { + const alternateProjectName = 'My Alt Project'; + const alternatePathName = 'my-alt-project'; + + setTestFixtures(`?name=${alternateProjectName}`); + + expect(document.querySelector('.js-path-name').value).toEqual(alternatePathName); + }); + }); + }); + + describe('path name', () => { + it('should fill in the path name derived from the previously filled path name', () => { + expect(document.querySelector('.js-path-name').value).toEqual(pathName); + }); + + describe('empty project name', () => { + it('derives the project name from the previously filled path name', () => { + const alternateProjectName = 'My Alt Project'; + const alternatePathName = 'my-alt-project'; + + setTestFixtures(`?path=${alternatePathName}`); + + expect(document.querySelector('.js-project-name').value).toEqual(alternateProjectName); + }); + }); + }); +}); diff --git a/spec/frontend/projects/project_new_spec.js b/spec/frontend/projects/project_new_spec.js new file mode 100644 index 00000000000..7c6ff90aff6 --- /dev/null +++ b/spec/frontend/projects/project_new_spec.js @@ -0,0 +1,205 @@ +import $ from 'jquery'; +import projectNew from '~/projects/project_new'; + +describe('New Project', () => { + let $projectImportUrl; + let $projectPath; + let $projectName; + + beforeEach(() => { + setFixtures(` + <div class='toggle-import-form'> + <div class='import-url-data'> + <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> + <input id="project_name" /> + <input id="project_path" /> + </div> + </div> + `); + + $projectImportUrl = $('#project_import_url'); + $projectPath = $('#project_path'); + $projectName = $('#project_name'); + }); + + describe('deriveProjectPathFromUrl', () => { + const dummyImportUrl = `${gl.TEST_HOST}/dummy/import/url.git`; + + beforeEach(() => { + projectNew.bindEvents(); + $projectPath + .val('') + .keyup() + .val(dummyImportUrl); + }); + + it('does not change project path for disabled $projectImportUrl', () => { + $projectImportUrl.prop('disabled', true); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual(dummyImportUrl); + }); + + describe('for enabled $projectImportUrl', () => { + beforeEach(() => { + $projectImportUrl.prop('disabled', false); + }); + + it('does not change project path if it is set by user', () => { + $projectPath.keyup(); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual(dummyImportUrl); + }); + + it('does not change project path for empty $projectImportUrl', () => { + $projectImportUrl.val(''); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual(dummyImportUrl); + }); + + it('does not change project path for whitespace $projectImportUrl', () => { + $projectImportUrl.val(' '); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual(dummyImportUrl); + }); + + it('does not change project path for $projectImportUrl without slashes', () => { + $projectImportUrl.val('has-no-slash'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual(dummyImportUrl); + }); + + it('changes project path to last $projectImportUrl component', () => { + $projectImportUrl.val('/this/is/last'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('last'); + }); + + it('ignores trailing slashes in $projectImportUrl', () => { + $projectImportUrl.val('/has/trailing/slash/'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('slash'); + }); + + it('ignores fragment identifier in $projectImportUrl', () => { + $projectImportUrl.val('/this/has/a#fragment-identifier/'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('a'); + }); + + it('ignores query string in $projectImportUrl', () => { + $projectImportUrl.val('/url/with?query=string'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('with'); + }); + + it('ignores trailing .git in $projectImportUrl', () => { + $projectImportUrl.val('/repository.git'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('repository'); + }); + + it('changes project path for HTTPS URL in $projectImportUrl', () => { + $projectImportUrl.val('https://gitlab.company.com/group/project.git'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('project'); + }); + + it('changes project path for SSH URL in $projectImportUrl', () => { + $projectImportUrl.val('git@gitlab.com:gitlab-org/gitlab-ce.git'); + + projectNew.deriveProjectPathFromUrl($projectImportUrl); + + expect($projectPath.val()).toEqual('gitlab-ce'); + }); + }); + }); + + 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'); + }); + }); + + 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); + }); + }); +}); |