debian-mirror-gitlab/spec/frontend/alerts_settings/components/alerts_integrations_list_spec.js

119 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlTable, GlIcon, GlButton } from '@gitlab/ui';
2021-01-03 14:25:43 +05:30
import { mount } from '@vue/test-utils';
2021-01-29 00:20:46 +05:30
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
2021-01-03 14:25:43 +05:30
import AlertIntegrationsList, {
i18n,
} from '~/alerts_settings/components/alerts_integrations_list.vue';
2021-01-29 00:20:46 +05:30
import { trackAlertIntegrationsViewsOptions } from '~/alerts_settings/constants';
2021-03-11 19:13:27 +05:30
import Tracking from '~/tracking';
2021-01-03 14:25:43 +05:30
const mockIntegrations = [
{
2021-01-29 00:20:46 +05:30
id: '1',
active: true,
2021-01-03 14:25:43 +05:30
name: 'Integration 1',
type: 'HTTP endpoint',
},
{
2021-01-29 00:20:46 +05:30
id: '2',
active: false,
2021-01-03 14:25:43 +05:30
name: 'Integration 2',
type: 'HTTP endpoint',
},
];
describe('AlertIntegrationsList', () => {
let wrapper;
2021-01-29 00:20:46 +05:30
const { trigger: triggerIntersection } = useMockIntersectionObserver();
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
function mountComponent({ data = {}, props = {} } = {}) {
2021-01-03 14:25:43 +05:30
wrapper = mount(AlertIntegrationsList, {
2021-01-29 00:20:46 +05:30
data() {
return { ...data };
},
2021-01-03 14:25:43 +05:30
propsData: {
integrations: mockIntegrations,
2021-01-29 00:20:46 +05:30
...props,
},
2021-01-03 14:25:43 +05:30
stubs: {
GlIcon: true,
2021-01-29 00:20:46 +05:30
GlButton: true,
2021-01-03 14:25:43 +05:30
},
});
}
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
beforeEach(() => {
mountComponent();
});
const findTableComponent = () => wrapper.find(GlTable);
2021-01-29 00:20:46 +05:30
const findTableComponentRows = () => wrapper.find(GlTable).findAll('table tbody tr');
2021-01-03 14:25:43 +05:30
const finsStatusCell = () => wrapper.findAll('[data-testid="integration-activated-status"]');
it('renders a table', () => {
expect(findTableComponent().exists()).toBe(true);
});
it('renders an empty state when no integrations provided', () => {
2021-01-29 00:20:46 +05:30
mountComponent({ props: { integrations: [] } });
2021-01-03 14:25:43 +05:30
expect(findTableComponent().text()).toContain(i18n.emptyState);
});
2021-01-29 00:20:46 +05:30
it('renders an an edit and delete button for each integration', () => {
expect(findTableComponent().findAll(GlButton).length).toBe(4);
});
it('renders an highlighted row when a current integration is selected to edit', () => {
mountComponent({ data: { currentIntegration: { id: '1' } } });
2021-03-08 18:12:59 +05:30
expect(findTableComponentRows().at(0).classes()).toContain('gl-bg-blue-50');
2021-01-29 00:20:46 +05:30
});
2021-01-03 14:25:43 +05:30
describe('integration status', () => {
it('enabled', () => {
const cell = finsStatusCell().at(0);
const activatedIcon = cell.find(GlIcon);
expect(cell.text()).toBe(i18n.status.enabled.name);
expect(activatedIcon.attributes('name')).toBe('check-circle-filled');
expect(activatedIcon.attributes('title')).toBe(i18n.status.enabled.tooltip);
});
it('disabled', () => {
const cell = finsStatusCell().at(1);
const notActivatedIcon = cell.find(GlIcon);
expect(cell.text()).toBe(i18n.status.disabled.name);
expect(notActivatedIcon.attributes('name')).toBe('warning-solid');
expect(notActivatedIcon.attributes('title')).toBe(i18n.status.disabled.tooltip);
});
});
describe('Snowplow tracking', () => {
beforeEach(() => {
mountComponent();
2021-01-29 00:20:46 +05:30
jest.spyOn(Tracking, 'event');
});
it('should NOT track alert list page views when list is collapsed', () => {
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: false } });
expect(Tracking.event).not.toHaveBeenCalled();
2021-01-03 14:25:43 +05:30
});
2021-01-29 00:20:46 +05:30
it('should track alert list page views only once when list is expanded', () => {
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
const { category, action } = trackAlertIntegrationsViewsOptions;
expect(Tracking.event).toHaveBeenCalledTimes(1);
2021-01-03 14:25:43 +05:30
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
});
});