diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-19 15:07:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-19 15:07:15 +0300 |
commit | ba55ca9bc4bf2c85d2d78fcb11552ad130151110 (patch) | |
tree | 8a205191235a5b2b29e5eaacf9224c73052dddc9 /spec/frontend | |
parent | ee3d5f16e3aa642944b121645764e33604a31307 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/__helpers__/fixtures.js | 29 | ||||
-rw-r--r-- | spec/frontend/environment.js | 6 | ||||
-rw-r--r-- | spec/frontend/listbox/index_spec.js | 9 | ||||
-rw-r--r-- | spec/frontend/listbox/redirect_behavior_spec.js | 9 | ||||
-rw-r--r-- | spec/frontend/tabs/index_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/users_select/index_spec.js | 5 | ||||
-rw-r--r-- | spec/frontend/users_select/test_helper.js | 10 |
7 files changed, 19 insertions, 60 deletions
diff --git a/spec/frontend/__helpers__/fixtures.js b/spec/frontend/__helpers__/fixtures.js index c66411979e9..5ae63bb1744 100644 --- a/spec/frontend/__helpers__/fixtures.js +++ b/spec/frontend/__helpers__/fixtures.js @@ -1,28 +1,3 @@ -import fs from 'fs'; -import path from 'path'; - -import { ErrorWithStack } from 'jest-util'; - -export function getFixture(relativePath) { - const basePath = relativePath.startsWith('static/') - ? global.staticFixturesBasePath - : global.fixturesBasePath; - const absolutePath = path.join(basePath, relativePath); - if (!fs.existsSync(absolutePath)) { - throw new ErrorWithStack( - `Fixture file ${relativePath} does not exist. - -Did you run bin/rake frontend:fixtures? You can also download fixtures from the gitlab-org/gitlab package registry. - -See https://docs.gitlab.com/ee/development/testing_guide/frontend_testing.html#download-fixtures for more info. -`, - getFixture, - ); - } - - return fs.readFileSync(absolutePath, 'utf8'); -} - export const resetHTMLFixture = () => { document.head.innerHTML = ''; document.body.innerHTML = ''; @@ -31,7 +6,3 @@ export const resetHTMLFixture = () => { export const setHTMLFixture = (htmlContent) => { document.body.innerHTML = htmlContent; }; - -export const loadHTMLFixture = (relativePath) => { - setHTMLFixture(getFixture(relativePath)); -}; diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js index 4e341b2bb2f..53fbe105ec6 100644 --- a/spec/frontend/environment.js +++ b/spec/frontend/environment.js @@ -1,6 +1,5 @@ /* eslint-disable import/no-commonjs, max-classes-per-file */ -const path = require('path'); const { TestEnvironment } = require('jest-environment-jsdom'); const { ErrorWithStack } = require('jest-util'); const { @@ -10,8 +9,6 @@ const { const { TEST_HOST } = require('./__helpers__/test_constants'); const { createGon } = require('./__helpers__/gon_helper'); -const ROOT_PATH = path.resolve(__dirname, '../..'); - class CustomEnvironment extends TestEnvironment { constructor({ globalConfig, projectConfig }, context) { // Setup testURL so that window.location is setup properly @@ -65,9 +62,6 @@ class CustomEnvironment extends TestEnvironment { this.rejectedPromises.push(error); }; - this.global.fixturesBasePath = `${ROOT_PATH}/tmp/tests/frontend/fixtures${IS_EE ? '-ee' : ''}`; - this.global.staticFixturesBasePath = `${ROOT_PATH}/spec/frontend/fixtures`; - /** * window.fetch() is required by the apollo-upload-client library otherwise * a ReferenceError is generated: https://github.com/jaydenseric/apollo-upload-client/issues/100 diff --git a/spec/frontend/listbox/index_spec.js b/spec/frontend/listbox/index_spec.js index 39e0332631b..ccbef1247ef 100644 --- a/spec/frontend/listbox/index_spec.js +++ b/spec/frontend/listbox/index_spec.js @@ -2,16 +2,15 @@ import { nextTick } from 'vue'; import { getAllByRole, getByTestId } from '@testing-library/dom'; import { GlCollapsibleListbox } from '@gitlab/ui'; import { createWrapper } from '@vue/test-utils'; +import htmlRedirectListbox from 'test_fixtures/listbox/redirect_listbox.html'; import { initListbox, parseAttributes } from '~/listbox'; -import { getFixture, setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; jest.mock('~/lib/utils/url_utility'); -const fixture = getFixture('listbox/redirect_listbox.html'); - const parsedAttributes = (() => { const div = document.createElement('div'); - div.innerHTML = fixture; + div.innerHTML = htmlRedirectListbox; return parseAttributes(div.firstChild); })(); @@ -46,7 +45,7 @@ describe('initListbox', () => { const findSelectedItems = () => getAllByRole(document.body, 'option', { selected: true }); beforeEach(async () => { - setHTMLFixture(fixture); + setHTMLFixture(htmlRedirectListbox); onChangeSpy = jest.fn(); setup(document.querySelector('.js-redirect-listbox'), { onChange: onChangeSpy }); diff --git a/spec/frontend/listbox/redirect_behavior_spec.js b/spec/frontend/listbox/redirect_behavior_spec.js index c2479e71e4a..eb3b6900a25 100644 --- a/spec/frontend/listbox/redirect_behavior_spec.js +++ b/spec/frontend/listbox/redirect_behavior_spec.js @@ -1,22 +1,21 @@ +import htmlRedirectListbox from 'test_fixtures/listbox/redirect_listbox.html'; import { initListbox } from '~/listbox'; import { initRedirectListboxBehavior } from '~/listbox/redirect_behavior'; import { redirectTo } from '~/lib/utils/url_utility'; // eslint-disable-line import/no-deprecated -import { getFixture, setHTMLFixture } from 'helpers/fixtures'; +import { setHTMLFixture } from 'helpers/fixtures'; jest.mock('~/lib/utils/url_utility'); jest.mock('~/listbox', () => ({ initListbox: jest.fn().mockReturnValue({ foo: true }), })); -const fixture = getFixture('listbox/redirect_listbox.html'); - describe('initRedirectListboxBehavior', () => { let instances; beforeEach(() => { setHTMLFixture(` - ${fixture} - ${fixture} + ${htmlRedirectListbox} + ${htmlRedirectListbox} `); instances = initRedirectListboxBehavior(); diff --git a/spec/frontend/tabs/index_spec.js b/spec/frontend/tabs/index_spec.js index 1d61d38a488..7c127fd7124 100644 --- a/spec/frontend/tabs/index_spec.js +++ b/spec/frontend/tabs/index_spec.js @@ -1,12 +1,11 @@ +import htmlTabs from 'test_fixtures/tabs/tabs.html'; import { GlTabsBehavior, TAB_SHOWN_EVENT, HISTORY_TYPE_HASH } from '~/tabs'; import { ACTIVE_PANEL_CLASS, ACTIVE_TAB_CLASSES } from '~/tabs/constants'; import { getLocationHash } from '~/lib/utils/url_utility'; import { NO_SCROLL_TO_HASH_CLASS } from '~/lib/utils/common_utils'; -import { getFixture, setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import setWindowLocation from 'helpers/set_window_location_helper'; -const tabsFixture = getFixture('tabs/tabs.html'); - global.CSS = { escape: (val) => val, }; @@ -107,7 +106,7 @@ describe('GlTabsBehavior', () => { }); beforeEach(() => { - setHTMLFixture(tabsFixture); + setHTMLFixture(htmlTabs); const tabsEl = findByTestId('tabs'); tabShownEventSpy = jest.fn(); @@ -247,7 +246,7 @@ describe('GlTabsBehavior', () => { describe('using aria-controls instead of href to link tabs to panels', () => { beforeEach(() => { - setHTMLFixture(tabsFixture); + setHTMLFixture(htmlTabs); const tabsEl = findByTestId('tabs'); ['foo', 'bar', 'qux'].forEach((name) => { @@ -279,7 +278,7 @@ describe('GlTabsBehavior', () => { let tabsEl; beforeEach(() => { - setHTMLFixture(tabsFixture); + setHTMLFixture(htmlTabs); tabsEl = findByTestId('tabs'); }); diff --git a/spec/frontend/users_select/index_spec.js b/spec/frontend/users_select/index_spec.js index 3757e63c4f9..dc6918ee543 100644 --- a/spec/frontend/users_select/index_spec.js +++ b/spec/frontend/users_select/index_spec.js @@ -1,4 +1,5 @@ import { escape } from 'lodash'; +import htmlCeMrSingleAssignees from 'test_fixtures/merge_requests/merge_request_with_single_assignee_feature.html'; import UsersSelect from '~/users_select/index'; import { createInputsModelExpectation, @@ -15,9 +16,7 @@ import { } from './test_helper'; describe('~/users_select/index', () => { - const context = createTestContext({ - fixturePath: 'merge_requests/merge_request_with_single_assignee_feature.html', - }); + const context = createTestContext({ fixture: htmlCeMrSingleAssignees }); beforeEach(() => { context.setup(); diff --git a/spec/frontend/users_select/test_helper.js b/spec/frontend/users_select/test_helper.js index 6fb3436100f..b38400446a9 100644 --- a/spec/frontend/users_select/test_helper.js +++ b/spec/frontend/users_select/test_helper.js @@ -1,18 +1,16 @@ import MockAdapter from 'axios-mock-adapter'; import { memoize, cloneDeep } from 'lodash'; import usersFixture from 'test_fixtures/autocomplete/users.json'; -import { getFixture } from 'helpers/fixtures'; import waitForPromises from 'helpers/wait_for_promises'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import UsersSelect from '~/users_select'; // fixtures ------------------------------------------------------------------- -const getUserSearchHTML = memoize((fixturePath) => { - const html = getFixture(fixturePath); +const getUserSearchHTML = memoize((fixture) => { const parser = new DOMParser(); - const el = parser.parseFromString(html, 'text/html').querySelector('.assignee'); + const el = parser.parseFromString(fixture, 'text/html').querySelector('.assignee'); return el.outerHTML; }); @@ -22,13 +20,13 @@ const getUsersFixture = () => usersFixture; export const getUsersFixtureAt = (idx) => getUsersFixture()[idx]; // test context --------------------------------------------------------------- -export const createTestContext = ({ fixturePath }) => { +export const createTestContext = ({ fixture }) => { let mock = null; let subject = null; const setup = () => { const rootEl = document.createElement('div'); - rootEl.innerHTML = getUserSearchHTML(fixturePath); + rootEl.innerHTML = getUserSearchHTML(fixture); document.body.appendChild(rootEl); mock = new MockAdapter(axios); |