debian-mirror-gitlab/spec/frontend/sidebar/components/attention_requested_toggle_spec.js

121 lines
4 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import { GlButton } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import AttentionRequestedToggle from '~/sidebar/components/attention_requested_toggle.vue';
let wrapper;
function factory(propsData = {}) {
wrapper = mount(AttentionRequestedToggle, { propsData });
}
const findToggle = () => wrapper.findComponent(GlButton);
describe('Attention require toggle', () => {
afterEach(() => {
wrapper.destroy();
});
it('renders button', () => {
2022-05-07 20:08:51 +05:30
factory({
type: 'reviewer',
user: { attention_requested: false, can_update_merge_request: true },
});
2021-12-11 22:18:48 +05:30
expect(findToggle().exists()).toBe(true);
});
it.each`
attentionRequested | icon
2022-01-26 12:08:38 +05:30
${true} | ${'attention-solid'}
${false} | ${'attention'}
2021-12-11 22:18:48 +05:30
`(
'renders $icon icon when attention_requested is $attentionRequested',
({ attentionRequested, icon }) => {
2022-05-07 20:08:51 +05:30
factory({
type: 'reviewer',
user: { attention_requested: attentionRequested, can_update_merge_request: true },
});
2021-12-11 22:18:48 +05:30
expect(findToggle().props('icon')).toBe(icon);
},
);
it.each`
attentionRequested | variant
${true} | ${'warning'}
${false} | ${'default'}
`(
'renders button with variant $variant when attention_requested is $attentionRequested',
({ attentionRequested, variant }) => {
2022-05-07 20:08:51 +05:30
factory({
type: 'reviewer',
user: { attention_requested: attentionRequested, can_update_merge_request: true },
});
2021-12-11 22:18:48 +05:30
expect(findToggle().props('variant')).toBe(variant);
},
);
it('emits toggle-attention-requested on click', async () => {
2022-05-07 20:08:51 +05:30
factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: true },
});
2021-12-11 22:18:48 +05:30
await findToggle().trigger('click');
expect(wrapper.emitted('toggle-attention-requested')[0]).toEqual([
{
2022-05-07 20:08:51 +05:30
user: { attention_requested: true, can_update_merge_request: true },
2021-12-11 22:18:48 +05:30
callback: expect.anything(),
},
]);
});
2022-05-07 20:08:51 +05:30
it('does not emit toggle-attention-requested on click if can_update_merge_request is false', async () => {
factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: false },
});
await findToggle().trigger('click');
expect(wrapper.emitted('toggle-attention-requested')).toBe(undefined);
});
2021-12-11 22:18:48 +05:30
it('sets loading on click', async () => {
2022-05-07 20:08:51 +05:30
factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: true },
});
2021-12-11 22:18:48 +05:30
await findToggle().trigger('click');
expect(findToggle().props('loading')).toBe(true);
});
it.each`
2022-05-07 20:08:51 +05:30
type | attentionRequested | tooltip | canUpdateMergeRequest
${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequested} | ${true}
${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedReviewer} | ${true}
${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedAssignee} | ${true}
${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false}
${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.noAttentionRequestedNoPermission} | ${false}
${'assignee'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false}
${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.noAttentionRequestedNoPermission} | ${false}
2021-12-11 22:18:48 +05:30
`(
2022-05-07 20:08:51 +05:30
'sets tooltip as $tooltip when attention_requested is $attentionRequested, type is $type and, can_update_merge_request is $canUpdateMergeRequest',
({ type, attentionRequested, tooltip, canUpdateMergeRequest }) => {
factory({
type,
user: {
attention_requested: attentionRequested,
can_update_merge_request: canUpdateMergeRequest,
},
});
2021-12-11 22:18:48 +05:30
expect(findToggle().attributes('aria-label')).toBe(tooltip);
},
);
});