Commit 2ce7fe66 authored by Mike Greiling's avatar Mike Greiling

Merge branch '339346-change-get-json-750bf1702c2' into 'master'

Use import for json fixture - 1/7

See merge request gitlab-org/gitlab!71898
parents 61d6439d 06f5f500
/* eslint no-param-reassign: "off" */ /* eslint no-param-reassign: "off" */
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import $ from 'jquery'; import $ from 'jquery';
import labelsFixture from 'test_fixtures/autocomplete_sources/labels.json';
import GfmAutoComplete, { membersBeforeSave } from 'ee_else_ce/gfm_auto_complete'; import GfmAutoComplete, { membersBeforeSave } from 'ee_else_ce/gfm_auto_complete';
import { initEmojiMock } from 'helpers/emoji'; import { initEmojiMock } from 'helpers/emoji';
import '~/lib/utils/jquery_at_who'; import '~/lib/utils/jquery_at_who';
import { getJSONFixture } from 'helpers/fixtures';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import AjaxCache from '~/lib/utils/ajax_cache'; import AjaxCache from '~/lib/utils/ajax_cache';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
const labelsFixture = getJSONFixture('autocomplete_sources/labels.json');
describe('GfmAutoComplete', () => { describe('GfmAutoComplete', () => {
const fetchDataMock = { fetchData: jest.fn() }; const fetchDataMock = { fetchData: jest.fn() };
let gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call(fetchDataMock); let gfmAutoCompleteCallbacks = GfmAutoComplete.prototype.getDefaultCallbacks.call(fetchDataMock);
......
...@@ -4,6 +4,9 @@ import axios from 'axios'; ...@@ -4,6 +4,9 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { merge, last } from 'lodash'; import { merge, last } from 'lodash';
import Vuex from 'vuex'; import Vuex from 'vuex';
import commit from 'test_fixtures/api/commits/commit.json';
import branches from 'test_fixtures/api/branches/branches.json';
import tags from 'test_fixtures/api/tags/tags.json';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import { ENTER_KEY } from '~/lib/utils/keys'; import { ENTER_KEY } from '~/lib/utils/keys';
import { sprintf } from '~/locale'; import { sprintf } from '~/locale';
...@@ -21,11 +24,7 @@ const localVue = createLocalVue(); ...@@ -21,11 +24,7 @@ const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
describe('Ref selector component', () => { describe('Ref selector component', () => {
const fixtures = { const fixtures = { branches, tags, commit };
branches: getJSONFixture('api/branches/branches.json'),
tags: getJSONFixture('api/tags/tags.json'),
commit: getJSONFixture('api/commits/commit.json'),
};
const projectId = '8'; const projectId = '8';
...@@ -480,8 +479,6 @@ describe('Ref selector component', () => { ...@@ -480,8 +479,6 @@ describe('Ref selector component', () => {
it('renders each commit as a selectable item with the short SHA and commit title', () => { it('renders each commit as a selectable item with the short SHA and commit title', () => {
const dropdownItems = findCommitDropdownItems(); const dropdownItems = findCommitDropdownItems();
const { commit } = fixtures;
expect(dropdownItems.at(0).text()).toBe(`${commit.short_id} ${commit.title}`); expect(dropdownItems.at(0).text()).toBe(`${commit.short_id} ${commit.title}`);
}); });
}); });
......
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import mockData from 'test_fixtures/issues/related_merge_requests.json';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import RelatedMergeRequests from '~/related_merge_requests/components/related_merge_requests.vue'; import RelatedMergeRequests from '~/related_merge_requests/components/related_merge_requests.vue';
import createStore from '~/related_merge_requests/store/index'; import createStore from '~/related_merge_requests/store/index';
import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue'; import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue';
const FIXTURE_PATH = 'issues/related_merge_requests.json';
const API_ENDPOINT = '/api/v4/projects/2/issues/33/related_merge_requests'; const API_ENDPOINT = '/api/v4/projects/2/issues/33/related_merge_requests';
const localVue = createLocalVue(); const localVue = createLocalVue();
describe('RelatedMergeRequests', () => { describe('RelatedMergeRequests', () => {
let wrapper; let wrapper;
let mock; let mock;
let mockData;
beforeEach((done) => { beforeEach((done) => {
loadFixtures(FIXTURE_PATH);
mockData = getJSONFixture(FIXTURE_PATH);
// put the fixture in DOM as the component expects // put the fixture in DOM as the component expects
document.body.innerHTML = `<div id="js-issuable-app"></div>`; document.body.innerHTML = `<div id="js-issuable-app"></div>`;
document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(mockData); document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(mockData);
......
const runnerFixture = (filename) => getJSONFixture(`graphql/runner/${filename}`);
// Fixtures generated by: spec/frontend/fixtures/runner.rb // Fixtures generated by: spec/frontend/fixtures/runner.rb
// Admin queries // Admin queries
export const runnersData = runnerFixture('get_runners.query.graphql.json'); import runnersData from 'test_fixtures/graphql/runner/get_runners.query.graphql.json';
export const runnersDataPaginated = runnerFixture('get_runners.query.graphql.paginated.json'); import runnersDataPaginated from 'test_fixtures/graphql/runner/get_runners.query.graphql.paginated.json';
export const runnerData = runnerFixture('get_runner.query.graphql.json'); import runnerData from 'test_fixtures/graphql/runner/get_runner.query.graphql.json';
// Group queries // Group queries
export const groupRunnersData = runnerFixture('get_group_runners.query.graphql.json'); import groupRunnersData from 'test_fixtures/graphql/runner/get_group_runners.query.graphql.json';
export const groupRunnersDataPaginated = runnerFixture( import groupRunnersDataPaginated from 'test_fixtures/graphql/runner/get_group_runners.query.graphql.paginated.json';
'get_group_runners.query.graphql.paginated.json',
); export {
runnerData,
runnersDataPaginated,
runnersData,
groupRunnersData,
groupRunnersDataPaginated,
};
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { memoize, cloneDeep } from 'lodash'; import { memoize, cloneDeep } from 'lodash';
import { getFixture, getJSONFixture } from 'helpers/fixtures'; import usersFixture from 'test_fixtures/autocomplete/users.json';
import { getFixture } from 'helpers/fixtures';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import UsersSelect from '~/users_select'; import UsersSelect from '~/users_select';
...@@ -15,7 +16,7 @@ const getUserSearchHTML = memoize((fixturePath) => { ...@@ -15,7 +16,7 @@ const getUserSearchHTML = memoize((fixturePath) => {
return el.outerHTML; return el.outerHTML;
}); });
const getUsersFixture = memoize(() => getJSONFixture('autocomplete/users.json')); const getUsersFixture = () => usersFixture;
export const getUsersFixtureAt = (idx) => getUsersFixture()[idx]; export const getUsersFixtureAt = (idx) => getUsersFixture()[idx];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment