Skip to content

Commit

Permalink
fix: cms carousel component should handle not completely filled slides (
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisie96 authored Apr 19, 2021
1 parent 961a087 commit baff0c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/app/core/utils/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ describe('Functions', () => {
expect(arraySlices(arr, 6)).toEqual([[1, 2, 3, 4, 5, 6]]);
});

it('should return truncated result for length 8', () => {
expect(arraySlices(arr, 8)).toBeEmpty();
it('should return correctly sliced arrays of length 8', () => {
expect(arraySlices(arr, 8)).toEqual([[1, 2, 3, 4, 5, 6]]);
});

it('should return truncated result for length 4', () => {
expect(arraySlices(arr, 4)).toEqual([[1, 2, 3, 4]]);
it('should return correctly sliced arrays of length 4', () => {
expect(arraySlices(arr, 4)).toEqual([
[1, 2, 3, 4],
[5, 6],
]);
});

it('should return undefined when input is undefined or empty', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Observable, isObservable, of } from 'rxjs';
export const arraySlices = <T>(input: T[], sliceLength: number): T[][] =>
input && input.length && sliceLength > 0
? // determine slice indexes
range(0, Math.floor(input.length / sliceLength))
range(0, Math.ceil(input.length / sliceLength))
// cut array into slices
.map(n => input.slice(n * sliceLength, (n + 1) * sliceLength))
: undefined;
Expand Down

0 comments on commit baff0c4

Please sign in to comment.