debian-mirror-gitlab/spec/javascripts/sidebar/subscriptions_spec.js

101 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2019-12-21 20:55:43 +05:30
import { mockTracking } from 'spec/helpers/tracking_helper';
2020-01-01 13:55:28 +05:30
import subscriptions from '~/sidebar/components/subscriptions/subscriptions.vue';
import eventHub from '~/sidebar/event_hub';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
describe('Subscriptions', function() {
2018-03-17 18:26:18 +05:30
let vm;
let Subscriptions;
beforeEach(() => {
Subscriptions = Vue.extend(subscriptions);
});
afterEach(() => {
vm.$destroy();
});
it('shows loading spinner when loading', () => {
vm = mountComponent(Subscriptions, {
loading: true,
subscribed: undefined,
});
expect(vm.$refs.toggleButton.isLoading).toBe(true);
2018-12-13 13:39:08 +05:30
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass(
'is-loading',
);
2018-03-17 18:26:18 +05:30
});
it('is toggled "off" when currently not subscribed', () => {
vm = mountComponent(Subscriptions, {
subscribed: false,
});
2018-12-13 13:39:08 +05:30
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).not.toHaveClass(
'is-checked',
);
2018-03-17 18:26:18 +05:30
});
it('is toggled "on" when currently subscribed', () => {
vm = mountComponent(Subscriptions, {
subscribed: true,
});
2018-12-13 13:39:08 +05:30
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass(
'is-checked',
);
2018-03-17 18:26:18 +05:30
});
2018-10-15 14:42:47 +05:30
it('toggleSubscription method emits `toggleSubscription` event on eventHub and Component', () => {
vm = mountComponent(Subscriptions, { subscribed: true });
spyOn(eventHub, '$emit');
spyOn(vm, '$emit');
2019-12-21 20:55:43 +05:30
spyOn(vm, 'track');
2018-10-15 14:42:47 +05:30
vm.toggleSubscription();
2018-12-13 13:39:08 +05:30
2018-10-15 14:42:47 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object));
expect(vm.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object));
});
2019-12-21 20:55:43 +05:30
it('tracks the event when toggled', () => {
2019-12-04 20:38:33 +05:30
vm = mountComponent(Subscriptions, { subscribed: true });
2019-12-21 20:55:43 +05:30
const spy = mockTracking('_category_', vm.$el, spyOn);
2019-12-04 20:38:33 +05:30
vm.toggleSubscription();
2019-12-21 20:55:43 +05:30
expect(spy).toHaveBeenCalled();
2019-12-04 20:38:33 +05:30
});
2018-10-15 14:42:47 +05:30
it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => {
vm = mountComponent(Subscriptions, { subscribed: true });
spyOn(vm, '$emit');
vm.onClickCollapsedIcon();
2018-12-13 13:39:08 +05:30
2018-10-15 14:42:47 +05:30
expect(vm.$emit).toHaveBeenCalledWith('toggleSidebar');
});
2019-12-26 22:10:19 +05:30
describe('given project emails are disabled', () => {
const subscribeDisabledDescription = 'Notifications have been disabled';
beforeEach(() => {
vm = mountComponent(Subscriptions, {
subscribed: false,
projectEmailsDisabled: true,
subscribeDisabledDescription,
});
});
it('sets the correct display text', () => {
expect(vm.$el.textContent).toContain(subscribeDisabledDescription);
expect(vm.$refs.tooltip.dataset.originalTitle).toBe(subscribeDisabledDescription);
});
it('does not render the toggle button', () => {
expect(vm.$refs.toggleButton).toBeUndefined();
});
});
2018-03-17 18:26:18 +05:30
});