Welcome to mirror list, hosted at ThFree Co, Russian Federation.

init_gitlab_web_ide_spec.js « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec8559f1b563e19d12c11af775e1d5d39704e6ba (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
60
61
62
import { start } from '@gitlab/web-ide';
import { initGitlabWebIDE } from '~/ide/init_gitlab_web_ide';
import { TEST_HOST } from 'helpers/test_constants';

jest.mock('@gitlab/web-ide');

const ROOT_ELEMENT_ID = 'ide';
const TEST_NONCE = 'test123nonce';
const TEST_PROJECT = { path_with_namespace: 'group1/project1' };
const TEST_BRANCH_NAME = '12345-foo-patch';
const TEST_GITLAB_URL = 'https://test-gitlab/';
const TEST_GITLAB_WEB_IDE_PUBLIC_PATH = 'test/webpack/assets/gitlab-web-ide/public/path';

describe('ide/init_gitlab_web_ide', () => {
  const createRootElement = () => {
    const el = document.createElement('div');

    el.id = ROOT_ELEMENT_ID;
    // why: We'll test that this class is removed later
    el.classList.add('ide-loading');
    el.dataset.project = JSON.stringify(TEST_PROJECT);
    el.dataset.cspNonce = TEST_NONCE;
    el.dataset.branchName = TEST_BRANCH_NAME;

    document.body.append(el);
  };
  const findRootElement = () => document.getElementById(ROOT_ELEMENT_ID);
  const act = () => initGitlabWebIDE(findRootElement());

  beforeEach(() => {
    process.env.GITLAB_WEB_IDE_PUBLIC_PATH = TEST_GITLAB_WEB_IDE_PUBLIC_PATH;
    window.gon.gitlab_url = TEST_GITLAB_URL;

    createRootElement();

    act();
  });

  afterEach(() => {
    document.body.innerHTML = '';
  });

  it('calls start with element', () => {
    expect(start).toHaveBeenCalledWith(findRootElement(), {
      baseUrl: `${TEST_HOST}/${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}`,
      projectPath: TEST_PROJECT.path_with_namespace,
      ref: TEST_BRANCH_NAME,
      gitlabUrl: TEST_GITLAB_URL,
      nonce: TEST_NONCE,
    });
  });

  it('clears classes and data from root element', () => {
    const rootEl = findRootElement();

    // why: Snapshot to test that `ide-loading` was removed and no other
    //      artifacts are remaining.
    expect(rootEl.outerHTML).toBe(
      '<div id="ide" class="gl--flex-center gl-relative gl-h-full"></div>',
    );
  });
});