diff options
author | Phil Hughes <me@iamphill.com> | 2018-07-06 13:40:11 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-07-06 13:40:11 +0000 |
commit | 89665b30dd957dc520b95bf3c9833e8b545d75d2 (patch) | |
tree | 4379c1214ca409902e0d858551282e2dd0c262aa /spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js | |
parent | b14b31b819f0f09d73e001a80acd528aad913dc9 (diff) | |
parent | 3892b022e3173851f418e4bd8469f0dcdde2ebef (diff) | |
download | gitlab-ce-89665b30dd957dc520b95bf3c9833e8b545d75d2.tar.gz |
Merge branch '36234-nav-add-groups-dropdown' into 'master'
Resolve "Add dropdown to Groups link in top bar"
Closes #36234
See merge request gitlab-org/gitlab-ce!18280
Diffstat (limited to 'spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js')
-rw-r--r-- | spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js b/spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js new file mode 100644 index 00000000000..201aca77b10 --- /dev/null +++ b/spec/javascripts/frequent_items/components/frequent_items_list_item_spec.js @@ -0,0 +1,75 @@ +import Vue from 'vue'; +import frequentItemsListItemComponent from '~/frequent_items/components/frequent_items_list_item.vue'; +import mountComponent from 'spec/helpers/vue_mount_component_helper'; +import { mockProject } from '../mock_data'; // can also use 'mockGroup', but not useful to test here + +const createComponent = () => { + const Component = Vue.extend(frequentItemsListItemComponent); + + return mountComponent(Component, { + itemId: mockProject.id, + itemName: mockProject.name, + namespace: mockProject.namespace, + webUrl: mockProject.webUrl, + avatarUrl: mockProject.avatarUrl, + }); +}; + +describe('FrequentItemsListItemComponent', () => { + 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'; + expect(vm.hasAvatar).toBe(true); + + vm.avatarUrl = null; + expect(vm.hasAvatar).toBe(false); + }); + }); + + describe('highlightedItemName', () => { + it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => { + vm.matcher = 'lab'; + expect(vm.highlightedItemName).toContain('<b>Lab</b>'); + }); + + it('should return project name as it is if `matcher` is not available', () => { + vm.matcher = null; + expect(vm.highlightedItemName).toBe(mockProject.name); + }); + }); + + 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', () => { + expect(vm.$el.classList.contains('frequent-items-list-item-container')).toBeTruthy(); + expect(vm.$el.querySelectorAll('a').length).toBe(1); + 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); + }); + }); +}); |