2023-05-27 22:25:52 +05:30
|
|
|
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Participants from '~/sidebar/components/participants/participants.vue';
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
describe('Participants component', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
let wrapper;
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const participant = {
|
|
|
|
id: 1,
|
|
|
|
state: 'active',
|
|
|
|
username: 'marcene',
|
|
|
|
name: 'Allie Will',
|
|
|
|
web_url: 'foo.com',
|
|
|
|
avatar_url: 'gravatar.com/avatar/xxx',
|
|
|
|
};
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const participants = [participant, { ...participant, id: 2 }, { ...participant, id: 3 }];
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findMoreParticipantsButton = () => wrapper.findComponent(GlButton);
|
|
|
|
const findCollapsedIcon = () => wrapper.find('.sidebar-collapsed-icon');
|
|
|
|
const findParticipantsAuthor = () => wrapper.findAll('.participants-author');
|
|
|
|
|
|
|
|
const mountComponent = (propsData) => shallowMount(Participants, { propsData });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe('collapsed sidebar state', () => {
|
|
|
|
it('shows loading spinner when loading', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ loading: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('does not show loading spinner when not loading', () => {
|
|
|
|
wrapper = mountComponent({ loading: false });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findLoadingIcon().exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows participant count when given', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findCollapsedIcon().text()).toBe(participants.length.toString());
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows full participant count when there are hidden participants', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants: 1 });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findCollapsedIcon().text()).toBe(participants.length.toString());
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('expanded sidebar state', () => {
|
|
|
|
it('shows loading spinner when loading', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ loading: true });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('when only showing visible participants, shows an avatar only for each participant under the limit', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const numberOfLessParticipants = 2;
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants });
|
|
|
|
|
|
|
|
expect(findParticipantsAuthor()).toHaveLength(numberOfLessParticipants);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('when only showing all participants, each has an avatar', async () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants: 2 });
|
|
|
|
|
|
|
|
await findMoreParticipantsButton().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(findParticipantsAuthor()).toHaveLength(participants.length);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not have more participants link when they can all be shown', () => {
|
|
|
|
const numberOfLessParticipants = 100;
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(participants.length).toBeLessThan(numberOfLessParticipants);
|
|
|
|
expect(findMoreParticipantsButton().exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('when too many participants, has more participants link to show more', () => {
|
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants: 2 });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findMoreParticipantsButton().text()).toBe('+ 1 more');
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('when too many participants and already showing them, has more participants link to show less', async () => {
|
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants: 2 });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await findMoreParticipantsButton().vm.$emit('click');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findMoreParticipantsButton().text()).toBe('- show less');
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('clicking on participants icon emits `toggleSidebar` event', () => {
|
|
|
|
wrapper = mountComponent({ participants, numberOfLessParticipants: 2 });
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
findCollapsedIcon().trigger('click');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(wrapper.emitted('toggleSidebar')).toEqual([[]]);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when not showing participants label', () => {
|
|
|
|
beforeEach(() => {
|
2023-05-27 22:25:52 +05:30
|
|
|
wrapper = mountComponent({ participants, showParticipantLabel: false });
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show sidebar collapsed icon', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findCollapsedIcon().exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show participants label title', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find('.title').exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|