-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(template-strategy): diff between tbody and tr
- Loading branch information
Showing
9 changed files
with
316 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { VirtualRepeat } from '../src/virtual-repeat'; | ||
|
||
export type Queue = (func: (...args: any[]) => any) => void; | ||
|
||
export function createAssertionQueue(): Queue { | ||
let queue: Array<() => any> = []; | ||
let next = () => { | ||
if (queue.length) { | ||
setTimeout(() => { | ||
let func = queue.shift(); | ||
func(); | ||
next(); | ||
}); | ||
} | ||
}; | ||
|
||
return (func: () => any) => { | ||
queue.push(func); | ||
if (queue.length === 1) { | ||
next(); | ||
} | ||
}; | ||
} | ||
|
||
export function validateState(virtualRepeat: VirtualRepeat, viewModel: any, itemHeight: number) { | ||
let views = virtualRepeat.viewSlot.children; | ||
let expectedHeight = viewModel.items.length * itemHeight; | ||
let topBufferHeight = virtualRepeat.topBuffer.getBoundingClientRect().height; | ||
let bottomBufferHeight = virtualRepeat.bottomBuffer.getBoundingClientRect().height; | ||
let renderedItemsHeight = views.length * itemHeight; | ||
expect(topBufferHeight + renderedItemsHeight + bottomBufferHeight).toBe(expectedHeight); | ||
|
||
if (viewModel.items.length > views.length) { | ||
expect(topBufferHeight + bottomBufferHeight).toBeGreaterThan(0); | ||
} | ||
|
||
// validate contextual data | ||
for (let i = 0; i < views.length; i++) { | ||
expect(views[i].bindingContext.item).toBe(viewModel.items[i]); | ||
let overrideContext = views[i].overrideContext; | ||
expect(overrideContext.parentOverrideContext.bindingContext).toBe(viewModel); | ||
expect(overrideContext.bindingContext).toBe(views[i].bindingContext); | ||
let first = i === 0; | ||
let last = i === viewModel.items.length - 1; | ||
let even = i % 2 === 0; | ||
expect(overrideContext.$index).toBe(i); | ||
expect(overrideContext.$first).toBe(first); | ||
expect(overrideContext.$last).toBe(last); | ||
expect(overrideContext.$middle).toBe(!first && !last); | ||
expect(overrideContext.$odd).toBe(!even); | ||
expect(overrideContext.$even).toBe(even); | ||
} | ||
} | ||
|
||
export function validateScrolledState(virtualRepeat: VirtualRepeat, viewModel: any, itemHeight: number) { | ||
let views = virtualRepeat.viewSlot.children; | ||
let expectedHeight = viewModel.items.length * itemHeight; | ||
let topBufferHeight = virtualRepeat.topBuffer.getBoundingClientRect().height; | ||
let bottomBufferHeight = virtualRepeat.bottomBuffer.getBoundingClientRect().height; | ||
let renderedItemsHeight = views.length * itemHeight; | ||
expect(topBufferHeight + renderedItemsHeight + bottomBufferHeight).toBe(expectedHeight); | ||
|
||
if (viewModel.items.length > views.length) { | ||
expect(topBufferHeight + bottomBufferHeight).toBeGreaterThan(0); | ||
} | ||
|
||
// validate contextual data | ||
let startingLoc = viewModel.items.indexOf(views[0].bindingContext.item); | ||
for (let i = startingLoc; i < views.length; i++) { | ||
expect(views[i].bindingContext.item).toBe(viewModel.items[i]); | ||
let overrideContext = views[i].overrideContext; | ||
expect(overrideContext.parentOverrideContext.bindingContext).toBe(viewModel); | ||
expect(overrideContext.bindingContext).toBe(views[i].bindingContext); | ||
let first = i === 0; | ||
let last = i === viewModel.items.length - 1; | ||
let even = i % 2 === 0; | ||
expect(overrideContext.$index).toBe(i); | ||
expect(overrideContext.$first).toBe(first); | ||
expect(overrideContext.$last).toBe(last); | ||
expect(overrideContext.$middle).toBe(!first && !last); | ||
expect(overrideContext.$odd).toBe(!even); | ||
expect(overrideContext.$even).toBe(even); | ||
} | ||
} |
Oops, something went wrong.