2021-06-29 12:08:48 +00:00
|
|
|
import '~/commons';
|
2021-04-07 12:08:53 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-06-29 12:08:48 +00:00
|
|
|
import { mockTracking } from 'helpers/tracking_helper';
|
2021-04-07 12:08:53 +00:00
|
|
|
import PipelinesCiTemplate from '~/pipelines/components/pipelines_list/pipelines_ci_templates.vue';
|
|
|
|
|
2021-06-29 12:08:48 +00:00
|
|
|
const pipelineEditorPath = '/-/ci/editor';
|
2021-04-13 06:11:22 +00:00
|
|
|
const suggestedCiTemplates = [
|
|
|
|
{ name: 'Android', logo: '/assets/illustrations/logos/android.svg' },
|
|
|
|
{ name: 'Bash', logo: '/assets/illustrations/logos/bash.svg' },
|
|
|
|
{ name: 'C++', logo: '/assets/illustrations/logos/c_plus_plus.svg' },
|
|
|
|
];
|
2021-04-07 12:08:53 +00:00
|
|
|
|
|
|
|
describe('Pipelines CI Templates', () => {
|
|
|
|
let wrapper;
|
2021-06-29 12:08:48 +00:00
|
|
|
let trackingSpy;
|
2021-04-09 18:09:24 +00:00
|
|
|
|
2021-04-07 12:08:53 +00:00
|
|
|
const createWrapper = () => {
|
|
|
|
return shallowMount(PipelinesCiTemplate, {
|
|
|
|
provide: {
|
2021-06-29 12:08:48 +00:00
|
|
|
pipelineEditorPath,
|
2021-04-13 06:11:22 +00:00
|
|
|
suggestedCiTemplates,
|
2021-04-07 12:08:53 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-09 18:09:24 +00:00
|
|
|
const findTestTemplateLinks = () => wrapper.findAll('[data-testid="test-template-link"]');
|
2021-04-07 12:08:53 +00:00
|
|
|
const findTemplateDescriptions = () => wrapper.findAll('[data-testid="template-description"]');
|
|
|
|
const findTemplateLinks = () => wrapper.findAll('[data-testid="template-link"]');
|
2021-04-09 18:09:24 +00:00
|
|
|
const findTemplateNames = () => wrapper.findAll('[data-testid="template-name"]');
|
2021-04-07 12:08:53 +00:00
|
|
|
const findTemplateLogos = () => wrapper.findAll('[data-testid="template-logo"]');
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2021-04-09 18:09:24 +00:00
|
|
|
describe('renders test template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper();
|
|
|
|
});
|
|
|
|
|
2021-06-29 12:08:48 +00:00
|
|
|
it('links to the getting started template', () => {
|
2021-04-09 18:09:24 +00:00
|
|
|
expect(findTestTemplateLinks().at(0).attributes('href')).toBe(
|
2021-06-29 12:08:48 +00:00
|
|
|
pipelineEditorPath.concat('?template=Getting-Started'),
|
2021-04-09 18:09:24 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renders template list', () => {
|
2021-04-07 12:08:53 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all suggested templates', () => {
|
|
|
|
const content = wrapper.text();
|
|
|
|
|
2021-04-13 06:11:22 +00:00
|
|
|
expect(content).toContain('Android', 'Bash', 'C++');
|
2021-04-07 12:08:53 +00:00
|
|
|
});
|
|
|
|
|
2021-04-09 18:09:24 +00:00
|
|
|
it('has the correct template name', () => {
|
|
|
|
expect(findTemplateNames().at(0).text()).toBe('Android');
|
|
|
|
});
|
|
|
|
|
2021-04-07 12:08:53 +00:00
|
|
|
it('links to the correct template', () => {
|
2021-04-09 18:09:24 +00:00
|
|
|
expect(findTemplateLinks().at(0).attributes('href')).toBe(
|
2021-06-29 12:08:48 +00:00
|
|
|
pipelineEditorPath.concat('?template=Android'),
|
2021-04-07 12:08:53 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the description of the template', () => {
|
2021-04-09 18:09:24 +00:00
|
|
|
expect(findTemplateDescriptions().at(0).text()).toBe(
|
|
|
|
'CI/CD template to test and deploy your Android project.',
|
2021-04-07 12:08:53 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the right logo of the template', () => {
|
2021-04-09 18:09:24 +00:00
|
|
|
expect(findTemplateLogos().at(0).attributes('src')).toBe(
|
2021-04-07 12:08:53 +00:00
|
|
|
'/assets/illustrations/logos/android.svg',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-04-13 12:11:32 +00:00
|
|
|
|
|
|
|
describe('tracking', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper();
|
2021-06-29 12:08:48 +00:00
|
|
|
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
|
2021-04-13 12:11:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sends an event when template is clicked', () => {
|
|
|
|
findTemplateLinks().at(0).vm.$emit('click');
|
|
|
|
|
2021-06-29 12:08:48 +00:00
|
|
|
expect(trackingSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', {
|
2021-04-13 12:11:32 +00:00
|
|
|
label: 'Android',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-29 12:08:48 +00:00
|
|
|
it('sends an event when Getting-Started template is clicked', () => {
|
2021-04-13 12:11:32 +00:00
|
|
|
findTestTemplateLinks().at(0).vm.$emit('click');
|
|
|
|
|
2021-06-29 12:08:48 +00:00
|
|
|
expect(trackingSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', {
|
|
|
|
label: 'Getting-Started',
|
2021-04-13 12:11:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-04-07 12:08:53 +00:00
|
|
|
});
|