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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

121 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlToggle } from '@gitlab/ui';
2020-05-24 23:13:21 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2020-05-24 23:13:21 +05:30
import Subscriptions from '~/sidebar/components/subscriptions/subscriptions.vue';
import eventHub from '~/sidebar/event_hub';
describe('Subscriptions', () => {
let wrapper;
2021-03-11 19:13:27 +05:30
const findToggleButton = () => wrapper.findComponent(GlToggle);
2020-05-24 23:13:21 +05:30
2021-03-08 18:12:59 +05:30
const mountComponent = (propsData) =>
2021-03-11 19:13:27 +05:30
extendedWrapper(
shallowMount(Subscriptions, {
propsData,
}),
);
2020-05-24 23:13:21 +05:30
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
it('shows loading spinner when loading', () => {
wrapper = mountComponent({
loading: true,
subscribed: undefined,
});
2021-03-11 19:13:27 +05:30
expect(findToggleButton().props('isLoading')).toBe(true);
2020-05-24 23:13:21 +05:30
});
it('is toggled "off" when currently not subscribed', () => {
wrapper = mountComponent({
subscribed: false,
});
2021-03-11 19:13:27 +05:30
expect(findToggleButton().props('value')).toBe(false);
2020-05-24 23:13:21 +05:30
});
it('is toggled "on" when currently subscribed', () => {
wrapper = mountComponent({
subscribed: true,
});
2021-03-11 19:13:27 +05:30
expect(findToggleButton().props('value')).toBe(true);
2020-05-24 23:13:21 +05:30
});
it('toggleSubscription method emits `toggleSubscription` event on eventHub and Component', () => {
const id = 42;
wrapper = mountComponent({ subscribed: true, id });
const eventHubSpy = jest.spyOn(eventHub, '$emit');
const wrapperEmitSpy = jest.spyOn(wrapper.vm, '$emit');
wrapper.vm.toggleSubscription();
expect(eventHubSpy).toHaveBeenCalledWith('toggleSubscription', id);
expect(wrapperEmitSpy).toHaveBeenCalledWith('toggleSubscription', id);
eventHubSpy.mockRestore();
wrapperEmitSpy.mockRestore();
});
it('tracks the event when toggled', () => {
wrapper = mountComponent({ subscribed: true });
const wrapperTrackSpy = jest.spyOn(wrapper.vm, 'track');
wrapper.vm.toggleSubscription();
expect(wrapperTrackSpy).toHaveBeenCalledWith('toggle_button', {
property: 'notifications',
value: 0,
});
wrapperTrackSpy.mockRestore();
});
it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => {
wrapper = mountComponent({ subscribed: true });
const spy = jest.spyOn(wrapper.vm, '$emit');
wrapper.vm.onClickCollapsedIcon();
expect(spy).toHaveBeenCalledWith('toggleSidebar');
spy.mockRestore();
});
2021-04-17 20:07:23 +05:30
it('has visually hidden label', () => {
wrapper = mountComponent();
expect(findToggleButton().props()).toMatchObject({
label: 'Notifications',
labelPosition: 'hidden',
});
});
2020-05-24 23:13:21 +05:30
describe('given project emails are disabled', () => {
const subscribeDisabledDescription = 'Notifications have been disabled';
beforeEach(() => {
wrapper = mountComponent({
subscribed: false,
projectEmailsDisabled: true,
subscribeDisabledDescription,
});
});
it('sets the correct display text', () => {
2021-03-11 19:13:27 +05:30
expect(wrapper.findByTestId('subscription-title').text()).toContain(
subscribeDisabledDescription,
);
2021-01-29 00:20:46 +05:30
expect(wrapper.find({ ref: 'tooltip' }).attributes('title')).toBe(
2020-05-24 23:13:21 +05:30
subscribeDisabledDescription,
);
});
it('does not render the toggle button', () => {
2021-03-11 19:13:27 +05:30
expect(findToggleButton().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
});
});
});