diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/frontend/groups/landing_spec.js | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/frontend/groups/landing_spec.js')
-rw-r--r-- | spec/frontend/groups/landing_spec.js | 184 |
1 files changed, 184 insertions, 0 deletions
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'); + }); + }); +}); |