Commit 8ac6382e authored by derek-knox's avatar derek-knox Committed by Chad Woolley

Update test suite

Update tests
Add changelog
parent a5438f30
---
title: Add merge request description templates to Static Site Editor
merge_request: 46488
author:
type: added
......@@ -10,6 +10,45 @@ RSpec.describe Projects::TemplatesController do
let!(:file_1) { project.repository.create_file(user, file_path_1, 'issue content', message: 'message', branch_name: 'master') }
let!(:file_2) { project.repository.create_file(user, file_path_2, 'merge request content', message: 'message', branch_name: 'master') }
describe '#index' do
before do
sign_in(user)
end
shared_examples 'templates request' do
it 'returns the templates' do
get(:index, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(1)
expect(json_response).to eq(expected_templates)
end
it 'fails for user with no access' do
other_user = create(:user)
sign_in(other_user)
get(:index, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json)
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when querying for issue templates' do
it_behaves_like 'templates request' do
let(:template_type) { 'issue' }
let(:expected_templates) { [ { key: "template1", name: "template_1", content: "This is template 1!" } ] }
end
end
context 'when querying for merge_request templates' do
it_behaves_like 'templates request' do
let(:template_type) { 'merge_request' }
let(:expected_templates) { [ { key: "template1", name: "template_1", content: "This is template 1!" } ] }
end
end
end
describe '#show' do
shared_examples 'renders issue templates as json' do
it do
......
......@@ -570,6 +570,28 @@ describe('Api', () => {
});
});
describe('issueTemplates', () => {
it('fetches all templates by type', done => {
const namespace = 'some namespace';
const project = 'some project';
const templateType = 'template type';
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}`;
const expectedData = [
{ key: 'Template1', name: 'Template 1', content: 'This is template 1!' },
];
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
Api.issueTemplates(namespace, project, templateType, (error, response) => {
expect(response.length).toBe(1);
const { key, name, content } = response[0];
expect(key).toBe('Template1');
expect(name).toBe('Template 1');
expect(content).toBe('This is template 1!');
done();
});
});
});
describe('projectTemplates', () => {
it('fetches a list of templates', done => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
......
import { shallowMount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import EditMetaModal from '~/static_site_editor/components/edit_meta_modal.vue';
import EditMetaControls from '~/static_site_editor/components/edit_meta_controls.vue';
import { MR_META_LOCAL_STORAGE_KEY } from '~/static_site_editor/constants';
import { sourcePath, mergeRequestMeta, mergeRequestTemplates } from '../mock_data';
import {
sourcePath,
mergeRequestMeta,
mergeRequestTemplates,
project as namespaceProject,
} from '../mock_data';
describe('~/static_site_editor/components/edit_meta_modal.vue', () => {
useLocalStorageSpy();
let wrapper;
let resetCachedEditable;
let mockEditMetaControlsInstance;
let mockAxios;
const { title, description } = mergeRequestMeta;
const [namespace, project] = namespaceProject.split('/');
const buildWrapper = (propsData = {}, data = {}) => {
wrapper = shallowMount(EditMetaModal, {
propsData: {
sourcePath,
namespace,
project,
...propsData,
},
data: () => data,
});
};
const buildMocks = () => {
resetCachedEditable = jest.fn();
mockEditMetaControlsInstance = { resetCachedEditable };
wrapper.vm.$refs.editMetaControls = mockEditMetaControlsInstance;
const buildMockAxios = () => {
mockAxios = new MockAdapter(axios);
mockAxios
.onGet(`${namespace}/${project}/templates/merge_request`)
.reply(200, mergeRequestTemplates);
};
const buildMockRefs = () => {
wrapper.vm.$refs.editMetaControls = { resetCachedEditable: jest.fn() };
};
const findGlModal = () => wrapper.find(GlModal);
......@@ -37,16 +51,17 @@ describe('~/static_site_editor/components/edit_meta_modal.vue', () => {
beforeEach(() => {
localStorage.setItem(MR_META_LOCAL_STORAGE_KEY);
});
beforeEach(() => {
buildMockAxios();
buildWrapper();
buildMocks();
buildMockRefs();
return wrapper.vm.$nextTick();
});
afterEach(() => {
mockAxios.restore();
wrapper.destroy();
wrapper = null;
});
......
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