diff options
author | Johann Hubert Sonntagbauer <johann.sonntagbauer@gmail.com> | 2018-10-09 21:03:09 +0300 |
---|---|---|
committer | Johann Hubert Sonntagbauer <johann.sonntagbauer@gmail.com> | 2018-10-17 07:57:29 +0300 |
commit | 6f5723a169b5d400c136dbd844fc54c68e5f8563 (patch) | |
tree | e7bad2648366ed5943293655a0abe23367e869a6 /spec/javascripts/groups | |
parent | 28d412e5b2b8499fba22e8fabb1d44f44449228e (diff) |
enable jasmine/new-line-before-expect
Diffstat (limited to 'spec/javascripts/groups')
11 files changed, 68 insertions, 0 deletions
diff --git a/spec/javascripts/groups/components/app_spec.js b/spec/javascripts/groups/components/app_spec.js index 89c07d1f06d..d832441dc93 100644 --- a/spec/javascripts/groups/components/app_spec.js +++ b/spec/javascripts/groups/components/app_spec.js @@ -76,6 +76,7 @@ describe('AppComponent', () => { spyOn(vm.store, 'getGroups'); const { groups } = vm; + expect(vm.store.getGroups).toHaveBeenCalled(); expect(groups).not.toBeDefined(); }); @@ -86,6 +87,7 @@ describe('AppComponent', () => { spyOn(vm.store, 'getPaginationInfo'); const { pageInfo } = vm; + expect(vm.store.getPaginationInfo).toHaveBeenCalled(); expect(pageInfo).not.toBeDefined(); }); @@ -154,6 +156,7 @@ describe('AppComponent', () => { spyOn(vm, 'updateGroups').and.callThrough(); vm.fetchAllGroups(); + expect(vm.isLoading).toBe(true); expect(vm.fetchGroups).toHaveBeenCalled(); setTimeout(() => { @@ -168,6 +171,7 @@ describe('AppComponent', () => { spyOn(vm, 'updateGroups').and.callThrough(); vm.fetchAllGroups(); + expect(vm.fetchGroups).toHaveBeenCalledWith({ page: null, filterGroupsBy: null, @@ -191,6 +195,7 @@ describe('AppComponent', () => { spyOn($, 'scrollTo'); vm.fetchPage(2, null, null, true); + expect(vm.isLoading).toBe(true); expect(vm.fetchGroups).toHaveBeenCalledWith({ page: 2, @@ -210,6 +215,7 @@ describe('AppComponent', () => { jasmine.any(String), jasmine.any(String), ); + expect(vm.updateGroups).toHaveBeenCalled(); done(); }, 0); @@ -230,6 +236,7 @@ describe('AppComponent', () => { spyOn(vm.store, 'setGroupChildren'); vm.toggleChildren(groupItem); + expect(groupItem.isChildrenLoading).toBe(true); expect(vm.fetchGroups).toHaveBeenCalledWith({ parentId: groupItem.id, @@ -245,6 +252,7 @@ describe('AppComponent', () => { groupItem.children = mockRawChildren; vm.toggleChildren(groupItem); + expect(vm.fetchGroups).not.toHaveBeenCalled(); expect(groupItem.isOpen).toBe(true); }); @@ -254,6 +262,7 @@ describe('AppComponent', () => { groupItem.isOpen = true; vm.toggleChildren(groupItem); + expect(vm.fetchGroups).not.toHaveBeenCalled(); expect(groupItem.isOpen).toBe(false); }); @@ -262,6 +271,7 @@ describe('AppComponent', () => { spyOn(vm, 'fetchGroups').and.returnValue(returnServicePromise({}, true)); vm.toggleChildren(groupItem); + expect(groupItem.isChildrenLoading).toBe(true); setTimeout(() => { expect(groupItem.isChildrenLoading).toBe(false); @@ -273,18 +283,22 @@ describe('AppComponent', () => { describe('showLeaveGroupModal', () => { it('caches candidate group (as props) which is to be left', () => { const group = Object.assign({}, mockParentGroupItem); + expect(vm.targetGroup).toBe(null); expect(vm.targetParentGroup).toBe(null); vm.showLeaveGroupModal(group, mockParentGroupItem); + expect(vm.targetGroup).not.toBe(null); expect(vm.targetParentGroup).not.toBe(null); }); it('updates props which show modal confirmation dialog', () => { const group = Object.assign({}, mockParentGroupItem); + expect(vm.showModal).toBe(false); expect(vm.groupLeaveConfirmationMessage).toBe(''); vm.showLeaveGroupModal(group, mockParentGroupItem); + expect(vm.showModal).toBe(true); expect(vm.groupLeaveConfirmationMessage).toBe( `Are you sure you want to leave the "${group.fullName}" group?`, @@ -296,8 +310,10 @@ describe('AppComponent', () => { it('hides modal confirmation which is shown before leaving the group', () => { const group = Object.assign({}, mockParentGroupItem); vm.showLeaveGroupModal(group, mockParentGroupItem); + expect(vm.showModal).toBe(true); vm.hideLeaveGroupModal(); + expect(vm.showModal).toBe(false); }); }); @@ -323,6 +339,7 @@ describe('AppComponent', () => { spyOn($, 'scrollTo'); vm.leaveGroup(); + expect(vm.showModal).toBe(false); expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.service.leaveGroup).toHaveBeenCalledWith(vm.targetGroup.leavePath); @@ -343,6 +360,7 @@ describe('AppComponent', () => { spyOn(window, 'Flash'); vm.leaveGroup(); + expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); setTimeout(() => { @@ -362,6 +380,7 @@ describe('AppComponent', () => { spyOn(window, 'Flash'); vm.leaveGroup(childGroupItem, groupItem); + expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); setTimeout(() => { @@ -378,6 +397,7 @@ describe('AppComponent', () => { spyOn(vm.store, 'setPaginationInfo'); vm.updatePagination(mockRawPageInfo); + expect(vm.store.setPaginationInfo).toHaveBeenCalledWith(mockRawPageInfo); }); }); @@ -387,6 +407,7 @@ describe('AppComponent', () => { spyOn(vm.store, 'setGroups'); vm.updateGroups(mockGroups); + expect(vm.store.setGroups).toHaveBeenCalledWith(mockGroups); }); @@ -394,14 +415,17 @@ describe('AppComponent', () => { spyOn(vm.store, 'setSearchedGroups'); vm.updateGroups(mockGroups, true); + expect(vm.store.setSearchedGroups).toHaveBeenCalledWith(mockGroups); }); it('should set `isSearchEmpty` prop based on groups count', () => { vm.updateGroups(mockGroups); + expect(vm.isSearchEmpty).toBe(false); vm.updateGroups([]); + expect(vm.isSearchEmpty).toBe(true); }); }); @@ -497,6 +521,7 @@ describe('AppComponent', () => { vm.showModal = true; Vue.nextTick(() => { const modalDialogEl = vm.$el.querySelector('.modal'); + expect(modalDialogEl).not.toBe(null); expect(modalDialogEl.querySelector('.modal-title').innerText.trim()).toBe('Are you sure?'); expect(modalDialogEl.querySelector('.btn.btn-warning').innerText.trim()).toBe('Leave'); diff --git a/spec/javascripts/groups/components/group_folder_spec.js b/spec/javascripts/groups/components/group_folder_spec.js index 4eb198595fb..9342c04e4d5 100644 --- a/spec/javascripts/groups/components/group_folder_spec.js +++ b/spec/javascripts/groups/components/group_folder_spec.js @@ -59,6 +59,7 @@ describe('GroupFolderComponent', () => { const newVm = createComponent(mockGroups, parentGroup); newVm.$mount(); + expect(newVm.$el.querySelector('li.group-row a.has-more-items')).toBeDefined(); newVm.$destroy(); }); diff --git a/spec/javascripts/groups/components/group_item_spec.js b/spec/javascripts/groups/components/group_item_spec.js index 49d4f7efd72..48e79fd85e4 100644 --- a/spec/javascripts/groups/components/group_item_spec.js +++ b/spec/javascripts/groups/components/group_item_spec.js @@ -57,11 +57,13 @@ describe('GroupItemComponent', () => { group.childrenCount = 5; newVm = createComponent(group); + expect(newVm.hasChildren).toBeTruthy(); newVm.$destroy(); group.childrenCount = 0; newVm = createComponent(group); + expect(newVm.hasChildren).toBeFalsy(); newVm.$destroy(); }); @@ -74,11 +76,13 @@ describe('GroupItemComponent', () => { group.avatarUrl = null; newVm = createComponent(group); + expect(newVm.hasAvatar).toBeFalsy(); newVm.$destroy(); group.avatarUrl = '/uploads/group_avatar.png'; newVm = createComponent(group); + expect(newVm.hasAvatar).toBeTruthy(); newVm.$destroy(); }); @@ -91,11 +95,13 @@ describe('GroupItemComponent', () => { group.type = 'group'; newVm = createComponent(group); + expect(newVm.isGroup).toBeTruthy(); newVm.$destroy(); group.type = 'project'; newVm = createComponent(group); + expect(newVm.isGroup).toBeFalsy(); newVm.$destroy(); }); @@ -127,6 +133,7 @@ describe('GroupItemComponent', () => { spyOn(eventHub, '$emit'); vm.onClickRowGroup(event); + expect(eventHub.$emit).toHaveBeenCalledWith('toggleChildren', vm.group); }); diff --git a/spec/javascripts/groups/components/groups_spec.js b/spec/javascripts/groups/components/groups_spec.js index 5af86b55532..0f3907f1ca2 100644 --- a/spec/javascripts/groups/components/groups_spec.js +++ b/spec/javascripts/groups/components/groups_spec.js @@ -42,6 +42,7 @@ describe('GroupsComponent', () => { spyOn(eventHub, '$emit').and.stub(); vm.change(2); + expect(eventHub.$emit).toHaveBeenCalledWith('fetchPage', 2, jasmine.any(Object), jasmine.any(Object), jasmine.any(Object)); }); }); diff --git a/spec/javascripts/groups/components/item_actions_spec.js b/spec/javascripts/groups/components/item_actions_spec.js index 15fd37ebcd2..bffeb4acd45 100644 --- a/spec/javascripts/groups/components/item_actions_spec.js +++ b/spec/javascripts/groups/components/item_actions_spec.js @@ -30,6 +30,7 @@ describe('ItemActionsComponent', () => { it('emits `showLeaveGroupModal` event with `group` and `parentGroup` props', () => { spyOn(eventHub, '$emit'); vm.onLeaveGroup(); + expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', vm.group, vm.parentGroup); }); }); @@ -46,6 +47,7 @@ describe('ItemActionsComponent', () => { const newVm = createComponent(group); const editBtn = newVm.$el.querySelector('a.edit-group'); + expect(editBtn).toBeDefined(); expect(editBtn.classList.contains('no-expand')).toBeTruthy(); expect(editBtn.getAttribute('href')).toBe(group.editPath); @@ -63,6 +65,7 @@ describe('ItemActionsComponent', () => { const newVm = createComponent(group); const leaveBtn = newVm.$el.querySelector('a.leave-group'); + expect(leaveBtn).toBeDefined(); expect(leaveBtn.classList.contains('no-expand')).toBeTruthy(); expect(leaveBtn.getAttribute('href')).toBe(group.leavePath); diff --git a/spec/javascripts/groups/components/item_caret_spec.js b/spec/javascripts/groups/components/item_caret_spec.js index 36f838a104f..6e430dbcdb2 100644 --- a/spec/javascripts/groups/components/item_caret_spec.js +++ b/spec/javascripts/groups/components/item_caret_spec.js @@ -16,6 +16,7 @@ describe('ItemCaretComponent', () => { describe('template', () => { it('should render component template correctly', () => { const vm = createComponent(); + expect(vm.$el.classList.contains('folder-caret')).toBeTruthy(); expect(vm.$el.querySelectorAll('svg').length).toBe(1); vm.$destroy(); @@ -23,12 +24,14 @@ describe('ItemCaretComponent', () => { it('should render caret down icon if `isGroupOpen` prop is `true`', () => { const vm = createComponent(true); + expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-down'); vm.$destroy(); }); it('should render caret right icon if `isGroupOpen` prop is `false`', () => { const vm = createComponent(); + expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-right'); vm.$destroy(); }); diff --git a/spec/javascripts/groups/components/item_stats_spec.js b/spec/javascripts/groups/components/item_stats_spec.js index e6a57495eb1..55a28dfea11 100644 --- a/spec/javascripts/groups/components/item_stats_spec.js +++ b/spec/javascripts/groups/components/item_stats_spec.js @@ -25,6 +25,7 @@ describe('ItemStatsComponent', () => { Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => { const item = Object.assign({}, mockParentGroupItem, { visibility }); const vm = createComponent(item); + expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]); vm.$destroy(); }); @@ -39,6 +40,7 @@ describe('ItemStatsComponent', () => { type: ITEM_TYPE.GROUP, }); const vm = createComponent(item); + expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]); vm.$destroy(); }); @@ -51,6 +53,7 @@ describe('ItemStatsComponent', () => { type: ITEM_TYPE.PROJECT, }); const vm = createComponent(item); + expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]); vm.$destroy(); }); @@ -64,11 +67,13 @@ describe('ItemStatsComponent', () => { item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); vm = createComponent(item); + expect(vm.isProject).toBeTruthy(); vm.$destroy(); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); vm = createComponent(item); + expect(vm.isProject).toBeFalsy(); vm.$destroy(); }); @@ -81,11 +86,13 @@ describe('ItemStatsComponent', () => { item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); vm = createComponent(item); + expect(vm.isGroup).toBeTruthy(); vm.$destroy(); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); vm = createComponent(item); + expect(vm.isGroup).toBeFalsy(); vm.$destroy(); }); @@ -105,6 +112,7 @@ describe('ItemStatsComponent', () => { const vm = createComponent(); const visibilityIconEl = vm.$el.querySelector('.item-visibility'); + expect(visibilityIconEl).not.toBe(null); expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip); expect(visibilityIconEl.querySelectorAll('svg').length).toBeGreaterThan(0); @@ -120,6 +128,7 @@ describe('ItemStatsComponent', () => { const vm = createComponent(item); const projectStarIconEl = vm.$el.querySelector('.project-stars'); + expect(projectStarIconEl).not.toBeNull(); expect(projectStarIconEl.querySelectorAll('svg').length).toBeGreaterThan(0); expect(projectStarIconEl.querySelectorAll('.stat-value').length).toBeGreaterThan(0); diff --git a/spec/javascripts/groups/components/item_stats_value_spec.js b/spec/javascripts/groups/components/item_stats_value_spec.js index 2a995e8efe6..ea8edcf49cd 100644 --- a/spec/javascripts/groups/components/item_stats_value_spec.js +++ b/spec/javascripts/groups/components/item_stats_value_spec.js @@ -29,11 +29,13 @@ describe('ItemStatsValueComponent', () => { describe('isValuePresent', () => { it('returns true if non-empty `value` is present', () => { vm = createComponent(Object.assign({}, itemConfig, { value: 10 })); + expect(vm.isValuePresent).toBeTruthy(); }); it('returns false if empty `value` is present', () => { vm = createComponent(itemConfig); + expect(vm.isValuePresent).toBeFalsy(); }); diff --git a/spec/javascripts/groups/components/item_type_icon_spec.js b/spec/javascripts/groups/components/item_type_icon_spec.js index 24380689b29..73108512222 100644 --- a/spec/javascripts/groups/components/item_type_icon_spec.js +++ b/spec/javascripts/groups/components/item_type_icon_spec.js @@ -18,6 +18,7 @@ describe('ItemTypeIconComponent', () => { it('should render component template correctly', () => { const vm = createComponent(); vm.$mount(); + expect(vm.$el.classList.contains('item-type-icon')).toBeTruthy(); vm.$destroy(); }); @@ -27,11 +28,13 @@ describe('ItemTypeIconComponent', () => { vm = createComponent(ITEM_TYPE.GROUP, true); vm.$mount(); + expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder-open'); vm.$destroy(); vm = createComponent(ITEM_TYPE.GROUP); vm.$mount(); + expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder'); vm.$destroy(); }); @@ -41,11 +44,13 @@ describe('ItemTypeIconComponent', () => { vm = createComponent(ITEM_TYPE.PROJECT); vm.$mount(); + expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('bookmark'); vm.$destroy(); vm = createComponent(ITEM_TYPE.GROUP); vm.$mount(); + expect(vm.$el.querySelector('use').getAttribute('xlink:href')).not.toContain('bookmark'); vm.$destroy(); }); diff --git a/spec/javascripts/groups/service/groups_service_spec.js b/spec/javascripts/groups/service/groups_service_spec.js index 20bb63687f7..339e5131615 100644 --- a/spec/javascripts/groups/service/groups_service_spec.js +++ b/spec/javascripts/groups/service/groups_service_spec.js @@ -24,9 +24,11 @@ describe('GroupsService', () => { }; service.getGroups(55, 2, 'git', 'created_asc', true); + expect(service.groups.get).toHaveBeenCalledWith({ parent_id: 55 }); service.getGroups(null, 2, 'git', 'created_asc', true); + expect(service.groups.get).toHaveBeenCalledWith(queryParams); }); }); @@ -36,6 +38,7 @@ describe('GroupsService', () => { spyOn(Vue.http, 'delete').and.stub(); service.leaveGroup(mockParentGroupItem.leavePath); + expect(Vue.http.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath); }); }); diff --git a/spec/javascripts/groups/store/groups_store_spec.js b/spec/javascripts/groups/store/groups_store_spec.js index 78caf8f80bf..23324d26cf0 100644 --- a/spec/javascripts/groups/store/groups_store_spec.js +++ b/spec/javascripts/groups/store/groups_store_spec.js @@ -11,12 +11,14 @@ describe('ProjectsStore', () => { let store; store = new GroupsStore(); + expect(Object.keys(store.state).length).toBe(2); expect(Array.isArray(store.state.groups)).toBeTruthy(); expect(Object.keys(store.state.pageInfo).length).toBe(0); expect(store.hideProjects).not.toBeDefined(); store = new GroupsStore(true); + expect(store.hideProjects).toBeTruthy(); }); }); @@ -27,6 +29,7 @@ describe('ProjectsStore', () => { spyOn(store, 'formatGroupItem').and.callThrough(); store.setGroups(mockGroups); + expect(store.state.groups.length).toBe(mockGroups.length); expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1); @@ -39,6 +42,7 @@ describe('ProjectsStore', () => { spyOn(store, 'formatGroupItem').and.callThrough(); store.setSearchedGroups(mockSearchedGroups); + expect(store.state.groups.length).toBe(mockSearchedGroups.length); expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1); @@ -52,6 +56,7 @@ describe('ProjectsStore', () => { spyOn(store, 'formatGroupItem').and.callThrough(); store.setGroupChildren(mockParentGroupItem, mockRawChildren); + expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(mockParentGroupItem.children.length).toBe(1); expect(Object.keys(mockParentGroupItem.children[0]).indexOf('fullName')).toBeGreaterThan(-1); @@ -65,6 +70,7 @@ describe('ProjectsStore', () => { const store = new GroupsStore(); store.setPaginationInfo(mockRawPageInfo); + expect(store.state.pageInfo.perPage).toBe(10); expect(store.state.pageInfo.page).toBe(10); expect(store.state.pageInfo.total).toBe(10); @@ -81,6 +87,7 @@ describe('ProjectsStore', () => { store = new GroupsStore(); updatedGroupItem = store.formatGroupItem(mockRawChildren[0]); + expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1); expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].children_count); expect(updatedGroupItem.isChildrenLoading).toBe(false); @@ -88,6 +95,7 @@ describe('ProjectsStore', () => { store = new GroupsStore(true); updatedGroupItem = store.formatGroupItem(mockRawChildren[0]); + expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1); expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].subgroup_count); }); @@ -104,6 +112,7 @@ describe('ProjectsStore', () => { const childItem = store.state.groups[0].children[0]; store.removeGroup(childItem, store.state.groups[0]); + expect(store.state.groups[0].children.length).toBe(0); }); }); |