Commit 4e07370f authored by Samantha Ming's avatar Samantha Ming

Ensure search param is kept in scrolled commit

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/24551
parent 2054a1e8
......@@ -16,7 +16,6 @@ export default {
callback = $.noop,
container = '',
) {
this.url = $('.content_list').data('href') || removeParams(['limit', 'offset']);
this.limit = limit;
this.offset = parseInt(getParameterByName('offset'), 10) || this.limit;
this.disable = disable;
......@@ -32,8 +31,10 @@ export default {
getOld() {
this.loading.show();
const url = $('.content_list').data('href') || removeParams(['limit', 'offset']);
axios
.get(this.url, {
.get(url, {
params: {
limit: this.limit,
offset: this.offset,
......
---
title: Ensure search param is kept in scrolled commit
merge_request: 57307
author:
type: fixed
......@@ -32,38 +32,12 @@ describe('pager', () => {
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', () => {
window.history.replaceState({}, null, '?offset=100');
Pager.init();
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', () => {
......@@ -164,5 +138,50 @@ describe('pager', () => {
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