diff options
Diffstat (limited to 'spec/frontend/merge_request_tabs_spec.js')
-rw-r--r-- | spec/frontend/merge_request_tabs_spec.js | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/spec/frontend/merge_request_tabs_spec.js b/spec/frontend/merge_request_tabs_spec.js index 6d434d7e654..3b8c9dd3bf3 100644 --- a/spec/frontend/merge_request_tabs_spec.js +++ b/spec/frontend/merge_request_tabs_spec.js @@ -1,6 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import htmlMergeRequestsWithTaskList from 'test_fixtures/merge_requests/merge_request_with_task_list.html'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import initMrPage from 'helpers/init_vue_mr_page_helper'; import { stubPerformanceWebAPI } from 'helpers/performance'; import axios from '~/lib/utils/axios_utils'; @@ -40,6 +41,10 @@ describe('MergeRequestTabs', () => { gl.mrWidget = {}; }); + afterEach(() => { + document.body.innerHTML = ''; + }); + describe('clickTab', () => { let params; @@ -84,7 +89,7 @@ describe('MergeRequestTabs', () => { let tabUrl; beforeEach(() => { - loadHTMLFixture('merge_requests/merge_request_with_task_list.html'); + setHTMLFixture(htmlMergeRequestsWithTaskList); tabUrl = $('.commits-tab a').attr('href'); @@ -268,32 +273,32 @@ describe('MergeRequestTabs', () => { describe('expandViewContainer', () => { beforeEach(() => { - $('body').append( - '<div class="content-wrapper"><div class="container-fluid container-limited"></div></div>', - ); - }); - - afterEach(() => { - $('.content-wrapper').remove(); + $('.content-wrapper .container-fluid').addClass('container-limited'); }); - it('removes container-limited from containers', () => { + it('removes `container-limited` class from content container', () => { + expect($('.content-wrapper .container-limited')).toHaveLength(1); testContext.class.expandViewContainer(); - expect($('.content-wrapper .container-limited')).toHaveLength(0); }); + }); - it('does not add container-limited when fluid layout is prefered', () => { - $('.content-wrapper .container-fluid').removeClass('container-limited'); - - testContext.class.expandViewContainer(false); + describe('resetViewContainer', () => { + it('does not add `container-limited` CSS class when fluid layout is preferred', () => { + testContext.class.resetViewContainer(); expect($('.content-wrapper .container-limited')).toHaveLength(0); }); - it('does remove container-limited from breadcrumbs', () => { - $('.container-limited').addClass('breadcrumbs'); - testContext.class.expandViewContainer(); + it('adds `container-limited` CSS class back when fixed layout is preferred', () => { + document.body.innerHTML = ''; + initMrPage(); + $('.content-wrapper .container-fluid').addClass('container-limited'); + // recreate the instance so that `isFixedLayoutPreferred` is re-evaluated + testContext.class = new MergeRequestTabs({ stubLocation }); + $('.content-wrapper .container-fluid').removeClass('container-limited'); + + testContext.class.resetViewContainer(); expect($('.content-wrapper .container-limited')).toHaveLength(1); }); @@ -354,8 +359,6 @@ describe('MergeRequestTabs', () => { testContext.class.expandSidebar.forEach((el) => { expect(el.classList.contains('gl-display-none!')).toBe(hides); }); - - window.gon = {}; }); describe('when switching tabs', () => { @@ -381,12 +384,12 @@ describe('MergeRequestTabs', () => { }); }); - it('scrolls to 0, if no position is stored', () => { + it('does not scroll if no position is stored', () => { testContext.class.tabShown('unknownTab'); jest.advanceTimersByTime(250); - expect(window.scrollTo.mock.calls[0][0]).toEqual({ top: 0, left: 0, behavior: 'auto' }); + expect(window.scrollTo).not.toHaveBeenCalled(); }); }); }); |