From fd45928b3ea6d89572145fd0d9d1abe4cb01820a Mon Sep 17 00:00:00 2001 From: "bigopon.777@gmail.com" Date: Wed, 6 Mar 2019 12:37:56 +1100 Subject: [PATCH] fix(virtual repeat): prepare new tests, add examples --- sample/sample-v-ui-app/src/app.ts | 6 ++ sample/sample-v-ui-app/src/nav-bar.html | 61 +++++++++++-------- .../src/promise-get-more/sub-app.html | 27 ++++++++ .../src/promise-get-more/sub-app.ts | 52 ++++++++++++++++ test/virtual-repeat-integration.spec.ts | 21 ++++--- test/vr-integration.scrolling.spec.ts | 0 6 files changed, 133 insertions(+), 34 deletions(-) create mode 100644 sample/sample-v-ui-app/src/promise-get-more/sub-app.html create mode 100644 sample/sample-v-ui-app/src/promise-get-more/sub-app.ts create mode 100644 test/vr-integration.scrolling.spec.ts diff --git a/sample/sample-v-ui-app/src/app.ts b/sample/sample-v-ui-app/src/app.ts index 1bed081..bc21c02 100644 --- a/sample/sample-v-ui-app/src/app.ts +++ b/sample/sample-v-ui-app/src/app.ts @@ -42,6 +42,12 @@ export class App { moduleId: PLATFORM.moduleName('./issue-146/sub-app'), nav: 6, title: 'Issue 146' + }, + { + route: 'promise-get-more', + moduleId: PLATFORM.moduleName('./promise-get-more/sub-app'), + nav: 7, + title: 'Infinite Scroll + Promise' } ]); diff --git a/sample/sample-v-ui-app/src/nav-bar.html b/sample/sample-v-ui-app/src/nav-bar.html index d3f3584..871a0dc 100644 --- a/sample/sample-v-ui-app/src/nav-bar.html +++ b/sample/sample-v-ui-app/src/nav-bar.html @@ -1,33 +1,40 @@ diff --git a/sample/sample-v-ui-app/src/promise-get-more/sub-app.html b/sample/sample-v-ui-app/src/promise-get-more/sub-app.html new file mode 100644 index 0000000..e230ec6 --- /dev/null +++ b/sample/sample-v-ui-app/src/promise-get-more/sub-app.html @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/sample/sample-v-ui-app/src/promise-get-more/sub-app.ts b/sample/sample-v-ui-app/src/promise-get-more/sub-app.ts new file mode 100644 index 0000000..0e2cc4a --- /dev/null +++ b/sample/sample-v-ui-app/src/promise-get-more/sub-app.ts @@ -0,0 +1,52 @@ +interface IScrollContext { + isAtTop: boolean; + isAtBottom: boolean; + topIndex: number; +} + +export interface Person { + fname: string; + lname: string; +} + +const fNames = [ + // tslint:disable-next-line:max-line-length + 'Ford', 'Arthur', 'Trillian', 'Sneezy', 'Sleepy', 'Dopey', 'Doc', 'Happy', 'Bashful', 'Grumpy', 'Mufasa', 'Sarabi', 'Simba', 'Nala', 'Kiara', 'Kovu', 'Timon', 'Pumbaa', 'Rafiki', 'Shenzi' +]; +const lNames = [ + // tslint:disable-next-line:max-line-length + 'Prefect', 'Dent', 'Astra', 'Adams', 'Baker', 'Clark', 'Davis', 'Evans', 'Frank', 'Ghosh', 'Hills', 'Irwin', 'Jones', 'Klein', 'Lopez', 'Mason', 'Nalty', 'Ochoa', 'Patel', 'Quinn', 'Reily', 'Smith', 'Trott', 'Usman', 'Valdo', 'White', 'Xiang', 'Yakub', 'Zafar' +]; +export class PromiseGetMoreApp { + private people: Person[]; + + constructor() { + this.people = [ + { fname: fNames[0], lname: lNames[0] }, + { fname: fNames[1], lname: lNames[1] }, + { fname: fNames[2], lname: lNames[2] } + ]; + this.push30(undefined, 0); + } + + public async push30(scrollContext?: IScrollContext, count = 30) { + console.log('Issue-102 getting more...'); + // if (scrollContext) { + // console.log('Issue-129 getting more:', JSON.stringify(scrollContext, undefined, 2)); + // } + return new Promise(resolve => { + setTimeout(() => { + if (!scrollContext || scrollContext.isAtBottom) { + for (let i = 0; i < count; i++) { + this.people.push({ + fname: fNames[Math.floor(Math.random() * fNames.length)], + lname: lNames[Math.floor(Math.random() * lNames.length)] + }); + } + } + resolve(); + console.log('Population size:', this.people.length); + }, Math.random() * 2000 + 500); + }); + } +} diff --git a/test/virtual-repeat-integration.spec.ts b/test/virtual-repeat-integration.spec.ts index 05273a5..10a982c 100644 --- a/test/virtual-repeat-integration.spec.ts +++ b/test/virtual-repeat-integration.spec.ts @@ -422,7 +422,7 @@ describe('VirtualRepeat Integration', () => { promisedVm = { items: items, test: '2', - getNextPage: function () { + getNextPage: jasmine.createSpy('promisedVm.getNextPage', function() { return new Promise((resolve, reject) => { let itemLength = this.items.length; for (let i = 0; i < 100; ++i) { @@ -431,7 +431,7 @@ describe('VirtualRepeat Integration', () => { } resolve(true); }); - } + }).and.callThrough() }; for (let i = 0; i < 1000; ++i) { items.push('item' + i); @@ -524,14 +524,21 @@ describe('VirtualRepeat Integration', () => { }); }); }); - it('handles getting next data set with promises', done => { - promisedCreate.then(() => { - validateScroll(promisedVirtualRepeat, promisedViewModel, () => { + it('handles getting next data set with promises', async done => { + await create; + await promisedCreate; + validateScroll( + promisedVirtualRepeat, + promisedViewModel, + async () => { + await waitForTimeout(500); + expect(promisedVm.getNextPage).toHaveBeenCalled(); // Jasmine spies seem to not be working with returned promises and getting the instance of them, causing regular checks on getNextPage to fail expect(promisedVm.items.length).toBe(1100); done(); - }, 'scrollContainerPromise'); - }); + }, + 'scrollContainerPromise' + ); }); it('handles getting next data set with small page size', done => { vm.items = []; diff --git a/test/vr-integration.scrolling.spec.ts b/test/vr-integration.scrolling.spec.ts new file mode 100644 index 0000000..e69de29