diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-21 18:14:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-21 18:14:09 +0300 |
commit | e87220d9c1a7878a4cb2bb86554c5951371e340b (patch) | |
tree | fa8d81c8463cf97362f441f81dfef890df34ebbd /spec/frontend/blame | |
parent | c0a3d287c0d613cc439a31683d06dd70f3411f8c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/blame')
-rw-r--r-- | spec/frontend/blame/blame_redirect_spec.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/frontend/blame/blame_redirect_spec.js b/spec/frontend/blame/blame_redirect_spec.js new file mode 100644 index 00000000000..beb10139b3a --- /dev/null +++ b/spec/frontend/blame/blame_redirect_spec.js @@ -0,0 +1,70 @@ +import redirectToCorrectPage from '~/blame/blame_redirect'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import { createAlert } from '~/flash'; + +jest.mock('~/flash'); + +describe('Blame page redirect', () => { + beforeEach(() => { + global.window = Object.create(window); + const url = 'https://gitlab.com/flightjs/Flight/-/blame/master/file.json'; + Object.defineProperty(window, 'location', { + writable: true, + value: { + href: url, + hash: '', + search: '', + }, + }); + + setHTMLFixture(`<div class="js-per-page" data-per-page="1000"></div>`); + }); + + afterEach(() => { + createAlert.mockClear(); + resetHTMLFixture(); + }); + + it('performs redirect to further pages when needed', () => { + window.location.hash = '#L1001'; + redirectToCorrectPage(); + expect(window.location.href).toMatch('?page=2'); + }); + + it('performs redirect back to first page when needed', () => { + window.location.href = 'https://gitlab.com/flightjs/Flight/-/blame/master/file.json'; + window.location.search = '?page=200'; + window.location.hash = '#L999'; + redirectToCorrectPage(); + expect(window.location.href).toMatch('?page=1'); + }); + + it('doesn`t perform redirect when the line is still on page 1', () => { + window.location.hash = '#L1000'; + redirectToCorrectPage(); + expect(window.location.href).not.toMatch('?page'); + }); + + it('doesn`t perform redirect when "no_pagination" param is present', () => { + window.location.href = 'https://gitlab.com/flightjs/Flight/-/blame/master/file.json'; + window.location.search = '?no_pagination=true'; + window.location.hash = '#L1001'; + redirectToCorrectPage(); + expect(window.location.href).not.toMatch('?page'); + }); + + it('doesn`t perform redirect when perPage is not present', () => { + setHTMLFixture(`<div class="js-per-page"></div>`); + window.location.hash = '#L1001'; + redirectToCorrectPage(); + expect(window.location.href).not.toMatch('?page'); + }); + + it('shows alert with a message', () => { + window.location.hash = '#L1001'; + redirectToCorrectPage(); + expect(createAlert).toHaveBeenCalledWith({ + message: 'Please wait a few moments while we load the file history for this line.', + }); + }); +}); |