diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-06 00:08:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-06 00:08:33 +0300 |
commit | 9dc655286f773d1e9efef83df7fb53241d720ee3 (patch) | |
tree | 0feb8894389fef71de019f654f2e40f15d2aac58 /spec/frontend/ide | |
parent | 04af78083ec8cfabc6bba6604855b1c7c4de04f2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide')
3 files changed, 57 insertions, 3 deletions
diff --git a/spec/frontend/ide/init_gitlab_web_ide_spec.js b/spec/frontend/ide/init_gitlab_web_ide_spec.js index 067da25cb52..ae4d8d6d947 100644 --- a/spec/frontend/ide/init_gitlab_web_ide_spec.js +++ b/spec/frontend/ide/init_gitlab_web_ide_spec.js @@ -17,7 +17,7 @@ describe('ide/init_gitlab_web_ide', () => { el.id = ROOT_ELEMENT_ID; // why: We'll test that this class is removed later - el.classList.add('ide-loading'); + el.classList.add('test-class'); el.dataset.projectPath = TEST_PROJECT_PATH; el.dataset.cspNonce = TEST_NONCE; el.dataset.branchName = TEST_BRANCH_NAME; @@ -41,6 +41,7 @@ describe('ide/init_gitlab_web_ide', () => { }); it('calls start with element', () => { + expect(start).toHaveBeenCalledTimes(1); expect(start).toHaveBeenCalledWith(findRootElement(), { baseUrl: `${TEST_HOST}/${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}`, projectPath: TEST_PROJECT_PATH, @@ -53,8 +54,7 @@ describe('ide/init_gitlab_web_ide', () => { 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. + // why: Snapshot to test that the element was cleaned including `test-class` expect(rootEl.outerHTML).toBe( '<div id="ide" class="gl--flex-center gl-relative gl-h-full"></div>', ); diff --git a/spec/frontend/ide/lib/gitlab_web_ide/get_base_config_spec.js b/spec/frontend/ide/lib/gitlab_web_ide/get_base_config_spec.js new file mode 100644 index 00000000000..4b4e96f3b41 --- /dev/null +++ b/spec/frontend/ide/lib/gitlab_web_ide/get_base_config_spec.js @@ -0,0 +1,22 @@ +import { getBaseConfig } from '~/ide/lib/gitlab_web_ide/get_base_config'; +import { TEST_HOST } from 'helpers/test_constants'; + +const TEST_GITLAB_WEB_IDE_PUBLIC_PATH = 'test/gitlab-web-ide/public/path'; +const TEST_GITLAB_URL = 'https://gdk.test/'; + +describe('~/ide/lib/gitlab_web_ide/get_base_config', () => { + it('returns base properties for @gitlab/web-ide config', () => { + // why: add trailing "/" to test that it gets removed + process.env.GITLAB_WEB_IDE_PUBLIC_PATH = `${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}/`; + window.gon.gitlab_url = TEST_GITLAB_URL; + + // act + const actual = getBaseConfig(); + + // asset + expect(actual).toEqual({ + baseUrl: `${TEST_HOST}/${TEST_GITLAB_WEB_IDE_PUBLIC_PATH}`, + gitlabUrl: TEST_GITLAB_URL, + }); + }); +}); diff --git a/spec/frontend/ide/lib/gitlab_web_ide/setup_root_element_spec.js b/spec/frontend/ide/lib/gitlab_web_ide/setup_root_element_spec.js new file mode 100644 index 00000000000..35cf41b31f5 --- /dev/null +++ b/spec/frontend/ide/lib/gitlab_web_ide/setup_root_element_spec.js @@ -0,0 +1,32 @@ +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import { setupRootElement } from '~/ide/lib/gitlab_web_ide/setup_root_element'; + +describe('~/ide/lib/gitlab_web_ide/setup_root_element', () => { + beforeEach(() => { + setHTMLFixture(` + <div id="ide-test-root" class="js-not-a-real-class"> + <span>We are loading lots of stuff...</span> + </div> + `); + }); + + afterEach(() => { + resetHTMLFixture(); + }); + + const findIDERoot = () => document.getElementById('ide-test-root'); + + it('has no children, has original ID, and classes', () => { + const result = setupRootElement(findIDERoot()); + + // why: Assert that the return element matches the new one found in the dom + // (implying a el.replaceWith...) + expect(result).toBe(findIDERoot()); + expect(result).toMatchInlineSnapshot(` + <div + class="gl--flex-center gl-relative gl-h-full" + id="ide-test-root" + /> + `); + }); +}); |