describe()

in spec/index.js [518:619]


  describe('Non-virtualized list view', function () {
    const count = 500;

    beforeEach(doAsync(async () => {
      listView = new ListView({
        el: '.test-container',
        virtualized: false,
      }).set({
        listTemplate: initialListTemplate,
        items: _.map(_.range(count), i => ({ text: i })),
      });
      await render();
    }));

    afterEach(doAsync(async () => {
      listView.remove();
      await sleep(redrawInterval);
    }));

    async function checkDOMUnchanged(action) {
      const $ul = $('.test-container > .internal-viewport > ul');
      const elFirst = $ul.children().first().get(0);
      const elLast = $ul.children().last().get(0);

      await action(function () {
        const $ulNew = $('.test-container > .internal-viewport > ul');
        const elFirstNew = $ulNew.children().get(0);
        const elLastNew = $ulNew.children().last().get(0);

        expect($ulNew.get(0)).to.equal($ul.get(0));
        expect(elFirstNew).to.equal(elFirst);
        expect(elLastNew).to.equal(elLast);
      });
    }

    it('should render all items initially', function () {
      const $ul = $('.test-container > .internal-viewport > ul');

      expect($ul.children().length).to.equal(count + 2);
      expect($ul.children().first().next().text()).to.equal('0');
    });

    it('should keep the DOM unchanged after scrolling', doAsync(
      async () => checkDOMUnchanged(async verify => {
        for (let scrollTop of [100, 1000, 5000, 3000]) {
          listView.viewport.scrollTo({ y: scrollTop });
          await sleep(redrawInterval);
          verify();
        }

        for (let scrollTop = 1000; scrollTop < 1500; scrollTop += 100) {
          listView.viewport.scrollTo({ y: scrollTop });
          await sleep(redrawInterval);
          verify();
        }

        for (let scrollTop = 2000; scrollTop > 1500; scrollTop -= 100) {
          listView.viewport.scrollTo({ y: scrollTop });
          await sleep(redrawInterval);
          verify();
        }
      })
    ));

    it('should keep the DOM unchanged after scrolling to item', doAsync(
      async () => checkDOMUnchanged(async verify => {
        for (let index of [0, 1, 11, 111]) {
          await scrollToItem(index, 'top');
          verify();
          checkItemLocation(index, 'top');
        }

        for (let index of [111, 110, 100]) {
          await scrollToItem(index, 'bottom');
          verify();
          checkItemLocation(index, 'bottom');
        }

        for (let index of [111, 110, 100]) {
          await scrollToItem(index, 'middle');
          verify();
          checkItemLocation(index, 'middle');
        }

        await scrollToItem(0, 'bottom');
        verify();
        checkScrolledToTop();

        await scrollToItem(listView.length - 1, 'top');
        verify();
        checkScrolledToBottom();

        await scrollToItem(0, 'middle');
        verify();
        checkScrolledToTop();

        await scrollToItem(listView.length - 1, 'middle');
        verify();
        checkScrolledToBottom();
      })
    ));
  });