diff options
Diffstat (limited to 'spec/frontend/groups')
-rw-r--r-- | spec/frontend/groups/components/group_item_spec.js | 1 | ||||
-rw-r--r-- | spec/frontend/groups/components/item_stats_spec.js | 1 | ||||
-rw-r--r-- | spec/frontend/groups/landing_spec.js | 184 | ||||
-rw-r--r-- | spec/frontend/groups/transfer_edit_spec.js | 31 |
4 files changed, 217 insertions, 0 deletions
diff --git a/spec/frontend/groups/components/group_item_spec.js b/spec/frontend/groups/components/group_item_spec.js index 60d47895a95..8ea7e54aef4 100644 --- a/spec/frontend/groups/components/group_item_spec.js +++ b/spec/frontend/groups/components/group_item_spec.js @@ -100,6 +100,7 @@ describe('GroupItemComponent', () => { wrapper.destroy(); group.type = 'project'; + group.lastActivityAt = '2017-04-09T18:40:39.101Z'; wrapper = createComponent({ group }); expect(wrapper.vm.isGroup).toBe(false); diff --git a/spec/frontend/groups/components/item_stats_spec.js b/spec/frontend/groups/components/item_stats_spec.js index 49f3f5da43c..fdc267bc14a 100644 --- a/spec/frontend/groups/components/item_stats_spec.js +++ b/spec/frontend/groups/components/item_stats_spec.js @@ -38,6 +38,7 @@ describe('ItemStats', () => { ...mockParentGroupItem, type: ITEM_TYPE.PROJECT, starCount: 4, + lastActivityAt: '2017-04-09T18:40:39.101Z', }; createComponent({ item }); diff --git a/spec/frontend/groups/landing_spec.js b/spec/frontend/groups/landing_spec.js new file mode 100644 index 00000000000..f90f541eb96 --- /dev/null +++ b/spec/frontend/groups/landing_spec.js @@ -0,0 +1,184 @@ +import Cookies from 'js-cookie'; +import Landing from '~/groups/landing'; + +describe('Landing', () => { + const test = {}; + + describe('class constructor', () => { + beforeEach(() => { + test.landingElement = {}; + test.dismissButton = {}; + test.cookieName = 'cookie_name'; + + test.landing = new Landing(test.landingElement, test.dismissButton, test.cookieName); + }); + + it('should set .landing', () => { + expect(test.landing.landingElement).toBe(test.landingElement); + }); + + it('should set .cookieName', () => { + expect(test.landing.cookieName).toBe(test.cookieName); + }); + + it('should set .dismissButton', () => { + expect(test.landing.dismissButton).toBe(test.dismissButton); + }); + + it('should set .eventWrapper', () => { + expect(test.landing.eventWrapper).toEqual({}); + }); + }); + + describe('toggle', () => { + beforeEach(() => { + test.isDismissed = false; + test.landingElement = { + classList: { + toggle: jest.fn(), + }, + }; + test.landing = { + isDismissed: () => {}, + addEvents: () => {}, + landingElement: test.landingElement, + }; + + jest.spyOn(test.landing, 'isDismissed').mockReturnValue(test.isDismissed); + jest.spyOn(test.landing, 'addEvents').mockImplementation(() => {}); + + Landing.prototype.toggle.call(test.landing); + }); + + it('should call .isDismissed', () => { + expect(test.landing.isDismissed).toHaveBeenCalled(); + }); + + it('should call .classList.toggle', () => { + expect(test.landingElement.classList.toggle).toHaveBeenCalledWith('hidden', test.isDismissed); + }); + + it('should call .addEvents', () => { + expect(test.landing.addEvents).toHaveBeenCalled(); + }); + + describe('if isDismissed is true', () => { + beforeEach(() => { + test.isDismissed = true; + test.landingElement = { + classList: { + toggle: jest.fn(), + }, + }; + test.landing = { + isDismissed: () => {}, + addEvents: () => {}, + landingElement: test.landingElement, + }; + + jest.spyOn(test.landing, 'isDismissed').mockReturnValue(test.isDismissed); + jest.spyOn(test.landing, 'addEvents').mockImplementation(() => {}); + + test.landing.isDismissed.mockClear(); + + Landing.prototype.toggle.call(test.landing); + }); + + it('should not call .addEvents', () => { + expect(test.landing.addEvents).not.toHaveBeenCalled(); + }); + }); + }); + + describe('addEvents', () => { + beforeEach(() => { + test.dismissButton = { + addEventListener: jest.fn(), + }; + test.eventWrapper = {}; + test.landing = { + eventWrapper: test.eventWrapper, + dismissButton: test.dismissButton, + dismissLanding: () => {}, + }; + + Landing.prototype.addEvents.call(test.landing); + }); + + it('should set .eventWrapper.dismissLanding', () => { + expect(test.eventWrapper.dismissLanding).toEqual(expect.any(Function)); + }); + + it('should call .addEventListener', () => { + expect(test.dismissButton.addEventListener).toHaveBeenCalledWith( + 'click', + test.eventWrapper.dismissLanding, + ); + }); + }); + + describe('removeEvents', () => { + beforeEach(() => { + test.dismissButton = { + removeEventListener: jest.fn(), + }; + test.eventWrapper = { dismissLanding: () => {} }; + test.landing = { + eventWrapper: test.eventWrapper, + dismissButton: test.dismissButton, + }; + + Landing.prototype.removeEvents.call(test.landing); + }); + + it('should call .removeEventListener', () => { + expect(test.dismissButton.removeEventListener).toHaveBeenCalledWith( + 'click', + test.eventWrapper.dismissLanding, + ); + }); + }); + + describe('dismissLanding', () => { + beforeEach(() => { + test.landingElement = { + classList: { + add: jest.fn(), + }, + }; + test.cookieName = 'cookie_name'; + test.landing = { landingElement: test.landingElement, cookieName: test.cookieName }; + + jest.spyOn(Cookies, 'set').mockImplementation(() => {}); + + Landing.prototype.dismissLanding.call(test.landing); + }); + + it('should call .classList.add', () => { + expect(test.landingElement.classList.add).toHaveBeenCalledWith('hidden'); + }); + + it('should call Cookies.set', () => { + expect(Cookies.set).toHaveBeenCalledWith(test.cookieName, 'true', { expires: 365 }); + }); + }); + + describe('isDismissed', () => { + beforeEach(() => { + test.cookieName = 'cookie_name'; + test.landing = { cookieName: test.cookieName }; + + jest.spyOn(Cookies, 'get').mockReturnValue('true'); + + test.isDismissed = Landing.prototype.isDismissed.call(test.landing); + }); + + it('should call Cookies.get', () => { + expect(Cookies.get).toHaveBeenCalledWith(test.cookieName); + }); + + it('should return a boolean', () => { + expect(typeof test.isDismissed).toEqual('boolean'); + }); + }); +}); diff --git a/spec/frontend/groups/transfer_edit_spec.js b/spec/frontend/groups/transfer_edit_spec.js new file mode 100644 index 00000000000..bc070920d02 --- /dev/null +++ b/spec/frontend/groups/transfer_edit_spec.js @@ -0,0 +1,31 @@ +import $ from 'jquery'; + +import { loadHTMLFixture } from 'helpers/fixtures'; +import setupTransferEdit from '~/groups/transfer_edit'; + +describe('setupTransferEdit', () => { + const formSelector = '.js-group-transfer-form'; + const targetSelector = '#new_parent_group_id'; + + beforeEach(() => { + loadHTMLFixture('groups/edit.html'); + setupTransferEdit(formSelector, targetSelector); + }); + + it('disables submit button on load', () => { + expect($(formSelector).find(':submit').prop('disabled')).toBe(true); + }); + + it('enables submit button when selection changes to non-empty value', () => { + const lastValue = $(formSelector).find(targetSelector).find('.dropdown-content li').last(); + $(formSelector).find(targetSelector).val(lastValue).trigger('change'); + + expect($(formSelector).find(':submit').prop('disabled')).toBeFalsy(); + }); + + it('disables submit button when selection changes to empty value', () => { + $(formSelector).find(targetSelector).val('').trigger('change'); + + expect($(formSelector).find(':submit').prop('disabled')).toBe(true); + }); +}); |