2017-05-22 19:20:15 -04:00
|
|
|
import Vue from 'vue';
|
2017-06-22 12:08:48 -04:00
|
|
|
import eventHub from '~/groups/event_hub';
|
2017-05-25 20:49:46 -04:00
|
|
|
import groupFolderComponent from '~/groups/components/group_folder.vue';
|
|
|
|
import groupItemComponent from '~/groups/components/group_item.vue';
|
2017-05-22 19:20:15 -04:00
|
|
|
import groupsComponent from '~/groups/components/groups.vue';
|
|
|
|
import GroupsStore from '~/groups/stores/groups_store';
|
2017-05-25 20:49:46 -04:00
|
|
|
import { groupsData } from './mock_data';
|
2017-05-22 19:20:15 -04:00
|
|
|
|
2017-06-07 04:45:48 -04:00
|
|
|
describe('Groups Component', () => {
|
2017-05-22 19:20:15 -04:00
|
|
|
let GroupsComponent;
|
|
|
|
let store;
|
2017-05-25 20:49:46 -04:00
|
|
|
let component;
|
|
|
|
let groups;
|
2017-05-22 19:20:15 -04:00
|
|
|
|
2017-05-25 20:49:46 -04:00
|
|
|
beforeEach((done) => {
|
|
|
|
Vue.component('group-folder', groupFolderComponent);
|
|
|
|
Vue.component('group-item', groupItemComponent);
|
2017-05-22 19:20:15 -04:00
|
|
|
|
|
|
|
store = new GroupsStore();
|
2017-05-25 20:49:46 -04:00
|
|
|
groups = store.setGroups(groupsData.groups);
|
|
|
|
|
2017-05-22 19:20:15 -04:00
|
|
|
store.storePagination(groupsData.pagination);
|
|
|
|
|
|
|
|
GroupsComponent = Vue.extend(groupsComponent);
|
2017-05-25 20:49:46 -04:00
|
|
|
|
|
|
|
component = new GroupsComponent({
|
|
|
|
propsData: {
|
|
|
|
groups: store.state.groups,
|
|
|
|
pageInfo: store.state.pageInfo,
|
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
done();
|
|
|
|
});
|
2017-05-22 19:20:15 -04:00
|
|
|
});
|
|
|
|
|
2017-06-07 11:05:17 -04:00
|
|
|
afterEach(() => {
|
|
|
|
component.$destroy();
|
|
|
|
});
|
|
|
|
|
2017-05-22 19:20:15 -04:00
|
|
|
describe('with data', () => {
|
2017-05-25 20:49:46 -04:00
|
|
|
it('should render a list of groups', () => {
|
|
|
|
expect(component.$el.classList.contains('groups-list-tree-container')).toBe(true);
|
|
|
|
expect(component.$el.querySelector('#group-12')).toBeDefined();
|
|
|
|
expect(component.$el.querySelector('#group-1119')).toBeDefined();
|
|
|
|
expect(component.$el.querySelector('#group-1120')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2017-06-22 12:08:48 -04:00
|
|
|
it('should respect the order of groups', () => {
|
|
|
|
const wrap = component.$el.querySelector('.groups-list-tree-container > .group-list-tree');
|
|
|
|
expect(wrap.querySelector('.group-row:nth-child(1)').id).toBe('group-12');
|
|
|
|
expect(wrap.querySelector('.group-row:nth-child(2)').id).toBe('group-1119');
|
|
|
|
});
|
|
|
|
|
2017-05-25 20:49:46 -04:00
|
|
|
it('should render group and its subgroup', () => {
|
|
|
|
const lists = component.$el.querySelectorAll('.group-list-tree');
|
|
|
|
|
|
|
|
expect(lists.length).toBe(3); // one parent and two subgroups
|
|
|
|
|
|
|
|
expect(lists[0].querySelector('#group-1119').classList.contains('is-open')).toBe(true);
|
2017-05-30 05:26:46 -04:00
|
|
|
expect(lists[0].querySelector('#group-1119').classList.contains('has-subgroups')).toBe(true);
|
2017-05-25 20:49:46 -04:00
|
|
|
|
2017-06-22 12:08:48 -04:00
|
|
|
expect(lists[2].querySelector('#group-1120').textContent).toContain(groups.id1119.subGroups.id1120.name);
|
2017-05-25 20:49:46 -04:00
|
|
|
});
|
|
|
|
|
2017-07-31 06:35:06 -04:00
|
|
|
it('should render group identicon when group avatar is not present', () => {
|
|
|
|
const avatar = component.$el.querySelector('#group-12 .avatar-container .avatar');
|
|
|
|
expect(avatar.nodeName).toBe('DIV');
|
|
|
|
expect(avatar.classList.contains('identicon')).toBeTruthy();
|
|
|
|
expect(avatar.getAttribute('style').indexOf('background-color') > -1).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render group avatar when group avatar is present', () => {
|
|
|
|
const avatar = component.$el.querySelector('#group-1120 .avatar-container .avatar');
|
|
|
|
expect(avatar.nodeName).toBe('IMG');
|
|
|
|
expect(avatar.classList.contains('identicon')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2017-05-25 20:49:46 -04:00
|
|
|
it('should remove prefix of parent group', () => {
|
|
|
|
expect(component.$el.querySelector('#group-12 #group-1128 .title').textContent).toContain('level2 / level3 / level4');
|
2017-05-22 19:20:15 -04:00
|
|
|
});
|
2017-06-22 12:08:48 -04:00
|
|
|
|
|
|
|
it('should remove the group after leaving the group', (done) => {
|
|
|
|
spyOn(window, 'confirm').and.returnValue(true);
|
|
|
|
|
|
|
|
eventHub.$on('leaveGroup', (group, collection) => {
|
|
|
|
store.removeGroup(group, collection);
|
|
|
|
});
|
|
|
|
|
|
|
|
component.$el.querySelector('#group-12 .leave-group').click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(component.$el.querySelector('#group-12')).toBeNull();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-22 19:20:15 -04:00
|
|
|
});
|
|
|
|
});
|