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

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

109 lines
3 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlToggle } from '@gitlab/ui';
2023-06-20 00:43:36 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { mockTracking } from 'helpers/tracking_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;
2023-06-20 00:43:36 +05:30
let trackingSpy;
2020-05-24 23:13:21 +05:30
2021-03-11 19:13:27 +05:30
const findToggleButton = () => wrapper.findComponent(GlToggle);
2023-06-20 00:43:36 +05:30
const findTooltip = () => wrapper.findComponent({ ref: 'tooltip' });
2020-05-24 23:13:21 +05:30
2023-06-20 00:43:36 +05:30
const mountComponent = (propsData) => {
wrapper = shallowMountExtended(Subscriptions, {
propsData,
});
};
2020-05-24 23:13:21 +05:30
it('shows loading spinner when loading', () => {
2023-06-20 00:43:36 +05:30
mountComponent({
2020-05-24 23:13:21 +05:30
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', () => {
2023-06-20 00:43:36 +05:30
mountComponent({
2020-05-24 23:13:21 +05:30
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', () => {
2023-06-20 00:43:36 +05:30
mountComponent({
2020-05-24 23:13:21 +05:30
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;
2023-06-20 00:43:36 +05:30
mountComponent({ subscribed: true, id });
2020-05-24 23:13:21 +05:30
const eventHubSpy = jest.spyOn(eventHub, '$emit');
2023-06-20 00:43:36 +05:30
findToggleButton().vm.$emit('change');
2020-05-24 23:13:21 +05:30
expect(eventHubSpy).toHaveBeenCalledWith('toggleSubscription', id);
2023-06-20 00:43:36 +05:30
expect(wrapper.emitted('toggleSubscription')).toEqual([[id]]);
2020-05-24 23:13:21 +05:30
});
it('tracks the event when toggled', () => {
2023-06-20 00:43:36 +05:30
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
mountComponent({ subscribed: true });
2020-05-24 23:13:21 +05:30
2023-06-20 00:43:36 +05:30
findToggleButton().vm.$emit('change');
2020-05-24 23:13:21 +05:30
2023-06-20 00:43:36 +05:30
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'toggle_button', {
category: undefined,
label: 'right_sidebar',
2020-05-24 23:13:21 +05:30
property: 'notifications',
value: 0,
});
});
it('onClickCollapsedIcon method emits `toggleSidebar` event on component', () => {
2023-06-20 00:43:36 +05:30
mountComponent({ subscribed: true });
findTooltip().trigger('click');
2020-05-24 23:13:21 +05:30
2023-06-20 00:43:36 +05:30
expect(wrapper.emitted('toggleSidebar')).toHaveLength(1);
2020-05-24 23:13:21 +05:30
});
2021-04-17 20:07:23 +05:30
it('has visually hidden label', () => {
2023-06-20 00:43:36 +05:30
mountComponent();
2021-04-17 20:07:23 +05:30
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(() => {
2023-06-20 00:43:36 +05:30
mountComponent({
2020-05-24 23:13:21 +05:30
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,
);
2023-06-20 00:43:36 +05:30
expect(findTooltip().attributes('title')).toBe(subscribeDisabledDescription);
2020-05-24 23:13:21 +05:30
});
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
});
});
});