summaryrefslogtreecommitdiff
path: root/spec/frontend/pager_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/pager_spec.js')
-rw-r--r--spec/frontend/pager_spec.js57
1 files changed, 49 insertions, 8 deletions
diff --git a/spec/frontend/pager_spec.js b/spec/frontend/pager_spec.js
index 043ea470436..9df69124d66 100644
--- a/spec/frontend/pager_spec.js
+++ b/spec/frontend/pager_spec.js
@@ -68,34 +68,34 @@ describe('pager', () => {
it('shows loader while loading next page', async () => {
mockSuccess();
- jest.spyOn(Pager.loading, 'show').mockImplementation(() => {});
+ jest.spyOn(Pager.$loading, 'show').mockImplementation(() => {});
Pager.getOld();
await waitForPromises();
- expect(Pager.loading.show).toHaveBeenCalled();
+ expect(Pager.$loading.show).toHaveBeenCalled();
});
it('hides loader on success', async () => {
mockSuccess();
- jest.spyOn(Pager.loading, 'hide').mockImplementation(() => {});
+ jest.spyOn(Pager.$loading, 'hide').mockImplementation(() => {});
Pager.getOld();
await waitForPromises();
- expect(Pager.loading.hide).toHaveBeenCalled();
+ expect(Pager.$loading.hide).toHaveBeenCalled();
});
it('hides loader on error', async () => {
mockError();
- jest.spyOn(Pager.loading, 'hide').mockImplementation(() => {});
+ jest.spyOn(Pager.$loading, 'hide').mockImplementation(() => {});
Pager.getOld();
await waitForPromises();
- expect(Pager.loading.hide).toHaveBeenCalled();
+ expect(Pager.$loading.hide).toHaveBeenCalled();
});
it('sends request to url with offset and limit params', async () => {
@@ -122,12 +122,12 @@ describe('pager', () => {
Pager.limit = 20;
mockSuccess(1);
- jest.spyOn(Pager.loading, 'hide').mockImplementation(() => {});
+ jest.spyOn(Pager.$loading, 'hide').mockImplementation(() => {});
Pager.getOld();
await waitForPromises();
- expect(Pager.loading.hide).toHaveBeenCalled();
+ expect(Pager.$loading.hide).toHaveBeenCalled();
expect(Pager.disable).toBe(true);
});
@@ -175,5 +175,46 @@ describe('pager', () => {
expect(axios.get).toHaveBeenCalledWith(href, expect.any(Object));
});
});
+
+ describe('when `container` is passed', () => {
+ const href = '/some_list';
+ const container = '#js-pager';
+ let endlessScrollCallback;
+
+ beforeEach(() => {
+ jest.spyOn(axios, 'get');
+ jest.spyOn($.fn, 'endlessScroll').mockImplementation(({ callback }) => {
+ endlessScrollCallback = callback;
+ });
+ });
+
+ describe('when `container` is visible', () => {
+ it('makes API request', () => {
+ setFixtures(
+ `<div id="js-pager"><div class="content_list" data-href="${href}"></div></div>`,
+ );
+
+ Pager.init({ container });
+
+ endlessScrollCallback();
+
+ expect(axios.get).toHaveBeenCalledWith(href, expect.any(Object));
+ });
+ });
+
+ describe('when `container` is not visible', () => {
+ it('does not make API request', () => {
+ setFixtures(
+ `<div id="js-pager" style="display: none;"><div class="content_list" data-href="${href}"></div></div>`,
+ );
+
+ Pager.init({ container });
+
+ endlessScrollCallback();
+
+ expect(axios.get).not.toHaveBeenCalled();
+ });
+ });
+ });
});
});