summaryrefslogtreecommitdiff
path: root/spec/frontend/projects/project_import_gitlab_project_spec.js
blob: aaf8a81f626b04994bf5ba399e7e374d4f8a9341 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
      });
    });
  });
});