Skip to content

Commit

Permalink
fix(virtual-repeat): better handles repeating with table row / table …
Browse files Browse the repository at this point in the history
…body

fixes #84
fixes #128
  • Loading branch information
bigopon committed Jan 13, 2019
1 parent fb67af5 commit a09d2a8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
8 changes: 6 additions & 2 deletions test/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createAssertionQueue(): Queue {
let func = queue.shift();
func();
next();
});
}, 1);
}
};

Expand All @@ -22,7 +22,11 @@ export function createAssertionQueue(): Queue {
};
}

export function validateState(virtualRepeat: VirtualRepeat, viewModel: any, itemHeight: number) {
/**
*
* @param extraHeight height of static content that contributes to overall heigh. Happen in case of table
*/
export function validateState(virtualRepeat: VirtualRepeat, viewModel: any, itemHeight: number, extraHeight?: number) {
let views = virtualRepeat.viewSlot.children;
let expectedHeight = viewModel.items.length * itemHeight;
let topBufferHeight = virtualRepeat.topBuffer.getBoundingClientRect().height;
Expand Down
9 changes: 6 additions & 3 deletions test/virtual-repeat-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { PLATFORM } from 'aurelia-pal';
import { createAssertionQueue, validateState, validateScrolledState } from './utilities';
import { VirtualRepeat } from '../src/virtual-repeat';

PLATFORM.moduleName('src/virtual-repeat');
PLATFORM.moduleName('test/noop-value-converter');
PLATFORM.moduleName('src/infinite-scroll-next');

describe('VirtualRepeat Integration', () => {

Expand Down Expand Up @@ -95,7 +98,7 @@ describe('VirtualRepeat Integration', () => {
nq(() => done());
}

function validateSplice(virtualRepeat, viewModel, done) {
function validateSplice(virtualRepeat: VirtualRepeat, viewModel: any, done: Function) {
viewModel.items.splice(2, 1, 'x', 'y');
nq(() => validateState(virtualRepeat, viewModel, itemHeight));
nq(() => done());
Expand Down Expand Up @@ -138,7 +141,7 @@ describe('VirtualRepeat Integration', () => {
items.push('item' + i);
}
component = StageComponent
.withResources(PLATFORM.moduleName('src/virtual-repeat'))
.withResources('src/virtual-repeat')
.inView(`<div style="height: ${itemHeight}px;" virtual-repeat.for="item of items">\${item}</div>`)
.boundTo({ items: items });

Expand Down Expand Up @@ -436,7 +439,7 @@ describe('VirtualRepeat Integration', () => {
spyOn(nestedVm, 'getNextPage').and.callThrough();

component = StageComponent
.withResources(['src/virtual-repeat', PLATFORM.moduleName('src/infinite-scroll-next')])
.withResources(['src/virtual-repeat', 'src/infinite-scroll-next'])
.inView(`<div id="scrollContainer" style="height: 500px; overflow-y: scroll">
<div style="height: ${itemHeight}px;" virtual-repeat.for="item of items" infinite-scroll-next="getNextPage">\${item}</div>
</div>`)
Expand Down
39 changes: 35 additions & 4 deletions test/virtual-repeat-integration.table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VirtualRepeat } from '../src/virtual-repeat';
PLATFORM.moduleName('src/virtual-repeat');
PLATFORM.moduleName('test/noop-value-converter');

fdescribe('VirtualRepeat Integration', () => {
describe('VirtualRepeat Integration', () => {
const itemHeight = 100;
const nq = createAssertionQueue();

Expand Down Expand Up @@ -80,8 +80,10 @@ fdescribe('VirtualRepeat Integration', () => {
});

afterEach(() => {
if (component) {
return component.cleanUp();
try {
component.cleanUp();
} catch (ex) {
console.log('Error cleaning up component');
}
});

Expand All @@ -92,7 +94,6 @@ fdescribe('VirtualRepeat Integration', () => {
virtualRepeat = component.sut;
viewModel = component.viewModel;
});
const element = virtualRepeat['element'];
const { topBuffer, bottomBuffer } = virtualRepeat;
expect(topBuffer.nextElementSibling.tagName).toBe('TBODY');
expect(topBuffer.tagName).toBe('TR');
Expand Down Expand Up @@ -127,6 +128,36 @@ fdescribe('VirtualRepeat Integration', () => {
done.fail(ex);
}
});

it('works with static row', async done => {
try {
component.inView(
// there is a small border spacing between tbodies, rows that will add up
// need to add border spacing 0 for testing purposes
`<table style="border-spacing: 0">
<tr><td>Name</td></tr>
<tbody virtual-repeat.for="item of items">
<tr style="height: ${itemHeight}px;"><td>\${item}</td></tr>
</tbody>
</table>`);

await component.create().then(() => {
virtualRepeat = component.sut;
viewModel = component.viewModel;
});
const element = virtualRepeat['element'];
const table = element.parentNode;
expect(table.firstElementChild).toBe(virtualRepeat.topBuffer.previousElementSibling);
expect(table.firstElementChild.innerHTML.trim()).toBe('<tr><td>Name</td></tr>');
nq(() => validateState(virtualRepeat, viewModel, itemHeight));
nq(() => validatePush(virtualRepeat, viewModel, () => {

done();
}));
} catch (ex) {
done.fail(ex);
}
});
});

function validatePush(virtualRepeat: VirtualRepeat, viewModel: any, done: Function) {
Expand Down

0 comments on commit a09d2a8

Please sign in to comment.