2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import frequentItemsListItemComponent from '~/frequent_items/components/frequent_items_list_item.vue';
|
2018-03-27 19:54:05 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { mockProject } from '../mock_data'; // can also use 'mockGroup', but not useful to test here
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const createComponent = () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const Component = Vue.extend(frequentItemsListItemComponent);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
return mountComponent(Component, {
|
2018-11-08 19:23:39 +05:30
|
|
|
itemId: mockProject.id,
|
|
|
|
itemName: mockProject.name,
|
2018-03-17 18:26:18 +05:30
|
|
|
namespace: mockProject.namespace,
|
|
|
|
webUrl: mockProject.webUrl,
|
|
|
|
avatarUrl: mockProject.avatarUrl,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('FrequentItemsListItemComponent', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('hasAvatar', () => {
|
|
|
|
it('should return `true` or `false` if whether avatar is present or not', () => {
|
|
|
|
vm.avatarUrl = 'path/to/avatar.png';
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.hasAvatar).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
vm.avatarUrl = null;
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.hasAvatar).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('highlightedItemName', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => {
|
|
|
|
vm.matcher = 'lab';
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.highlightedItemName).toContain('<b>Lab</b>');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should return project name as it is if `matcher` is not available', () => {
|
|
|
|
vm.matcher = null;
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.highlightedItemName).toBe(mockProject.name);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('truncatedNamespace', () => {
|
|
|
|
it('should truncate project name from namespace string', () => {
|
|
|
|
vm.namespace = 'platform / nokia-3310';
|
|
|
|
expect(vm.truncatedNamespace).toBe('platform');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate namespace string from the middle if it includes more than two groups in path', () => {
|
|
|
|
vm.namespace = 'platform / hardware / broadcom / Wifi Group / Mobile Chipset / nokia-3310';
|
|
|
|
expect(vm.truncatedNamespace).toBe('platform / ... / Mobile Chipset');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should render component element', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$el.classList.contains('frequent-items-list-item-container')).toBeTruthy();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelectorAll('a').length).toBe(1);
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(vm.$el.querySelectorAll('.frequent-items-item-avatar-container').length).toBe(1);
|
|
|
|
expect(vm.$el.querySelectorAll('.frequent-items-item-metadata-container').length).toBe(1);
|
|
|
|
expect(vm.$el.querySelectorAll('.frequent-items-item-title').length).toBe(1);
|
|
|
|
expect(vm.$el.querySelectorAll('.frequent-items-item-namespace').length).toBe(1);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|