Skip to content
Snippets Groups Projects
Commit 10d0e569 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent a19a376b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -20,7 +20,7 @@ describe('File upload', () => {
const btn = document.querySelector('.js-button');
const input = document.querySelector('.js-input');
 
spyOn(input, 'click');
jest.spyOn(input, 'click').mockReturnValue();
 
btn.click();
 
Loading
Loading
@@ -43,7 +43,7 @@ describe('File upload', () => {
const btn = document.querySelector('.js-button');
fileUpload('.js-not-button', '.js-input');
 
spyOn(input, 'click');
jest.spyOn(input, 'click').mockReturnValue();
 
btn.click();
 
Loading
Loading
@@ -55,7 +55,7 @@ describe('File upload', () => {
const btn = document.querySelector('.js-button');
fileUpload('.js-button', '.js-not-input');
 
spyOn(input, 'click');
jest.spyOn(input, 'click').mockReturnValue();
 
btn.click();
 
Loading
Loading
Loading
Loading
@@ -17,51 +17,44 @@ describe('Icon utils', () => {
 
let axiosMock;
let mockEndpoint;
let getIcon;
const mockName = 'mockIconName';
const mockPath = 'mockPath';
const getIcon = () => iconUtils.getSvgIconPathContent(mockName);
 
beforeEach(() => {
axiosMock = new MockAdapter(axios);
mockEndpoint = axiosMock.onGet(gon.sprite_icons);
getIcon = iconUtils.getSvgIconPathContent(mockName);
});
 
afterEach(() => {
axiosMock.restore();
});
 
it('extracts svg icon path content from sprite icons', done => {
it('extracts svg icon path content from sprite icons', () => {
mockEndpoint.replyOnce(
200,
`<svg><symbol id="${mockName}"><path d="${mockPath}"/></symbol></svg>`,
);
getIcon
.then(path => {
expect(path).toBe(mockPath);
done();
})
.catch(done.fail);
return getIcon().then(path => {
expect(path).toBe(mockPath);
});
});
 
it('returns null if icon path content does not exist', done => {
it('returns null if icon path content does not exist', () => {
mockEndpoint.replyOnce(200, ``);
getIcon
.then(path => {
expect(path).toBe(null);
done();
})
.catch(done.fail);
return getIcon().then(path => {
expect(path).toBe(null);
});
});
 
it('returns null if an http error occurs', done => {
it('returns null if an http error occurs', () => {
mockEndpoint.replyOnce(500);
getIcon
.then(path => {
expect(path).toBe(null);
done();
})
.catch(done.fail);
return getIcon().then(path => {
expect(path).toBe(null);
});
});
});
});
Loading
Loading
@@ -243,7 +243,7 @@ describe('init markdown', () => {
});
 
it('uses ace editor insert text when editor is passed in', () => {
spyOn(editor, 'insert');
jest.spyOn(editor, 'insert').mockReturnValue();
 
insertMarkdownText({
text: editor.getValue,
Loading
Loading
@@ -258,7 +258,7 @@ describe('init markdown', () => {
});
 
it('adds block tags on line above and below selection', () => {
spyOn(editor, 'insert');
jest.spyOn(editor, 'insert').mockReturnValue();
 
const selected = 'this text \n is multiple \n lines';
const text = `before \n ${selected} \n after`;
Loading
Loading
@@ -276,7 +276,7 @@ describe('init markdown', () => {
});
 
it('uses ace editor to navigate back tag length when nothing is selected', () => {
spyOn(editor, 'navigateLeft');
jest.spyOn(editor, 'navigateLeft').mockReturnValue();
 
insertMarkdownText({
text: editor.getValue,
Loading
Loading
@@ -291,7 +291,7 @@ describe('init markdown', () => {
});
 
it('ace editor does not navigate back when there is selected text', () => {
spyOn(editor, 'navigateLeft');
jest.spyOn(editor, 'navigateLeft').mockReturnValue();
 
insertMarkdownText({
text: editor.getValue,
Loading
Loading
Loading
Loading
@@ -4,7 +4,10 @@ import UsersCache from '~/lib/utils/users_cache';
describe('UsersCache', () => {
const dummyUsername = 'win';
const dummyUserId = 123;
const dummyUser = { name: 'has a farm', username: 'farmer' };
const dummyUser = {
name: 'has a farm',
username: 'farmer',
};
const dummyUserStatus = 'my status';
 
beforeEach(() => {
Loading
Loading
@@ -68,7 +71,6 @@ describe('UsersCache', () => {
 
it('does nothing if cache contains no matching data', () => {
UsersCache.internalStorage['no body'] = 'no data';
UsersCache.remove(dummyUsername);
 
expect(UsersCache.internalStorage['no body']).toBe('no data');
Loading
Loading
@@ -76,7 +78,6 @@ describe('UsersCache', () => {
 
it('removes matching data', () => {
UsersCache.internalStorage[dummyUsername] = dummyUser;
UsersCache.remove(dummyUsername);
 
expect(UsersCache.internalStorage).toEqual({});
Loading
Loading
@@ -87,13 +88,16 @@ describe('UsersCache', () => {
let apiSpy;
 
beforeEach(() => {
spyOn(Api, 'users').and.callFake((query, options) => apiSpy(query, options));
jest.spyOn(Api, 'users').mockImplementation((query, options) => apiSpy(query, options));
});
 
it('stores and returns data from API call if cache is empty', done => {
apiSpy = (query, options) => {
expect(query).toBe('');
expect(options).toEqual({ username: dummyUsername });
expect(options).toEqual({
username: dummyUsername,
});
return Promise.resolve({
data: [dummyUser],
});
Loading
Loading
@@ -110,14 +114,18 @@ describe('UsersCache', () => {
 
it('returns undefined if Ajax call fails and cache is empty', done => {
const dummyError = new Error('server exploded');
apiSpy = (query, options) => {
expect(query).toBe('');
expect(options).toEqual({ username: dummyUsername });
expect(options).toEqual({
username: dummyUsername,
});
return Promise.reject(dummyError);
};
 
UsersCache.retrieve(dummyUsername)
.then(user => fail(`Received unexpected user: ${JSON.stringify(user)}`))
.then(user => done.fail(`Received unexpected user: ${JSON.stringify(user)}`))
.catch(error => {
expect(error).toBe(dummyError);
})
Loading
Loading
@@ -127,7 +135,8 @@ describe('UsersCache', () => {
 
it('makes no Ajax call if matching data exists', done => {
UsersCache.internalStorage[dummyUsername] = dummyUser;
apiSpy = () => fail(new Error('expected no Ajax call!'));
apiSpy = () => done.fail(new Error('expected no Ajax call!'));
 
UsersCache.retrieve(dummyUsername)
.then(user => {
Loading
Loading
@@ -142,12 +151,13 @@ describe('UsersCache', () => {
let apiSpy;
 
beforeEach(() => {
spyOn(Api, 'user').and.callFake(id => apiSpy(id));
jest.spyOn(Api, 'user').mockImplementation(id => apiSpy(id));
});
 
it('stores and returns data from API call if cache is empty', done => {
apiSpy = id => {
expect(id).toBe(dummyUserId);
return Promise.resolve({
data: dummyUser,
});
Loading
Loading
@@ -164,13 +174,15 @@ describe('UsersCache', () => {
 
it('returns undefined if Ajax call fails and cache is empty', done => {
const dummyError = new Error('server exploded');
apiSpy = id => {
expect(id).toBe(dummyUserId);
return Promise.reject(dummyError);
};
 
UsersCache.retrieveById(dummyUserId)
.then(user => fail(`Received unexpected user: ${JSON.stringify(user)}`))
.then(user => done.fail(`Received unexpected user: ${JSON.stringify(user)}`))
.catch(error => {
expect(error).toBe(dummyError);
})
Loading
Loading
@@ -180,7 +192,8 @@ describe('UsersCache', () => {
 
it('makes no Ajax call if matching data exists', done => {
UsersCache.internalStorage[dummyUserId] = dummyUser;
apiSpy = () => fail(new Error('expected no Ajax call!'));
apiSpy = () => done.fail(new Error('expected no Ajax call!'));
 
UsersCache.retrieveById(dummyUserId)
.then(user => {
Loading
Loading
@@ -195,12 +208,13 @@ describe('UsersCache', () => {
let apiSpy;
 
beforeEach(() => {
spyOn(Api, 'userStatus').and.callFake(id => apiSpy(id));
jest.spyOn(Api, 'userStatus').mockImplementation(id => apiSpy(id));
});
 
it('stores and returns data from API call if cache is empty', done => {
apiSpy = id => {
expect(id).toBe(dummyUserId);
return Promise.resolve({
data: dummyUserStatus,
});
Loading
Loading
@@ -217,13 +231,15 @@ describe('UsersCache', () => {
 
it('returns undefined if Ajax call fails and cache is empty', done => {
const dummyError = new Error('server exploded');
apiSpy = id => {
expect(id).toBe(dummyUserId);
return Promise.reject(dummyError);
};
 
UsersCache.retrieveStatusById(dummyUserId)
.then(userStatus => fail(`Received unexpected user: ${JSON.stringify(userStatus)}`))
.then(userStatus => done.fail(`Received unexpected user: ${JSON.stringify(userStatus)}`))
.catch(error => {
expect(error).toBe(dummyError);
})
Loading
Loading
@@ -232,8 +248,11 @@ describe('UsersCache', () => {
});
 
it('makes no Ajax call if matching data exists', done => {
UsersCache.internalStorage[dummyUserId] = { status: dummyUserStatus };
apiSpy = () => fail(new Error('expected no Ajax call!'));
UsersCache.internalStorage[dummyUserId] = {
status: dummyUserStatus,
};
apiSpy = () => done.fail(new Error('expected no Ajax call!'));
 
UsersCache.retrieveStatusById(dummyUserId)
.then(userStatus => {
Loading
Loading
Loading
Loading
@@ -235,4 +235,88 @@ describe ApplicationHelper do
end
end
end
describe '#body_data' do
context 'when @project is not set' do
it 'does not include project data in the body data elements' do
expect(helper.body_data).to eq(
{
page: 'application',
page_type_id: nil,
find_file: nil,
group: ''
}
)
end
context 'when @group is set' do
it 'sets group in the body data elements' do
group = create(:group)
assign(:group, group)
expect(helper.body_data).to eq(
{
page: 'application',
page_type_id: nil,
find_file: nil,
group: group.path
}
)
end
end
end
context 'when @project is set' do
it 'includes all possible body data elements and associates the project elements with project' do
project = create(:project)
assign(:project, project)
expect(helper.body_data).to eq(
{
page: 'application',
page_type_id: nil,
find_file: nil,
group: '',
project_id: project.id,
project: project.name,
namespace_id: project.namespace.id
}
)
end
context 'when controller is issues' do
before do
stub_controller_method(:controller_path, 'projects:issues')
end
context 'when params[:id] is present and the issue exsits and action_name is show' do
it 'sets all project and id elements correctly related to the issue' do
issue = create(:issue)
stub_controller_method(:action_name, 'show')
stub_controller_method(:params, { id: issue.id })
assign(:project, issue.project)
expect(helper.body_data).to eq(
{
page: 'projects:issues:show',
page_type_id: issue.id,
find_file: nil,
group: '',
project_id: issue.project.id,
project: issue.project.name,
namespace_id: issue.project.namespace.id
}
)
end
end
end
end
def stub_controller_method(method_name, value)
allow(helper.controller).to receive(method_name).and_return(value)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'layouts/application' do
let(:user) { create(:user) }
before do
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
allow(view).to receive(:experiment_enabled?).and_return(false)
allow(view).to receive(:session).and_return({})
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
end
context 'body data elements for pageview context' do
let(:body_data) do
{
body_data_page: 'projects:issues:show',
body_data_page_type_id: '1',
body_data_project_id: '2',
body_data_namespace_id: '3'
}
end
before do
allow(view).to receive(:body_data).and_return(body_data)
render
end
it 'includes the body element page' do
expect(rendered).to include('data-page="projects:issues:show"')
end
it 'includes the body element page_type_id' do
expect(rendered).to include('data-page-type-id="1"')
end
it 'includes the body element project_id' do
expect(rendered).to include('data-project-id="2"')
end
it 'includes the body element namespace_id' do
expect(rendered).to include('data-namespace-id="3"')
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment