Skip to content

Commit 1981006

Browse files
author
Sander Hoogendoorn
committed
fix: repaired view with a pagelist, now has correct options.
1 parent bd612b6 commit 1981006

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/easy/src/utils/View.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class View<V = any> {
6666
if (isPageList(source))
6767
return toPageList(
6868
source.map(s => this.reduce(s)),
69-
source
69+
source.options
7070
);
7171
if (isArray(source)) return source.map(s => this.reduce(s));
7272
return this.reduce(source);

packages/easy/test/utils/View.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,47 @@ describe('View', () => {
405405
expect(s).toMatchJson({ id: 3, loan: 3000, name: 'Sander Hoogendoorn' });
406406
});
407407
});
408+
409+
const toThing = view({
410+
id: 'id',
411+
name: 'name',
412+
});
413+
414+
const data = [
415+
{ id: 1, name: 'a' },
416+
{ id: 2, name: 'b' },
417+
{ id: 3, name: 'c' },
418+
];
419+
420+
const options = { take: 3 };
421+
422+
describe('view works', () => {
423+
test('toThing works for an array', () => {
424+
const things = toThing.from(data);
425+
expect(things).toHaveLength(3);
426+
expect((things as any).options).toBeUndefined();
427+
});
428+
429+
test('toThing works for a List', () => {
430+
const pl = toList(data);
431+
const things = toThing.from(pl);
432+
expect(things).toHaveLength(3);
433+
expect((things as any).options).toBeUndefined();
434+
});
435+
436+
test('toThing works for a PageList', () => {
437+
const pl = toPageList(data);
438+
expect(pl.options).toBeUndefined();
439+
const things = toThing.from(pl);
440+
expect(things).toHaveLength(3);
441+
expect(things.options).toBeUndefined();
442+
});
443+
444+
test('toThing works for a PageList with options', () => {
445+
const pl = toPageList(data, options);
446+
expect(pl.options).toEqual(options);
447+
const things = toThing.from(pl);
448+
expect(things).toHaveLength(3);
449+
expect(things.options).toEqual(options);
450+
});
451+
});

0 commit comments

Comments
 (0)