BigW Consortium Gitlab

Commit f4d7b476 by Kushal Pandya

Update selector to test SVG icon name, cleanup tests

parent 4fb47407
...@@ -26,7 +26,6 @@ describe('ItemStatsComponent', () => { ...@@ -26,7 +26,6 @@ describe('ItemStatsComponent', () => {
Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => { Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => {
const item = Object.assign({}, mockParentGroupItem, { visibility }); const item = Object.assign({}, mockParentGroupItem, { visibility });
const vm = createComponent(item); const vm = createComponent(item);
vm.$mount();
expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]); expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -41,7 +40,6 @@ describe('ItemStatsComponent', () => { ...@@ -41,7 +40,6 @@ describe('ItemStatsComponent', () => {
type: ITEM_TYPE.GROUP, type: ITEM_TYPE.GROUP,
}); });
const vm = createComponent(item); const vm = createComponent(item);
vm.$mount();
expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]); expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -54,7 +52,6 @@ describe('ItemStatsComponent', () => { ...@@ -54,7 +52,6 @@ describe('ItemStatsComponent', () => {
type: ITEM_TYPE.PROJECT, type: ITEM_TYPE.PROJECT,
}); });
const vm = createComponent(item); const vm = createComponent(item);
vm.$mount();
expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]); expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -68,13 +65,11 @@ describe('ItemStatsComponent', () => { ...@@ -68,13 +65,11 @@ describe('ItemStatsComponent', () => {
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
vm = createComponent(item); vm = createComponent(item);
vm.$mount();
expect(vm.isProject).toBeTruthy(); expect(vm.isProject).toBeTruthy();
vm.$destroy(); vm.$destroy();
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
vm = createComponent(item); vm = createComponent(item);
vm.$mount();
expect(vm.isProject).toBeFalsy(); expect(vm.isProject).toBeFalsy();
vm.$destroy(); vm.$destroy();
}); });
...@@ -87,13 +82,11 @@ describe('ItemStatsComponent', () => { ...@@ -87,13 +82,11 @@ describe('ItemStatsComponent', () => {
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
vm = createComponent(item); vm = createComponent(item);
vm.$mount();
expect(vm.isGroup).toBeTruthy(); expect(vm.isGroup).toBeTruthy();
vm.$destroy(); vm.$destroy();
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
vm = createComponent(item); vm = createComponent(item);
vm.$mount();
expect(vm.isGroup).toBeFalsy(); expect(vm.isGroup).toBeFalsy();
vm.$destroy(); vm.$destroy();
}); });
...@@ -101,57 +94,37 @@ describe('ItemStatsComponent', () => { ...@@ -101,57 +94,37 @@ describe('ItemStatsComponent', () => {
}); });
describe('template', () => { describe('template', () => {
it('should render component template correctly', () => { it('renders component container element correctly', () => {
const vm = createComponent(); const vm = createComponent();
vm.$mount();
const visibilityIconEl = vm.$el.querySelector('.item-visibility'); expect(vm.$el.classList.contains('stats')).toBeTruthy();
expect(vm.$el.classList.contains('.stats')).toBeDefined();
expect(visibilityIconEl).toBeDefined();
expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip);
expect(visibilityIconEl.querySelector('i.fa')).toBeDefined();
vm.$destroy(); vm.$destroy();
}); });
it('should render stat icons if `item.type` is Group', () => { it('renders item visibility icon and tooltip correctly', () => {
const item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); const vm = createComponent();
const vm = createComponent(item);
vm.$mount(); const visibilityIconEl = vm.$el.querySelector('.item-visibility');
expect(visibilityIconEl).not.toBe(null);
const subgroupIconEl = vm.$el.querySelector('span.number-subgroups'); expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip);
expect(subgroupIconEl).toBeDefined(); expect(visibilityIconEl.querySelectorAll('svg').length > 0).toBeTruthy();
expect(subgroupIconEl.dataset.originalTitle).toBe('Subgroups');
expect(subgroupIconEl.querySelector('i.fa.fa-folder')).toBeDefined();
expect(subgroupIconEl.innerText.trim()).toBe(`${vm.item.subgroupCount}`);
const projectsIconEl = vm.$el.querySelector('span.number-projects');
expect(projectsIconEl).toBeDefined();
expect(projectsIconEl.dataset.originalTitle).toBe('Projects');
expect(projectsIconEl.querySelector('i.fa.fa-bookmark')).toBeDefined();
expect(projectsIconEl.innerText.trim()).toBe(`${vm.item.projectCount}`);
const membersIconEl = vm.$el.querySelector('span.number-users');
expect(membersIconEl).toBeDefined();
expect(membersIconEl.dataset.originalTitle).toBe('Members');
expect(membersIconEl.querySelector('i.fa.fa-users')).toBeDefined();
expect(membersIconEl.innerText.trim()).toBe(`${vm.item.memberCount}`);
vm.$destroy(); vm.$destroy();
}); });
it('should render stat icons if `item.type` is Project', () => { it('renders start count and last updated information for project item correctly', () => {
const item = Object.assign({}, mockParentGroupItem, { const item = Object.assign({}, mockParentGroupItem, {
type: ITEM_TYPE.PROJECT, type: ITEM_TYPE.PROJECT,
starCount: 4, starCount: 4,
}); });
const vm = createComponent(item); const vm = createComponent(item);
vm.$mount();
const projectStarIconEl = vm.$el.querySelector('.project-stars'); const projectStarIconEl = vm.$el.querySelector('.project-stars');
expect(projectStarIconEl).toBeDefined(); expect(projectStarIconEl).not.toBe(null);
expect(projectStarIconEl.querySelector('i.fa.fa-star')).toBeDefined(); expect(projectStarIconEl.querySelectorAll('svg').length > 0).toBeTruthy();
expect(projectStarIconEl.innerText.trim()).toBe(`${vm.item.starCount}`); expect(projectStarIconEl.querySelectorAll('.stat-value').length > 0).toBeTruthy();
expect(vm.$el.querySelectorAll('.last-updated').length > 0).toBeTruthy();
vm.$destroy(); vm.$destroy();
}); });
......
...@@ -28,12 +28,12 @@ describe('ItemTypeIconComponent', () => { ...@@ -28,12 +28,12 @@ describe('ItemTypeIconComponent', () => {
vm = createComponent(ITEM_TYPE.GROUP, true); vm = createComponent(ITEM_TYPE.GROUP, true);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('i.fa.fa-folder-open')).toBeDefined(); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder-open');
vm.$destroy(); vm.$destroy();
vm = createComponent(ITEM_TYPE.GROUP); vm = createComponent(ITEM_TYPE.GROUP);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('i.fa.fa-folder')).toBeDefined(); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder');
vm.$destroy(); vm.$destroy();
}); });
...@@ -42,12 +42,12 @@ describe('ItemTypeIconComponent', () => { ...@@ -42,12 +42,12 @@ describe('ItemTypeIconComponent', () => {
vm = createComponent(ITEM_TYPE.PROJECT); vm = createComponent(ITEM_TYPE.PROJECT);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelectorAll('i.fa.fa-bookmark').length).toBe(1); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('bookmark');
vm.$destroy(); vm.$destroy();
vm = createComponent(ITEM_TYPE.GROUP); vm = createComponent(ITEM_TYPE.GROUP);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelectorAll('i.fa.fa-bookmark').length).toBe(0); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).not.toContain('bookmark');
vm.$destroy(); vm.$destroy();
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment