|
| 1 | +let ias; |
| 2 | + |
| 3 | +describe('Load on scroll', () => { |
| 4 | + beforeEach(() => { |
| 5 | + // runs before each test in the block |
| 6 | + cy.visit('http://localhost:8080/test/fixtures/default/page1.html') |
| 7 | + }); |
| 8 | + |
| 9 | + it('should emit a next event when loadOnScroll enabled by default', () => { |
| 10 | + const spy = { |
| 11 | + next() {} |
| 12 | + }; |
| 13 | + |
| 14 | + cy.spy(spy, 'next'); |
| 15 | + |
| 16 | + cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => { |
| 17 | + ias = new InfiniteAjaxScroll('.blocks', { |
| 18 | + item: '.blocks__block', |
| 19 | + }); |
| 20 | + |
| 21 | + ias.on('next', spy.next); |
| 22 | + |
| 23 | + cy.scrollTo('bottom', {duration: 300}).then(function() { |
| 24 | + expect(spy.next).to.have.been.called; |
| 25 | + }); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should emit a next event when loadOnScroll explicitly enabled', () => { |
| 30 | + const spy = { |
| 31 | + next() {} |
| 32 | + }; |
| 33 | + |
| 34 | + cy.spy(spy, 'next'); |
| 35 | + |
| 36 | + cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => { |
| 37 | + ias = new InfiniteAjaxScroll('.blocks', { |
| 38 | + item: '.blocks__block', |
| 39 | + loadOnScroll: true |
| 40 | + }); |
| 41 | + |
| 42 | + ias.on('next', spy.next); |
| 43 | + |
| 44 | + cy.scrollTo('bottom', {duration: 300}).then(function() { |
| 45 | + expect(spy.next).to.have.been.called; |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should not emit a next event when loadOnScroll is disabled', () => { |
| 51 | + const spy = { |
| 52 | + next() {} |
| 53 | + }; |
| 54 | + |
| 55 | + cy.spy(spy, 'next'); |
| 56 | + |
| 57 | + cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => { |
| 58 | + ias = new InfiniteAjaxScroll('.blocks', { |
| 59 | + item: '.blocks__block', |
| 60 | + loadOnScroll: false |
| 61 | + }); |
| 62 | + |
| 63 | + ias.on('next', spy.next); |
| 64 | + |
| 65 | + cy.scrollTo('bottom', {duration: 300}).then(function() { |
| 66 | + expect(spy.next).to.not.have.been.called; |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it('can be enabled (enableLoadOnScroll)', () => { |
| 72 | + const spy = { |
| 73 | + next() {} |
| 74 | + }; |
| 75 | + |
| 76 | + cy.spy(spy, 'next'); |
| 77 | + |
| 78 | + cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => { |
| 79 | + ias = new InfiniteAjaxScroll('.blocks', { |
| 80 | + item: '.blocks__block', |
| 81 | + loadOnScroll: false |
| 82 | + }); |
| 83 | + |
| 84 | + ias.enableLoadOnScroll(); |
| 85 | + |
| 86 | + ias.on('next', spy.next); |
| 87 | + |
| 88 | + cy.scrollTo('bottom', {duration: 300}).then(function() { |
| 89 | + expect(spy.next).to.have.been.called; |
| 90 | + }); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + it('can be disabled (disableLoadOnScroll)', () => { |
| 95 | + const spy = { |
| 96 | + next() {} |
| 97 | + }; |
| 98 | + |
| 99 | + cy.spy(spy, 'next'); |
| 100 | + |
| 101 | + cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => { |
| 102 | + ias = new InfiniteAjaxScroll('.blocks', { |
| 103 | + item: '.blocks__block', |
| 104 | + loadOnScroll: true |
| 105 | + }); |
| 106 | + |
| 107 | + ias.disableLoadOnScroll(); |
| 108 | + |
| 109 | + ias.on('next', spy.next); |
| 110 | + |
| 111 | + cy.scrollTo('bottom', {duration: 300}).then(function() { |
| 112 | + expect(spy.next).to.not.have.been.called; |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments