Skip to content
代码片段 群组 项目
未验证 提交 46c6989c 编辑于 作者: Miguel Rincon's avatar Miguel Rincon 提交者: GitLab
浏览文件

Merge branch 'pedropombeiro/448507/add-unit-tests' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -361,7 +361,7 @@ describe('DashboardsList', () => { ...@@ -361,7 +361,7 @@ describe('DashboardsList', () => {
}); });
}); });
it('dimisses the alert when the component is destroyed', async () => { it('dismisses the alert when the component is destroyed', async () => {
wrapper.destroy(); wrapper.destroy();
await nextTick(); await nextTick();
......
import { GlSprintf } from '@gitlab/ui'; import { GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { mockTracking } from 'helpers/tracking_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createAlert, VARIANT_SUCCESS } from '~/alert'; import { createAlert, VARIANT_SUCCESS } from '~/alert';
...@@ -12,6 +13,7 @@ import { ...@@ -12,6 +13,7 @@ import {
PARAM_KEY_PLATFORM, PARAM_KEY_PLATFORM,
GROUP_TYPE, GROUP_TYPE,
DEFAULT_PLATFORM, DEFAULT_PLATFORM,
GOOGLE_CLOUD_PLATFORM,
WINDOWS_PLATFORM, WINDOWS_PLATFORM,
} from '~/ci/runner/constants'; } from '~/ci/runner/constants';
import RunnerCreateForm from '~/ci/runner/components/runner_create_form.vue'; import RunnerCreateForm from '~/ci/runner/components/runner_create_form.vue';
...@@ -31,6 +33,7 @@ const mockCreatedRunner = runnerCreateResult.data.runnerCreate.runner; ...@@ -31,6 +33,7 @@ const mockCreatedRunner = runnerCreateResult.data.runnerCreate.runner;
describe('GroupRunnerRunnerApp', () => { describe('GroupRunnerRunnerApp', () => {
let wrapper; let wrapper;
let trackingSpy;
const findRunnerPlatformsRadioGroup = () => wrapper.findComponent(RunnerPlatformsRadioGroup); const findRunnerPlatformsRadioGroup = () => wrapper.findComponent(RunnerPlatformsRadioGroup);
const findRegistrationCompatibilityAlert = () => const findRegistrationCompatibilityAlert = () =>
...@@ -38,6 +41,7 @@ describe('GroupRunnerRunnerApp', () => { ...@@ -38,6 +41,7 @@ describe('GroupRunnerRunnerApp', () => {
const findRunnerCreateForm = () => wrapper.findComponent(RunnerCreateForm); const findRunnerCreateForm = () => wrapper.findComponent(RunnerCreateForm);
const createComponent = () => { const createComponent = () => {
trackingSpy = mockTracking(undefined, window.document, jest.spyOn);
wrapper = shallowMountExtended(GroupRunnerRunnerApp, { wrapper = shallowMountExtended(GroupRunnerRunnerApp, {
propsData: { propsData: {
groupId: mockGroupId, groupId: mockGroupId,
...@@ -84,6 +88,14 @@ describe('GroupRunnerRunnerApp', () => { ...@@ -84,6 +88,14 @@ describe('GroupRunnerRunnerApp', () => {
}); });
}); });
it('tracks that create runner button has been clicked', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'click_create_group_runner_button',
expect.any(Object),
);
});
it('redirects to the registration page', () => { it('redirects to the registration page', () => {
const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${DEFAULT_PLATFORM}`; const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${DEFAULT_PLATFORM}`;
...@@ -104,6 +116,21 @@ describe('GroupRunnerRunnerApp', () => { ...@@ -104,6 +116,21 @@ describe('GroupRunnerRunnerApp', () => {
}); });
}); });
describe('When Google Cloud platform is selected and a runner is saved', () => {
beforeEach(() => {
findRunnerPlatformsRadioGroup().vm.$emit('input', GOOGLE_CLOUD_PLATFORM);
findRunnerCreateForm().vm.$emit('saved', mockCreatedRunner);
});
it('tracks that runner was provisioned on Google Cloud', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'provision_group_runner_on_google_cloud',
expect.any(Object),
);
});
});
describe('When runner fails to save', () => { describe('When runner fails to save', () => {
const ERROR_MSG = 'Cannot save!'; const ERROR_MSG = 'Cannot save!';
......
...@@ -4,7 +4,9 @@ import { GlButton } from '@gitlab/ui'; ...@@ -4,7 +4,9 @@ import { GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import setWindowLocation from 'helpers/set_window_location_helper'; import setWindowLocation from 'helpers/set_window_location_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { mockTracking } from 'helpers/tracking_helper';
import { InternalEvents } from '~/tracking';
import { updateHistory } from '~/lib/utils/url_utility'; import { updateHistory } from '~/lib/utils/url_utility';
import { import {
PARAM_KEY_PLATFORM, PARAM_KEY_PLATFORM,
...@@ -29,6 +31,7 @@ jest.mock('~/lib/utils/url_utility', () => ({ ...@@ -29,6 +31,7 @@ jest.mock('~/lib/utils/url_utility', () => ({
describe('GroupRegisterRunnerApp', () => { describe('GroupRegisterRunnerApp', () => {
let wrapper; let wrapper;
let trackingSpy;
const findCloudRegistrationInstructions = () => const findCloudRegistrationInstructions = () =>
wrapper.findComponent(GoogleCloudRegistrationInstructions); wrapper.findComponent(GoogleCloudRegistrationInstructions);
...@@ -37,6 +40,7 @@ describe('GroupRegisterRunnerApp', () => { ...@@ -37,6 +40,7 @@ describe('GroupRegisterRunnerApp', () => {
const findBtn = () => wrapper.findComponent(GlButton); const findBtn = () => wrapper.findComponent(GlButton);
const createComponent = (googleCloudSupportFeatureFlag = false) => { const createComponent = (googleCloudSupportFeatureFlag = false) => {
trackingSpy = mockTracking(undefined, window.document, jest.spyOn);
wrapper = shallowMountExtended(GroupRegisterRunnerApp, { wrapper = shallowMountExtended(GroupRegisterRunnerApp, {
propsData: { propsData: {
runnerId: mockRunnerId, runnerId: mockRunnerId,
...@@ -73,9 +77,28 @@ describe('GroupRegisterRunnerApp', () => { ...@@ -73,9 +77,28 @@ describe('GroupRegisterRunnerApp', () => {
it('shows runner list button', () => { it('shows runner list button', () => {
expect(findBtn().attributes('href')).toBe(mockRunnersPath); expect(findBtn().attributes('href')).toBe(mockRunnersPath);
expect(findBtn().attributes('data-event-tracking')).toBe(
'click_view_runners_button_in_new_group_runner_form',
);
expect(findBtn().props('variant')).toBe('confirm'); expect(findBtn().props('variant')).toBe('confirm');
}); });
}); });
describe('when runners list button is clicked', () => {
beforeEach(async () => {
InternalEvents.bindInternalEventDocument(findBtn().element);
await findBtn().trigger('click');
await nextTick();
});
it('tracks that view runners button has been clicked', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'click_view_runners_button_in_new_group_runner_form',
expect.any(Object),
);
});
});
}); });
describe('When another platform has been selected', () => { describe('When another platform has been selected', () => {
......
import { GlSprintf } from '@gitlab/ui'; import { GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { mockTracking } from 'helpers/tracking_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createAlert, VARIANT_SUCCESS } from '~/alert'; import { createAlert, VARIANT_SUCCESS } from '~/alert';
...@@ -12,6 +13,7 @@ import { ...@@ -12,6 +13,7 @@ import {
PARAM_KEY_PLATFORM, PARAM_KEY_PLATFORM,
PROJECT_TYPE, PROJECT_TYPE,
DEFAULT_PLATFORM, DEFAULT_PLATFORM,
GOOGLE_CLOUD_PLATFORM,
WINDOWS_PLATFORM, WINDOWS_PLATFORM,
} from '~/ci/runner/constants'; } from '~/ci/runner/constants';
import RunnerCreateForm from '~/ci/runner/components/runner_create_form.vue'; import RunnerCreateForm from '~/ci/runner/components/runner_create_form.vue';
...@@ -31,6 +33,7 @@ const mockCreatedRunner = runnerCreateResult.data.runnerCreate.runner; ...@@ -31,6 +33,7 @@ const mockCreatedRunner = runnerCreateResult.data.runnerCreate.runner;
describe('ProjectRunnerRunnerApp', () => { describe('ProjectRunnerRunnerApp', () => {
let wrapper; let wrapper;
let trackingSpy;
const findRunnerPlatformsRadioGroup = () => wrapper.findComponent(RunnerPlatformsRadioGroup); const findRunnerPlatformsRadioGroup = () => wrapper.findComponent(RunnerPlatformsRadioGroup);
const findRegistrationCompatibilityAlert = () => const findRegistrationCompatibilityAlert = () =>
...@@ -38,6 +41,7 @@ describe('ProjectRunnerRunnerApp', () => { ...@@ -38,6 +41,7 @@ describe('ProjectRunnerRunnerApp', () => {
const findRunnerCreateForm = () => wrapper.findComponent(RunnerCreateForm); const findRunnerCreateForm = () => wrapper.findComponent(RunnerCreateForm);
const createComponent = () => { const createComponent = () => {
trackingSpy = mockTracking(undefined, window.document, jest.spyOn);
wrapper = shallowMountExtended(ProjectRunnerRunnerApp, { wrapper = shallowMountExtended(ProjectRunnerRunnerApp, {
propsData: { propsData: {
projectId: mockProjectId, projectId: mockProjectId,
...@@ -85,6 +89,14 @@ describe('ProjectRunnerRunnerApp', () => { ...@@ -85,6 +89,14 @@ describe('ProjectRunnerRunnerApp', () => {
}); });
}); });
it('tracks that create runner button has been clicked', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'click_create_project_runner_button',
expect.any(Object),
);
});
it('redirects to the registration page', () => { it('redirects to the registration page', () => {
const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${DEFAULT_PLATFORM}`; const url = `${mockCreatedRunner.ephemeralRegisterUrl}?${PARAM_KEY_PLATFORM}=${DEFAULT_PLATFORM}`;
...@@ -105,6 +117,21 @@ describe('ProjectRunnerRunnerApp', () => { ...@@ -105,6 +117,21 @@ describe('ProjectRunnerRunnerApp', () => {
}); });
}); });
describe('When Google Cloud platform is selected and a runner is saved', () => {
beforeEach(() => {
findRunnerPlatformsRadioGroup().vm.$emit('input', GOOGLE_CLOUD_PLATFORM);
findRunnerCreateForm().vm.$emit('saved', mockCreatedRunner);
});
it('tracks that runner was provisioned on Google Cloud', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'provision_project_runner_on_google_cloud',
expect.any(Object),
);
});
});
describe('When runner fails to save', () => { describe('When runner fails to save', () => {
const ERROR_MSG = 'Cannot save!'; const ERROR_MSG = 'Cannot save!';
......
...@@ -4,7 +4,9 @@ import { GlButton } from '@gitlab/ui'; ...@@ -4,7 +4,9 @@ import { GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import setWindowLocation from 'helpers/set_window_location_helper'; import setWindowLocation from 'helpers/set_window_location_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { mockTracking } from 'helpers/tracking_helper';
import { InternalEvents } from '~/tracking';
import { updateHistory } from '~/lib/utils/url_utility'; import { updateHistory } from '~/lib/utils/url_utility';
import { import {
PARAM_KEY_PLATFORM, PARAM_KEY_PLATFORM,
...@@ -29,6 +31,7 @@ jest.mock('~/lib/utils/url_utility', () => ({ ...@@ -29,6 +31,7 @@ jest.mock('~/lib/utils/url_utility', () => ({
describe('ProjectRegisterRunnerApp', () => { describe('ProjectRegisterRunnerApp', () => {
let wrapper; let wrapper;
let trackingSpy;
const findCloudRegistrationInstructions = () => const findCloudRegistrationInstructions = () =>
wrapper.findComponent(GoogleCloudRegistrationInstructions); wrapper.findComponent(GoogleCloudRegistrationInstructions);
...@@ -37,6 +40,7 @@ describe('ProjectRegisterRunnerApp', () => { ...@@ -37,6 +40,7 @@ describe('ProjectRegisterRunnerApp', () => {
const findBtn = () => wrapper.findComponent(GlButton); const findBtn = () => wrapper.findComponent(GlButton);
const createComponent = (googleCloudSupportFeatureFlag = false) => { const createComponent = (googleCloudSupportFeatureFlag = false) => {
trackingSpy = mockTracking(undefined, window.document, jest.spyOn);
wrapper = shallowMountExtended(ProjectRegisterRunnerApp, { wrapper = shallowMountExtended(ProjectRegisterRunnerApp, {
propsData: { propsData: {
runnerId: mockRunnerId, runnerId: mockRunnerId,
...@@ -73,9 +77,28 @@ describe('ProjectRegisterRunnerApp', () => { ...@@ -73,9 +77,28 @@ describe('ProjectRegisterRunnerApp', () => {
it('shows runner list button', () => { it('shows runner list button', () => {
expect(findBtn().attributes('href')).toBe(mockRunnersPath); expect(findBtn().attributes('href')).toBe(mockRunnersPath);
expect(findBtn().attributes('data-event-tracking')).toBe(
'click_view_runners_button_in_new_project_runner_form',
);
expect(findBtn().props('variant')).toBe('confirm'); expect(findBtn().props('variant')).toBe('confirm');
}); });
}); });
describe('when runners list button is clicked', () => {
beforeEach(async () => {
InternalEvents.bindInternalEventDocument(findBtn().element);
await findBtn().trigger('click');
await nextTick();
});
it('tracks that view runners button has been clicked', () => {
expect(trackingSpy).toHaveBeenCalledWith(
undefined,
'click_view_runners_button_in_new_project_runner_form',
expect.any(Object),
);
});
});
}); });
describe('When another platform has been selected', () => { describe('When another platform has been selected', () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册