Commit c588c60f authored by Phil Hughes's avatar Phil Hughes

Merge branch '24551-keep-search-param-in-commit-scroll' into 'master'

Ensure search param is kept in scrolled commit

See merge request gitlab-org/gitlab!57307
parents 41ebeaa7 4e07370f
...@@ -16,7 +16,6 @@ export default { ...@@ -16,7 +16,6 @@ export default {
callback = $.noop, callback = $.noop,
container = '', container = '',
) { ) {
this.url = $('.content_list').data('href') || removeParams(['limit', 'offset']);
this.limit = limit; this.limit = limit;
this.offset = parseInt(getParameterByName('offset'), 10) || this.limit; this.offset = parseInt(getParameterByName('offset'), 10) || this.limit;
this.disable = disable; this.disable = disable;
...@@ -32,8 +31,10 @@ export default { ...@@ -32,8 +31,10 @@ export default {
getOld() { getOld() {
this.loading.show(); this.loading.show();
const url = $('.content_list').data('href') || removeParams(['limit', 'offset']);
axios axios
.get(this.url, { .get(url, {
params: { params: {
limit: this.limit, limit: this.limit,
offset: this.offset, offset: this.offset,
......
---
title: Ensure search param is kept in scrolled commit
merge_request: 57307
author:
type: fixed
...@@ -32,38 +32,12 @@ describe('pager', () => { ...@@ -32,38 +32,12 @@ describe('pager', () => {
window.history.replaceState({}, null, originalHref); window.history.replaceState({}, null, originalHref);
}); });
it('should use data-href attribute from list element', () => {
const href = `${TEST_HOST}/some_list.json`;
setFixtures(`<div class="content_list" data-href="${href}"></div>`);
Pager.init();
expect(Pager.url).toBe(href);
});
it('should use current url if data-href attribute not provided', () => {
const href = `${TEST_HOST}/some_list`;
removeParams.mockReturnValue(href);
Pager.init();
expect(Pager.url).toBe(href);
});
it('should get initial offset from query parameter', () => { it('should get initial offset from query parameter', () => {
window.history.replaceState({}, null, '?offset=100'); window.history.replaceState({}, null, '?offset=100');
Pager.init(); Pager.init();
expect(Pager.offset).toBe(100); expect(Pager.offset).toBe(100);
}); });
it('keeps extra query parameters from url', () => {
window.history.replaceState({}, null, '?filter=test&offset=100');
const href = `${TEST_HOST}/some_list?filter=test`;
removeParams.mockReturnValue(href);
Pager.init();
expect(removeParams).toHaveBeenCalledWith(['limit', 'offset']);
expect(Pager.url).toEqual(href);
});
}); });
describe('getOld', () => { describe('getOld', () => {
...@@ -164,5 +138,50 @@ describe('pager', () => { ...@@ -164,5 +138,50 @@ describe('pager', () => {
done(); done();
}); });
}); });
describe('has data-href attribute from list element', () => {
const href = `${TEST_HOST}/some_list.json`;
beforeEach(() => {
setFixtures(`<div class="content_list" data-href="${href}"></div>`);
});
it('should use data-href attribute', () => {
Pager.getOld();
expect(axios.get).toHaveBeenCalledWith(href, expect.any(Object));
});
it('should not use current url', () => {
Pager.getOld();
expect(removeParams).not.toHaveBeenCalled();
expect(removeParams).not.toHaveBeenCalledWith(href);
});
});
describe('no data-href attribute attribute provided from list element', () => {
beforeEach(() => {
setFixtures(`<div class="content_list"></div>`);
});
it('should use current url', () => {
const href = `${TEST_HOST}/some_list`;
removeParams.mockReturnValue(href);
Pager.getOld();
expect(axios.get).toHaveBeenCalledWith(href, expect.any(Object));
});
it('keeps extra query parameters from url', () => {
window.history.replaceState({}, null, '?filter=test&offset=100');
const href = `${TEST_HOST}/some_list?filter=test`;
removeParams.mockReturnValue(href);
Pager.getOld();
expect(removeParams).toHaveBeenCalledWith(['limit', 'offset']);
expect(axios.get).toHaveBeenCalledWith(href, expect.any(Object));
});
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment