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`
|
2022-07-23 23:45:48 +05:30
|
|
|
attentionRequested | selected
|
|
|
|
${true} | ${true}
|
|
|
|
${false} | ${false}
|
2021-12-11 22:18:48 +05:30
|
|
|
`(
|
2022-07-23 23:45:48 +05:30
|
|
|
'renders button with as selected when $selected when attention_requested is $attentionRequested',
|
|
|
|
({ attentionRequested, selected }) => {
|
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
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(findToggle().props('selected')).toBe(selected);
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
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-07-16 23:28:13 +05:30
|
|
|
direction: 'remove',
|
2021-12-11 22:18:48 +05:30
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
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
|
2022-07-16 23:28:13 +05:30
|
|
|
${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequest} | ${true}
|
|
|
|
${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.addAttentionRequest} | ${true}
|
|
|
|
${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.addAttentionRequest} | ${true}
|
2022-05-07 20:08:51 +05:30
|
|
|
${'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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|