Skip to content

Commit

Permalink
Fix virtualScroll spec
Browse files Browse the repository at this point in the history
  • Loading branch information
masimplo committed Sep 20, 2017
1 parent c6a2a97 commit 3497d40
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions src/components/virtual-scroll/test/virtual-scroll.spec.ts
Expand Up @@ -22,7 +22,7 @@ describe('VirtualScroll', () => {
ftrWidth: viewportWidth,
ftrHeight: HEIGHT_FOOTER
};
window.getComputedStyle = function() {
window.getComputedStyle = function () {
var styles: any = {
marginTop: '0px',
marginRight: '0px',
Expand All @@ -33,7 +33,7 @@ describe('VirtualScroll', () => {
};
});

describe('estimateHeight', () => {
describe('estimateHeight', () => {

it('should return zero when no records', () => {
const h = estimateHeight(0, undefined, 100, .25);
Expand All @@ -42,14 +42,14 @@ describe('VirtualScroll', () => {

});

describe('processRecords', () => {
describe('processRecords', () => {

it('should load data for 100% width items', () => {
records = [0, 1, 2, 3, 4];
let stopAtHeight = 200;

processRecords(stopAtHeight, records, cells,
headerFn, footerFn, data);
headerFn, footerFn, data);

expect(cells.length).toBe(4);

Expand Down Expand Up @@ -81,16 +81,16 @@ describe('VirtualScroll', () => {
data.hdrWidth = data.viewWidth; // 100%, 1 per row
data.ftrWidth = data.viewWidth; // 100%, 1 per row

headerFn = function(record: any) {
headerFn = function (record: any) {
return (record === 0) ? 'Header' : null;
};

footerFn = function(record: any) {
footerFn = function (record: any) {
return (record === 4) ? 'Footer' : null;
};

processRecords(stopAtHeight, records, cells,
headerFn, footerFn, data);
headerFn, footerFn, data);

expect(cells.length).toBe(7);

Expand Down Expand Up @@ -165,12 +165,12 @@ describe('VirtualScroll', () => {
data.itmWidth = 90; // 2 per row
data.hdrWidth = data.viewWidth; // 100%, 1 per row

headerFn = function(record: any) {
headerFn = function (record: any) {
return (record === 0) ? 'Header' : null;
};

processRecords(stopAtHeight, records, cells,
headerFn, footerFn, data);
headerFn, footerFn, data);

expect(cells.length).toBe(5);

Expand All @@ -188,7 +188,7 @@ describe('VirtualScroll', () => {

stopAtHeight = 150;
processRecords(stopAtHeight, records, cells,
headerFn, footerFn, data);
headerFn, footerFn, data);

expect(cells[2].row).toBe(1);
expect(cells[2].top).toBe(HEIGHT_HEADER);
Expand All @@ -206,7 +206,7 @@ describe('VirtualScroll', () => {

stopAtHeight = 20000;
processRecords(stopAtHeight, records, cells,
headerFn, footerFn, data);
headerFn, footerFn, data);

expect(cells.length).toBe(11);

Expand All @@ -230,36 +230,36 @@ describe('VirtualScroll', () => {
let endCellIndex = 0;

populateNodeData(startCellIndex, endCellIndex, true,
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp, false);
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp);

expect(nodes.length).toBe(0);
});

it('should skip already rendered, and create nodes', () => {
cells = [
{row: 0, tmpl: TEMPLATE_ITEM},
{row: 1, tmpl: TEMPLATE_ITEM},
{row: 2, tmpl: TEMPLATE_HEADER},
{row: 3, tmpl: TEMPLATE_ITEM},
{row: 4, tmpl: TEMPLATE_FOOTER},
{row: 5, tmpl: TEMPLATE_ITEM},
{row: 6, tmpl: TEMPLATE_ITEM, reads: 0}
{ row: 0, tmpl: TEMPLATE_ITEM },
{ row: 1, tmpl: TEMPLATE_ITEM },
{ row: 2, tmpl: TEMPLATE_HEADER },
{ row: 3, tmpl: TEMPLATE_ITEM },
{ row: 4, tmpl: TEMPLATE_FOOTER },
{ row: 5, tmpl: TEMPLATE_ITEM },
{ row: 6, tmpl: TEMPLATE_ITEM, reads: 0 }
];

nodes = [
{cell: 0, tmpl: TEMPLATE_ITEM, view: getView()},
{cell: 1, tmpl: TEMPLATE_ITEM, view: getView()},
{cell: 2, tmpl: TEMPLATE_HEADER, view: getView()},
{cell: 3, tmpl: TEMPLATE_ITEM, view: getView()},
{ cell: 0, tmpl: TEMPLATE_ITEM, view: getView() },
{ cell: 1, tmpl: TEMPLATE_ITEM, view: getView() },
{ cell: 2, tmpl: TEMPLATE_HEADER, view: getView() },
{ cell: 3, tmpl: TEMPLATE_ITEM, view: getView() },
];

let startCellIndex = 2;
let endCellIndex = 5;

populateNodeData(startCellIndex, endCellIndex, true,
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp, false);
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp);

expect(nodes.length).toBe(5);

Expand All @@ -274,21 +274,21 @@ describe('VirtualScroll', () => {

it('should create nodes', () => {
cells = [
{row: 0, tmpl: TEMPLATE_ITEM},
{row: 1, tmpl: TEMPLATE_ITEM},
{row: 2, tmpl: TEMPLATE_HEADER},
{row: 3, tmpl: TEMPLATE_ITEM},
{row: 4, tmpl: TEMPLATE_FOOTER},
{row: 5, tmpl: TEMPLATE_ITEM},
{row: 6, tmpl: TEMPLATE_ITEM}
{ row: 0, tmpl: TEMPLATE_ITEM },
{ row: 1, tmpl: TEMPLATE_ITEM },
{ row: 2, tmpl: TEMPLATE_HEADER },
{ row: 3, tmpl: TEMPLATE_ITEM },
{ row: 4, tmpl: TEMPLATE_FOOTER },
{ row: 5, tmpl: TEMPLATE_ITEM },
{ row: 6, tmpl: TEMPLATE_ITEM }
];

let startCellIndex = 2;
let endCellIndex = 4;

populateNodeData(startCellIndex, endCellIndex, true,
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp, true);
cells, records, nodes, viewContainer,
itmTmp, hdrTmp, ftrTmp);

expect(nodes.length).toBe(3);

Expand All @@ -308,21 +308,21 @@ describe('VirtualScroll', () => {
it('should get all the row heights w/ 30% width rows', () => {
let firstTop = 13;
nodes = [
{cell: 0, tmpl: TEMPLATE_HEADER, view: getView(data.viewWidth, HEIGHT_HEADER, firstTop, 0)},
{cell: 1, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 0)},
{cell: 2, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 90)},
{cell: 3, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 180)},
{cell: 4, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM + firstTop, 0)},
{cell: 5, tmpl: TEMPLATE_FOOTER, view: getView(data.viewWidth, HEIGHT_FOOTER, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM + firstTop, 0)},
{ cell: 0, tmpl: TEMPLATE_HEADER, view: getView(data.viewWidth, HEIGHT_HEADER, firstTop, 0) },
{ cell: 1, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 0) },
{ cell: 2, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 90) },
{ cell: 3, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + firstTop, 180) },
{ cell: 4, tmpl: TEMPLATE_ITEM, view: getView(90, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM + firstTop, 0) },
{ cell: 5, tmpl: TEMPLATE_FOOTER, view: getView(data.viewWidth, HEIGHT_FOOTER, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM + firstTop, 0) },
];

cells = [
{row: 0, tmpl: TEMPLATE_HEADER, reads: 0},
{row: 0, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 0, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 0, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 0, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 0, tmpl: TEMPLATE_FOOTER, reads: 0},
{ row: 0, tmpl: TEMPLATE_HEADER, reads: 0 },
{ row: 0, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 0, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 0, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 0, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 0, tmpl: TEMPLATE_FOOTER, reads: 0 },
];

initReadNodes(mockPlatform(), nodes, cells, data);
Expand Down Expand Up @@ -360,19 +360,19 @@ describe('VirtualScroll', () => {

it('should get all the row heights w/ all 100% width rows', () => {
nodes = [
{cell: 0, tmpl: TEMPLATE_HEADER, view: getView(data.viewWidth, HEIGHT_HEADER, 0, 0)},
{cell: 1, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER, 0)},
{cell: 2, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM, 0)},
{cell: 3, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM, 0)},
{cell: 4, tmpl: TEMPLATE_FOOTER, view: getView(data.viewWidth, HEIGHT_FOOTER, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM + HEIGHT_ITEM, 0)},
{ cell: 0, tmpl: TEMPLATE_HEADER, view: getView(data.viewWidth, HEIGHT_HEADER, 0, 0) },
{ cell: 1, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER, 0) },
{ cell: 2, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM, 0) },
{ cell: 3, tmpl: TEMPLATE_ITEM, view: getView(data.viewWidth, HEIGHT_ITEM, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM, 0) },
{ cell: 4, tmpl: TEMPLATE_FOOTER, view: getView(data.viewWidth, HEIGHT_FOOTER, HEIGHT_HEADER + HEIGHT_ITEM + HEIGHT_ITEM + HEIGHT_ITEM, 0) },
];

cells = [
{row: 0, tmpl: TEMPLATE_HEADER, reads: 0},
{row: 1, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 2, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 3, tmpl: TEMPLATE_ITEM, reads: 0},
{row: 4, tmpl: TEMPLATE_FOOTER, reads: 0},
{ row: 0, tmpl: TEMPLATE_HEADER, reads: 0 },
{ row: 1, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 2, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 3, tmpl: TEMPLATE_ITEM, reads: 0 },
{ row: 4, tmpl: TEMPLATE_FOOTER, reads: 0 },
];

initReadNodes(mockPlatform(), nodes, cells, data);
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('VirtualScroll', () => {

it('should adjust when all the way to the top, scrolling down', () => {
for (var i = 0; i < 100; i++) {
cells.push({top: i, height: 1, row: i});
cells.push({ top: i, height: 1, row: i });
}
data.scrollDiff = 1;
data.viewHeight = 20;
Expand All @@ -418,7 +418,7 @@ describe('VirtualScroll', () => {

it('should adjust when in the middle, scrolling down', () => {
for (var i = 0; i < 100; i++) {
cells.push({top: i, height: 1, row: i});
cells.push({ top: i, height: 1, row: i });
}
data.scrollDiff = 1;
data.viewHeight = 20;
Expand All @@ -436,7 +436,7 @@ describe('VirtualScroll', () => {

it('should adjust when all the way to the bottom, scrolling down', () => {
for (var i = 0; i < 100; i++) {
cells.push({top: i, height: 1, row: i});
cells.push({ top: i, height: 1, row: i });
}
data.scrollDiff = 1;
data.viewHeight = 20;
Expand All @@ -454,7 +454,7 @@ describe('VirtualScroll', () => {

it('should adjust when all the way to the bottom, scrolling up', () => {
for (var i = 0; i < 100; i++) {
cells.push({top: i, height: 1, row: i});
cells.push({ top: i, height: 1, row: i });
}
data.scrollDiff = -1;
data.viewHeight = 20;
Expand Down Expand Up @@ -546,10 +546,10 @@ describe('VirtualScroll', () => {
let hdrTmp: any = {};
let ftrTmp: any = {};
let viewContainer: any = {
createEmbeddedView: function() {
createEmbeddedView: function () {
return getView();
},
indexOf: function() {
indexOf: function () {
return 0;
}
};
Expand All @@ -570,10 +570,10 @@ describe('VirtualScroll', () => {
left: ''
},
classList: {
add: function(){},
remove: function(){}
add: function () { },
remove: function () { }
},
setAttribute: function(){},
setAttribute: function () { },
innerHTML: '',
}]
};
Expand Down

0 comments on commit 3497d40

Please sign in to comment.