Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-20 00:06:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-20 00:06:29 +0300
commitb35b9ac7e2fd4a707ea9291eb57769c690403b4c (patch)
treeae746b64cc7d3a19926e6d4a39a5daeb990a4154 /spec
parent81f7adf08b4557c38ac2ef1c730e72e07db2f1a3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/tracking_spec.js81
-rw-r--r--spec/javascripts/helpers/tracking_helper.js25
-rw-r--r--spec/javascripts/integrations/integration_settings_form_spec.js1
-rw-r--r--spec/javascripts/sidebar/assignee_title_spec.js14
-rw-r--r--spec/javascripts/sidebar/confidential_issue_sidebar_spec.js13
-rw-r--r--spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js13
-rw-r--r--spec/javascripts/sidebar/subscriptions_spec.js9
-rw-r--r--spec/models/repository_spec.rb4
-rw-r--r--spec/requests/api/commits_spec.rb12
9 files changed, 110 insertions, 62 deletions
diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js
index dfc068ab6ea..964f8b8787e 100644
--- a/spec/frontend/tracking_spec.js
+++ b/spec/frontend/tracking_spec.js
@@ -1,10 +1,9 @@
-import $ from 'jquery';
import { setHTMLFixture } from './helpers/fixtures';
-
import Tracking, { initUserTracking } from '~/tracking';
describe('Tracking', () => {
let snowplowSpy;
+ let bindDocumentSpy;
beforeEach(() => {
window.snowplow = window.snowplow || (() => {});
@@ -17,6 +16,10 @@ describe('Tracking', () => {
});
describe('initUserTracking', () => {
+ beforeEach(() => {
+ bindDocumentSpy = jest.spyOn(Tracking, 'bindDocument').mockImplementation(() => null);
+ });
+
it('calls through to get a new tracker with the expected options', () => {
initUserTracking();
expect(snowplowSpy).toHaveBeenCalledWith('newTracker', '_namespace_', 'app.gitfoo.com', {
@@ -50,6 +53,11 @@ describe('Tracking', () => {
expect(snowplowSpy).toHaveBeenCalledWith('enableFormTracking');
expect(snowplowSpy).toHaveBeenCalledWith('enableLinkClickTracking');
});
+
+ it('binds the document event handling', () => {
+ initUserTracking();
+ expect(bindDocumentSpy).toHaveBeenCalled();
+ });
});
describe('.event', () => {
@@ -62,11 +70,15 @@ describe('Tracking', () => {
it('tracks to snowplow (our current tracking system)', () => {
Tracking.event('_category_', '_eventName_', { label: '_label_' });
- expect(snowplowSpy).toHaveBeenCalledWith('trackStructEvent', '_category_', '_eventName_', {
- label: '_label_',
- property: '',
- value: '',
- });
+ expect(snowplowSpy).toHaveBeenCalledWith(
+ 'trackStructEvent',
+ '_category_',
+ '_eventName_',
+ '_label_',
+ undefined,
+ undefined,
+ undefined,
+ );
});
it('skips tracking if snowplow is unavailable', () => {
@@ -99,83 +111,70 @@ describe('Tracking', () => {
});
describe('tracking interface events', () => {
- let eventSpy = null;
- let subject = null;
+ let eventSpy;
+
+ const trigger = (selector, eventName = 'click') => {
+ const event = new Event(eventName, { bubbles: true });
+ document.querySelector(selector).dispatchEvent(event);
+ };
beforeEach(() => {
eventSpy = jest.spyOn(Tracking, 'event');
- subject = new Tracking('_category_');
+ Tracking.bindDocument('_category_'); // only happens once
setHTMLFixture(`
<input data-track-event="click_input1" data-track-label="_label_" value="_value_"/>
<input data-track-event="click_input2" data-track-value="_value_override_" value="_value_"/>
<input type="checkbox" data-track-event="toggle_checkbox" value="_value_" checked/>
<input class="dropdown" data-track-event="toggle_dropdown"/>
- <div class="js-projects-list-holder"></div>
+ <div data-track-event="nested_event"><span class="nested"></span></div>
`);
});
it('binds to clicks on elements matching [data-track-event]', () => {
- subject.bind(document);
- $('[data-track-event="click_input1"]').click();
+ trigger('[data-track-event="click_input1"]');
expect(eventSpy).toHaveBeenCalledWith('_category_', 'click_input1', {
label: '_label_',
value: '_value_',
- property: '',
});
});
it('allows value override with the data-track-value attribute', () => {
- subject.bind(document);
- $('[data-track-event="click_input2"]').click();
+ trigger('[data-track-event="click_input2"]');
expect(eventSpy).toHaveBeenCalledWith('_category_', 'click_input2', {
- label: '',
value: '_value_override_',
- property: '',
});
});
it('handles checkbox values correctly', () => {
- subject.bind(document);
- const $checkbox = $('[data-track-event="toggle_checkbox"]');
-
- $checkbox.click(); // unchecking
+ trigger('[data-track-event="toggle_checkbox"]'); // checking
expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_checkbox', {
- label: '',
- property: '',
value: false,
});
- $checkbox.click(); // checking
+ trigger('[data-track-event="toggle_checkbox"]'); // unchecking
expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_checkbox', {
- label: '',
- property: '',
value: '_value_',
});
});
it('handles bootstrap dropdowns', () => {
- new Tracking('_category_').bind(document);
- const $dropdown = $('[data-track-event="toggle_dropdown"]');
+ trigger('[data-track-event="toggle_dropdown"]', 'show.bs.dropdown'); // showing
- $dropdown.trigger('show.bs.dropdown'); // showing
+ expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_dropdown_show', {});
- expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_dropdown_show', {
- label: '',
- property: '',
- value: '',
- });
+ trigger('[data-track-event="toggle_dropdown"]', 'hide.bs.dropdown'); // hiding
+
+ expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_dropdown_hide', {});
+ });
- $dropdown.trigger('hide.bs.dropdown'); // hiding
+ it('handles nested elements inside an element with tracking', () => {
+ trigger('span.nested', 'click');
- expect(eventSpy).toHaveBeenCalledWith('_category_', 'toggle_dropdown_hide', {
- label: '',
- property: '',
- value: '',
- });
+ expect(eventSpy).toHaveBeenCalledWith('_category_', 'nested_event', {});
});
});
});
diff --git a/spec/javascripts/helpers/tracking_helper.js b/spec/javascripts/helpers/tracking_helper.js
new file mode 100644
index 00000000000..68c1bd2dbca
--- /dev/null
+++ b/spec/javascripts/helpers/tracking_helper.js
@@ -0,0 +1,25 @@
+import Tracking from '~/tracking';
+
+export default Tracking;
+
+let document;
+let handlers;
+
+export function mockTracking(category = '_category_', documentOverride, spyMethod) {
+ document = documentOverride || window.document;
+ window.snowplow = () => {};
+ Tracking.bindDocument(category, document);
+ return spyMethod ? spyMethod(Tracking, 'event') : null;
+}
+
+export function unmockTracking() {
+ window.snowplow = undefined;
+ handlers.forEach(event => document.removeEventListener(event.name, event.func));
+}
+
+export function triggerEvent(selectorOrEl, eventName = 'click') {
+ const event = new Event(eventName, { bubbles: true });
+ const el = typeof selectorOrEl === 'string' ? document.querySelector(selectorOrEl) : selectorOrEl;
+
+ el.dispatchEvent(event);
+}
diff --git a/spec/javascripts/integrations/integration_settings_form_spec.js b/spec/javascripts/integrations/integration_settings_form_spec.js
index 069e2cb07b5..82d1f815ca8 100644
--- a/spec/javascripts/integrations/integration_settings_form_spec.js
+++ b/spec/javascripts/integrations/integration_settings_form_spec.js
@@ -126,6 +126,7 @@ describe('IntegrationSettingsForm', () => {
spyOn(axios, 'put').and.callThrough();
integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
+ // eslint-disable-next-line no-jquery/no-serialize
formData = integrationSettingsForm.$form.serialize();
});
diff --git a/spec/javascripts/sidebar/assignee_title_spec.js b/spec/javascripts/sidebar/assignee_title_spec.js
index 7fff7c075d9..6c65a55ff29 100644
--- a/spec/javascripts/sidebar/assignee_title_spec.js
+++ b/spec/javascripts/sidebar/assignee_title_spec.js
@@ -1,13 +1,12 @@
import Vue from 'vue';
import AssigneeTitle from '~/sidebar/components/assignees/assignee_title.vue';
+import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
describe('AssigneeTitle component', () => {
let component;
let AssigneeTitleComponent;
- let statsSpy;
beforeEach(() => {
- statsSpy = spyOnDependency(AssigneeTitle, 'trackEvent');
AssigneeTitleComponent = Vue.extend(AssigneeTitle);
});
@@ -105,15 +104,20 @@ describe('AssigneeTitle component', () => {
expect(component.$el.querySelector('.edit-link')).not.toBeNull();
});
- it('calls trackEvent when edit is clicked', () => {
+ it('tracks the event when edit is clicked', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 0,
editable: true,
},
}).$mount();
- component.$el.querySelector('.js-sidebar-dropdown-toggle').click();
- expect(statsSpy).toHaveBeenCalled();
+ const spy = mockTracking('_category_', component.$el, spyOn);
+ triggerEvent('.js-sidebar-dropdown-toggle');
+
+ expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
+ label: 'right_sidebar',
+ property: 'assignee',
+ });
});
});
diff --git a/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js b/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js
index ea9e5677bc5..50374b8973f 100644
--- a/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js
+++ b/spec/javascripts/sidebar/confidential_issue_sidebar_spec.js
@@ -1,13 +1,12 @@
import Vue from 'vue';
import confidentialIssueSidebar from '~/sidebar/components/confidential/confidential_issue_sidebar.vue';
+import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
describe('Confidential Issue Sidebar Block', () => {
let vm1;
let vm2;
- let statsSpy;
beforeEach(() => {
- statsSpy = spyOnDependency(confidentialIssueSidebar, 'trackEvent');
const Component = Vue.extend(confidentialIssueSidebar);
const service = {
update: () => Promise.resolve(true),
@@ -70,9 +69,13 @@ describe('Confidential Issue Sidebar Block', () => {
});
});
- it('calls trackEvent when "Edit" is clicked', () => {
- vm1.$el.querySelector('.confidential-edit').click();
+ it('tracks the event when "Edit" is clicked', () => {
+ const spy = mockTracking('_category_', vm1.$el, spyOn);
+ triggerEvent('.confidential-edit');
- expect(statsSpy).toHaveBeenCalled();
+ expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
+ label: 'right_sidebar',
+ property: 'confidentiality',
+ });
});
});
diff --git a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js b/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js
index 2d930428230..decccbb8964 100644
--- a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js
+++ b/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js
@@ -1,13 +1,12 @@
import Vue from 'vue';
import lockIssueSidebar from '~/sidebar/components/lock/lock_issue_sidebar.vue';
+import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
describe('LockIssueSidebar', () => {
let vm1;
let vm2;
- let statsSpy;
beforeEach(() => {
- statsSpy = spyOnDependency(lockIssueSidebar, 'trackEvent');
const Component = Vue.extend(lockIssueSidebar);
const mediator = {
@@ -61,10 +60,14 @@ describe('LockIssueSidebar', () => {
});
});
- it('calls trackEvent when "Edit" is clicked', () => {
- vm1.$el.querySelector('.lock-edit').click();
+ it('tracks an event when "Edit" is clicked', () => {
+ const spy = mockTracking('_category_', vm1.$el, spyOn);
+ triggerEvent('.lock-edit');
- expect(statsSpy).toHaveBeenCalled();
+ expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
+ label: 'right_sidebar',
+ property: 'lock_issue',
+ });
});
it('displays the edit form when opened from collapsed state', done => {
diff --git a/spec/javascripts/sidebar/subscriptions_spec.js b/spec/javascripts/sidebar/subscriptions_spec.js
index 2efa13f3fe8..a97608d6b8a 100644
--- a/spec/javascripts/sidebar/subscriptions_spec.js
+++ b/spec/javascripts/sidebar/subscriptions_spec.js
@@ -2,14 +2,13 @@ import Vue from 'vue';
import subscriptions from '~/sidebar/components/subscriptions/subscriptions.vue';
import eventHub from '~/sidebar/event_hub';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
+import { mockTracking } from 'spec/helpers/tracking_helper';
describe('Subscriptions', function() {
let vm;
let Subscriptions;
- let statsSpy;
beforeEach(() => {
- statsSpy = spyOnDependency(subscriptions, 'trackEvent');
Subscriptions = Vue.extend(subscriptions);
});
@@ -53,6 +52,7 @@ describe('Subscriptions', function() {
vm = mountComponent(Subscriptions, { subscribed: true });
spyOn(eventHub, '$emit');
spyOn(vm, '$emit');
+ spyOn(vm, 'track');
vm.toggleSubscription();
@@ -60,11 +60,12 @@ describe('Subscriptions', function() {
expect(vm.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object));
});
- it('calls trackEvent when toggled', () => {
+ it('tracks the event when toggled', () => {
vm = mountComponent(Subscriptions, { subscribed: true });
+ const spy = mockTracking('_category_', vm.$el, spyOn);
vm.toggleSubscription();
- expect(statsSpy).toHaveBeenCalled();
+ expect(spy).toHaveBeenCalled();
});
it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => {
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 6dc47e0e501..011b46c7f1a 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -279,7 +279,7 @@ describe Repository do
describe '#commits' do
context 'when neither the all flag nor a ref are specified' do
it 'returns every commit from default branch' do
- expect(repository.commits(limit: 60).size).to eq(37)
+ expect(repository.commits(nil, limit: 60).size).to eq(37)
end
end
@@ -320,7 +320,7 @@ describe Repository do
context "when 'all' flag is set" do
it 'returns every commit from the repository' do
- expect(repository.commits(all: true, limit: 60).size).to eq(60)
+ expect(repository.commits(nil, all: true, limit: 60).size).to eq(60)
end
end
end
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 5e6ff40e8cf..90ff1d12bf1 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -169,6 +169,18 @@ describe API::Commits do
end
end
+ context 'first_parent optional parameter' do
+ it 'returns all first_parent commits' do
+ commit_count = project.repository.count_commits(ref: SeedRepo::Commit::ID, first_parent: true)
+
+ get api("/projects/#{project_id}/repository/commits", user), params: { ref_name: SeedRepo::Commit::ID, first_parent: 'true' }
+
+ expect(response).to include_pagination_headers
+ expect(commit_count).to eq(12)
+ expect(response.headers['X-Total']).to eq(commit_count.to_s)
+ end
+ end
+
context 'with_stats optional parameter' do
let(:project) { create(:project, :public, :repository) }