gitlab-org--gitlab-foss/spec/javascripts/sidebar/subscriptions_spec.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-10-31 16:15:03 +00:00
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';
2017-10-31 16:15:03 +00:00
2018-10-17 07:13:26 +00:00
describe('Subscriptions', function() {
2017-10-31 16:15:03 +00:00
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,
});
2018-01-12 05:45:54 +00:00
expect(vm.$refs.toggleButton.isLoading).toBe(true);
2018-10-17 07:13:26 +00:00
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass(
'is-loading',
);
2017-10-31 16:15:03 +00:00
});
2018-01-12 05:45:54 +00:00
it('is toggled "off" when currently not subscribed', () => {
2017-10-31 16:15:03 +00:00
vm = mountComponent(Subscriptions, {
subscribed: false,
});
2018-10-17 07:13:26 +00:00
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).not.toHaveClass(
'is-checked',
);
2017-10-31 16:15:03 +00:00
});
2018-01-12 05:45:54 +00:00
it('is toggled "on" when currently subscribed', () => {
2017-10-31 16:15:03 +00:00
vm = mountComponent(Subscriptions, {
subscribed: true,
});
2018-10-17 07:13:26 +00:00
expect(vm.$refs.toggleButton.$el.querySelector('.project-feature-toggle')).toHaveClass(
'is-checked',
);
2017-10-31 16:15:03 +00:00
});
it('toggleSubscription method emits `toggleSubscription` event on eventHub and Component', () => {
vm = mountComponent(Subscriptions, { subscribed: true });
spyOn(eventHub, '$emit');
spyOn(vm, '$emit');
vm.toggleSubscription();
2018-10-09 18:03:09 +00:00
expect(eventHub.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object));
expect(vm.$emit).toHaveBeenCalledWith('toggleSubscription', jasmine.any(Object));
});
it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => {
vm = mountComponent(Subscriptions, { subscribed: true });
spyOn(vm, '$emit');
vm.onClickCollapsedIcon();
2018-10-09 18:03:09 +00:00
expect(vm.$emit).toHaveBeenCalledWith('toggleSidebar');
});
2017-10-31 16:15:03 +00:00
});