From f04b6b5d1ff7496a30aa75eaba3563aae6289e09 Mon Sep 17 00:00:00 2001 From: dhilt Date: Sun, 15 Dec 2019 23:16:09 +0300 Subject: [PATCH] issue-107 append/prepend to empty datasource with eof/bof parameter (spec) --- tests/adapter.append-prepend.spec.ts | 68 +++++++++++++++------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/tests/adapter.append-prepend.spec.ts b/tests/adapter.append-prepend.spec.ts index 9f227e33..d8ab44b9 100644 --- a/tests/adapter.append-prepend.spec.ts +++ b/tests/adapter.append-prepend.spec.ts @@ -141,39 +141,43 @@ describe('Adapter Append-Prepend Spec', () => { }) }); - makeTest({ - config: (configEmpty)[token], - title: `should ${token} to empty datasource`, - it: (misc: Misc) => (done: any) => { - const { viewport, buffer } = misc.scroller; - const { paddings } = viewport; - const _config = (configEmpty)[token]; - const templateSize = _config.templateSettings.viewportHeight; - const items = (getNewItems(_config.amount))[token]; + const shouldDealWithEmptyDatasource = (virtualize: boolean) => + makeTest({ + config: (configEmpty)[token], + title: `should ${token} to empty datasource` + virtualize ? ' (virtualization)' : '', + it: (misc: Misc) => (done: any) => { + const { viewport, buffer } = misc.scroller; + const { paddings } = viewport; + const _config = (configEmpty)[token]; + const templateSize = _config.templateSettings.viewportHeight; + const items = (getNewItems(_config.amount))[token]; - spyOn(misc.workflow, 'finalize').and.callFake(() => { - const itemSize = misc.getItemSize(); - if (misc.workflow.cyclesDone === 1) { - expect(viewport.getScrollableSize()).toEqual(templateSize); - (misc.scroller.datasource.adapter)[token](items); - } else { - const viewportSize = Math.max(_config.amount * itemSize, templateSize); - const scrollPosition = isAppend ? 0 : Math.min(_config.amount * itemSize, templateSize); - const first = buffer.firstIndex; - const last = buffer.lastIndex; - const _first = isAppend ? max - _config.amount + 1 : min; - const _last = isAppend ? max : min + _config.amount - 1; - expect(misc.getScrollableSize()).toEqual(viewportSize); - expect(misc.getScrollPosition()).toEqual(scrollPosition); - expect(first).toEqual(_first); - expect(last).toEqual(_last); - expect(misc.checkElementContentByIndex(first)).toEqual(true); - expect(misc.checkElementContentByIndex(last)).toEqual(true); - done(); - } - }); - } - }); + spyOn(misc.workflow, 'finalize').and.callFake(() => { + const itemSize = misc.getItemSize(); + if (misc.workflow.cyclesDone === 1) { + expect(viewport.getScrollableSize()).toEqual(templateSize); + (misc.scroller.datasource.adapter)[token](items, virtualize); + } else { + const viewportSize = Math.max(_config.amount * itemSize, templateSize); + const scrollPosition = isAppend ? 0 : Math.min(_config.amount * itemSize, templateSize); + const first = buffer.firstIndex; + const last = buffer.lastIndex; + const _first = isAppend ? max - _config.amount + 1 : min; + const _last = isAppend ? max : min + _config.amount - 1; + expect(misc.getScrollableSize()).toEqual(viewportSize); + expect(misc.getScrollPosition()).toEqual(scrollPosition); + expect(first).toEqual(_first); + expect(last).toEqual(_last); + expect(misc.checkElementContentByIndex(first)).toEqual(true); + expect(misc.checkElementContentByIndex(last)).toEqual(true); + done(); + } + }); + } + }); + + shouldDealWithEmptyDatasource(false); + shouldDealWithEmptyDatasource(true); };